[PATCH] D33259: Don't defer to the GCC driver for linking arm-baremetal

Saleem Abdulrasool via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 22 21:12:58 PDT 2017

compnerd added inline comments.

Comment at: lib/Driver/ToolChains/BareMetal.cpp:68
+  SmallString<128> Dir(getDriver().ResourceDir);
+  llvm::sys::path::append(Dir, "lib", "baremetal");
+  return Dir.str();
jroelofs wrote:
> compnerd wrote:
> > jroelofs wrote:
> > > compnerd wrote:
> > > > Why not just the standard `arm` directory?
> > > There are a few differences between the stuff in the existing ones, and what is needed on baremetal. For example __enable_execute_stack, emutls, as well as anything else that assumes existence of pthreads support shouldn't be there.
> > Well, I think that "baremetal" here is a bad idea.  How about using the android approach?  Use `clang_rt.builtins-arm-baremetal.a` ?
> Why? Given the way the cmake goop works in lib/runtimes + compiler-rt, the folder name there has to be the same as the CMAKE_SYSTEM_NAME. The alternative, I guess, is to call it 'generic', but I'm not convinced that's better than 'baremetal'.
Because I can have a baremetal environment that uses a different architecture.  How do you differentiate between the MIPS and ARM bare metal runtimes?  The way that the compiler actually looks up the builtins is that it uses `clang_rt.[component]-[arch][-variant]`

Comment at: lib/Driver/ToolChains/BareMetal.h:42
+  const char *getDefaultLinker() const override { return "ld.lld"; }
ruiu wrote:
> jroelofs wrote:
> > compnerd wrote:
> > > jroelofs wrote:
> > > > compnerd wrote:
> > > > > I think that this really should be `ld` still, as that is the canonical name for the linker.
> > > > You mean `lld`?
> > > > 
> > > > ```
> > > > $ lld
> > > > lld is a generic driver.
> > > > Invoke ld.lld (Unix), ld (macOS) or lld-link (Windows) instead.
> > > > ```
> > > > 
> > > > Or are you saying: "make binutils ld the default, not llvm's lld"?
> > > Im saying use the name "ld".  ld is a symlink on most linux distributions these days.  ld -> ld.gold, ld.bfd, ld.lld
> > I don't think this makes sense. I don't care about "most linux distributions", but rather about putting together an LLVM baremetal distribution based as much as possible on LLVM components. If someone wants a different linker, they can use `-fuse-ld=` and/or `-B`.
> > 
> > Also, doesn't using a symlink named `ld` cause `lld` to behave like a mach-o linker? We really want the elf one here.
> If you invoke lld as ld, it behaves as a Mach-O linker on macOS. On other OSes, it behaves as an ELF linker.
`ld` really is just the unix name for the linker.  I think that at some point we are going to have to consider cross-linking with lld.  Adding a `-flavor <flavor>` with `-fuse-ld=lld` makes sense I think.


More information about the cfe-commits mailing list