[lld] r262910 - ELF: Add /lib and /usr/lib as default search paths.

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 8 09:20:39 PST 2016


Sorry, I reverted this.

The problem is that it broke linking on Fedora 64 bits. There the
default search path should be /lib64 /usr/lib64.

It is probably better to try to stay out of the business of knowing
the defaults of multiple systems. The vast majority or links are
started by the driver and it passes all the necessary -L options.

Cheers,
Rafael


On 7 March 2016 at 23:06, Rui Ueyama via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: ruiu
> Date: Mon Mar  7 22:06:27 2016
> New Revision: 262910
>
> URL: http://llvm.org/viewvc/llvm-project?rev=262910&view=rev
> Log:
> ELF: Add /lib and /usr/lib as default search paths.
>
> GNU ld and gold have these paths as default search paths.
> If you don't want these directories, pass -nostdlib.
>
> Added:
>     lld/trunk/test/ELF/Inputs/nostdlib.s
>     lld/trunk/test/ELF/nostdlib.s
> Modified:
>     lld/trunk/ELF/Config.h
>     lld/trunk/ELF/Driver.cpp
>     lld/trunk/ELF/LinkerScript.cpp
>     lld/trunk/ELF/Options.td
>
> Modified: lld/trunk/ELF/Config.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=262910&r1=262909&r2=262910&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Config.h (original)
> +++ lld/trunk/ELF/Config.h Mon Mar  7 22:06:27 2016
> @@ -67,6 +67,7 @@ struct Configuration {
>    bool Mips64EL = false;
>    bool NoInhibitExec;
>    bool NoUndefined;
> +  bool Nostdlib;
>    bool PrintGcSections;
>    bool Relocatable;
>    bool Shared;
>
> Modified: lld/trunk/ELF/Driver.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=262910&r1=262909&r2=262910&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Driver.cpp (original)
> +++ lld/trunk/ELF/Driver.cpp Mon Mar  7 22:06:27 2016
> @@ -207,9 +207,6 @@ void LinkerDriver::main(ArrayRef<const c
>
>  // Initializes Config members by the command line options.
>  void LinkerDriver::readConfigs(opt::InputArgList &Args) {
> -  for (auto *Arg : Args.filtered(OPT_L))
> -    Config->SearchPaths.push_back(Arg->getValue());
> -
>    std::vector<StringRef> RPaths;
>    for (auto *Arg : Args.filtered(OPT_rpath))
>      RPaths.push_back(Arg->getValue());
> @@ -237,6 +234,7 @@ void LinkerDriver::readConfigs(opt::Inpu
>    Config->ICF = Args.hasArg(OPT_icf);
>    Config->NoInhibitExec = Args.hasArg(OPT_noinhibit_exec);
>    Config->NoUndefined = Args.hasArg(OPT_no_undefined);
> +  Config->Nostdlib = Args.hasArg(OPT_nostdlib);
>    Config->PrintGcSections = Args.hasArg(OPT_print_gc_sections);
>    Config->Relocatable = Args.hasArg(OPT_relocatable);
>    Config->Shared = Args.hasArg(OPT_shared);
> @@ -279,6 +277,14 @@ void LinkerDriver::readConfigs(opt::Inpu
>
>    for (auto *Arg : Args.filtered(OPT_undefined))
>      Config->Undefined.push_back(Arg->getValue());
> +
> +  if (!Config->Nostdlib) {
> +    Config->SearchPaths.push_back("=/lib");
> +    Config->SearchPaths.push_back("=/usr/lib");
> +  }
> +
> +  for (auto *Arg : Args.filtered(OPT_L))
> +    Config->SearchPaths.push_back(Arg->getValue());
>  }
>
>  void LinkerDriver::createFiles(opt::InputArgList &Args) {
>
> Modified: lld/trunk/ELF/LinkerScript.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=262910&r1=262909&r2=262910&view=diff
> ==============================================================================
> --- lld/trunk/ELF/LinkerScript.cpp (original)
> +++ lld/trunk/ELF/LinkerScript.cpp Mon Mar  7 22:06:27 2016
> @@ -396,7 +396,9 @@ void ScriptParser::readOutputFormat() {
>
>  void ScriptParser::readSearchDir() {
>    expect("(");
> -  Config->SearchPaths.push_back(next());
> +  StringRef Path = next();
> +  if (!Config->Nostdlib)
> +    Config->SearchPaths.push_back(Path);
>    expect(")");
>  }
>
>
> Modified: lld/trunk/ELF/Options.td
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=262910&r1=262909&r2=262910&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Options.td (original)
> +++ lld/trunk/ELF/Options.td Mon Mar  7 22:06:27 2016
> @@ -91,6 +91,9 @@ def noinhibit_exec : Flag<["--"], "noinh
>  def no_undefined : Flag<["--"], "no-undefined">,
>    HelpText<"Report unresolved symbols even if the linker is creating a shared library">;
>
> +def nostdlib: Flag<["-", "--"], "nostdlib">,
> +  HelpText<"Only search directories specified on the command line">;
> +
>  def o : JoinedOrSeparate<["-"], "o">, MetaVarName<"<path>">,
>    HelpText<"Path to file to write output">;
>
>
> Added: lld/trunk/test/ELF/Inputs/nostdlib.s
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/nostdlib.s?rev=262910&view=auto
> ==============================================================================
> --- lld/trunk/test/ELF/Inputs/nostdlib.s (added)
> +++ lld/trunk/test/ELF/Inputs/nostdlib.s Mon Mar  7 22:06:27 2016
> @@ -0,0 +1,3 @@
> +.globl foo
> +foo:
> +  ret
>
> Added: lld/trunk/test/ELF/nostdlib.s
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/nostdlib.s?rev=262910&view=auto
> ==============================================================================
> --- lld/trunk/test/ELF/nostdlib.s (added)
> +++ lld/trunk/test/ELF/nostdlib.s Mon Mar  7 22:06:27 2016
> @@ -0,0 +1,16 @@
> +# REQUIRES: x86
> +
> +# RUN: mkdir -p %t.dir/lib
> +# RUN: mkdir -p %t.dir/usr/lib
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/nostdlib.s -o %t2.o
> +# RUN: ld.lld -shared -o %t.dir/lib/libfoo.so %t2.o
> +# RUN: ld.lld -shared -o %t.dir/usr/lib/libbar.so %t2.o
> +# RUN: ld.lld --sysroot=%t.dir -o %t %t1.o -lfoo
> +# RUN: ld.lld --sysroot=%t.dir -o %t %t1.o -lbar
> +# RUN: not ld.lld --sysroot=%t.dir -nostdlib -o %t %t1.o -lfoo
> +# RUN: not ld.lld --sysroot=%t.dir -nostdlib -o %t %t1.o -lbar
> +
> +.globl _start
> +_start:
> +  ret
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list