[llvm-commits] PATCH: Add support for tracking and exposing the host triple

Joerg Sonnenberger joerg at britannica.bec.de
Tue Jan 24 08:23:41 PST 2012


On Tue, Jan 24, 2012 at 03:59:00AM -0800, Chandler Carruth wrote:
> Attached is a patch to add support for tracking and exposing the host
> triple. This is one of the many steps along the way to cleaning up the
> Clang driver. In many places within Clang, we need to reason about the
> *host*, not the target, in order to decide how to behave. For example, this
> is at issue when deciding where within the host machine we should look for
> the target's toolchain. While in some cases, there is a canonical location
> that the target *always* uses, in other cases both can be relevant.
> Consider the Debian multiarch case where we will often want to use
> '/usr/lib/<host-triple>/gcc/<target-triple>/<version>/crtbegin.o'. In other
> cases, we may need to check whether the host triple might contain a
> toolchain capable of targeting our target. This happens frequently when
> working in a bi-arch world, where the GCC installed under
> 'i386-pc-linux-gnu' is actually capable of targeting 'x86_64-pc-linux-gnu'
> thanks to the '-m64' flag.

I disagree with this. I don't the host OS is involved in any of the
decisions. Let me summarize how NetBSD handles this case, I think the
same applies to other platforms and can be moved into the upper layers.

When clang is invoked, it derives the base target either from program
name, command line or configuration. During the NetBSD build, it is
always the program name (e.g. x86_64--netbsd-clang). This base target is
memorised and used for finding the tool chain, so that e.g.
x86_64--netbsd-ld is used as linker. If the driver finds -m32 on the
command line, three things change. The triple for the compiler invocation
is changed to i386--netbsd. This changes the code generation only.
Second, the library search path is changed from =/usr/lib to =/usr/lib/i386.
That's where crt0.o and friends can be found. This differs from a
"native" i386--netbsd compiler, since that expects the path correctly in
=/usr/lib to match the native environment. Third, -m elf_i386 is passed
to ld.

I don't see how the Debian case is different. Use the compiler target
triple (after -m32 / -m64 modifications) to look up the library path for
crt*.o. Pick the correct ld emulation, if it differs from the base
triple. Not sure how consistent the emulation list is on Linux to be
able to always specify it.

Joerg



More information about the llvm-commits mailing list