[LLVMbugs] [Bug 10744] New: Can't specify linker to use with the -B flag

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Aug 25 11:45:27 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=10744

           Summary: Can't specify linker to use with the -B flag
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Driver
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: glotov at chromium.org
                CC: llvmbugs at cs.uiuc.edu


$ clang
-B/usr/x86_64-pc-linux-gnu/i686-pc-linux-gnu/binutils-bin/2.20.1-gold/ld test.c
uses linker at
"/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/../../../../x86_64-pc-linux-gnu/bin/ld"
and ignores one specified by -B. To see it, use -v.

I think this is because of the following code:

In tools/clang/lib/Driver/ToolChains.cpp:

 llvm::sys::Path LinkerPath(Base + "/../../../../" + GccTriple + "/bin/ld");
 if (!llvm::sys::fs::exists(LinkerPath.str(), Exists) && Exists)
   Linker = LinkerPath.str();
 else
   Linker = GetProgramPath("ld");

So it tries to use the first guess
(/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/../../../../x86_64-pc-linux-gnu/bin/ld)
linker, and only if not found, it invokes ToolChain::GetProgramPath("ld",
true), which calls Driver::GetProgramPath("ld", this, true):

In tools/clang/lib/Driver/Driver.cpp:

std::string Driver::GetProgramPath(const char *Name, const ToolChain &TC,
                                   bool WantFile) const {
  // Respect a limited subset of the '-Bprefix' functionality in GCC by
  // attempting to use this prefix when lokup up program paths.
  for (Driver::prefix_list::const_iterator it = PrefixDirs.begin(),
       ie = PrefixDirs.end(); it != ie; ++it) {
    llvm::sys::Path P(*it);
    P.appendComponent(Name);
    bool Exists;
    if (WantFile ? !llvm::sys::fs::exists(P.str(), Exists) && Exists
                 : P.canExecute())
      return P.str();
  }
...

So it does respect -B, but only if the first guess not found.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list