From 8026d128513eb3f16f4029919ed5d9fec95222c1 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 8 Aug 2019 01:55:27 +0000 Subject: [PATCH] [Driver] Move LIBRARY_PATH before user inputs Fixes PR16786 Currently, library paths specified by LIBRARY_PATH are placed after inputs: `inputs LIBRARY_PATH stdlib` In gcc, the order is: `LIBRARY_PATH inputs stdlib` if not cross compiling. (On Darwin targets, isCrossCompiling() always returns false.) This patch changes the behavior to match gcc. Reviewed By: hfinkel Differential Revision: https://reviews.llvm.org/D65880 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368245 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/CommonArgs.cpp | 11 +++++------ test/Driver/linker-opts.c | 8 +++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp index 93b823b72e..56f0b9437c 100644 --- a/lib/Driver/ToolChains/CommonArgs.cpp +++ b/lib/Driver/ToolChains/CommonArgs.cpp @@ -145,6 +145,11 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, // (constructed via -Xarch_). Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input); + // LIBRARY_PATH are included before user inputs and only supported on native + // toolchains. + if (!TC.isCrossCompiling()) + addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH"); + for (const auto &II : Inputs) { // If the current tool chain refers to an OpenMP or HIP offloading host, we // should ignore inputs that refer to OpenMP or HIP offloading devices - @@ -182,12 +187,6 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, A.renderAsInput(Args, CmdArgs); } } - - // LIBRARY_PATH - included following the user specified library paths. - // and only supported on native toolchains. - if (!TC.isCrossCompiling()) { - addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH"); - } } void tools::AddTargetFeature(const ArgList &Args, diff --git a/test/Driver/linker-opts.c b/test/Driver/linker-opts.c index 68b1e9fbe5..70f51431eb 100644 --- a/test/Driver/linker-opts.c +++ b/test/Driver/linker-opts.c @@ -1,8 +1,10 @@ // RUN: rm -rf %t // RUN: mkdir %t // -// RUN: env LIBRARY_PATH=%t/test1 %clang -x c %s -### 2>&1 | FileCheck %s +// RUN: env LIBRARY_PATH=%t/test1 %clang -target %itanium_abi_triple %s -la -### 2>&1 | FileCheck %s // CHECK: "-L{{.*}}/test1" +// CHECK: "{{[^"]+}}.o" +// CHECK: "-la" // GCC driver is used as linker on cygming. It should be aware of LIBRARY_PATH. // XFAIL: windows-msvc @@ -10,8 +12,8 @@ // REQUIRES: native // Make sure that LIBRARY_PATH works for both i386 and x86_64 on Darwin. -// RUN: env LIBRARY_PATH=%t/test1 %clang -target x86_64-apple-darwin %s -### 2>&1 | FileCheck %s -// RUN: env LIBRARY_PATH=%t/test1 %clang -target i386-apple-darwin %s -### 2>&1 | FileCheck %s +// RUN: env LIBRARY_PATH=%t/test1 %clang -target x86_64-apple-darwin %s -la -### 2>&1 | FileCheck %s +// RUN: env LIBRARY_PATH=%t/test1 %clang -target i386-apple-darwin %s -la -### 2>&1 | FileCheck %s // // Make sure that we don't warn on unused compiler arguments. // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o -- 2.40.0