[PATCH] D100054: Handle flags such as -m32 when computing the triple prefix for programs

Alexander Richardson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 7 11:18:17 PDT 2021


arichardson created this revision.
arichardson added reviewers: MaskRay, phosek.
Herald added subscribers: frasercrmck, luismarques, apazos, sameer.abuasal, pengfei, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, krytarowski, emaste.
arichardson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I was trying to use -DLLVM_ENABLE_RUNTIMES=compiler-rt on FreeBSD and this
failed since the 32-bit build ended up linking against the 64-bit ASAN
runtime and linking with "/usr/local/bin/x86_64-unknown-freebsd12.2-ld".
Looking at the driver code shows that the triple used as a prefix for tools
and libaries is always the raw value passed to -target and is not affected
by flags such as -m32/-march/etc.

This commit uses computeTargetTriple() to update the triple used as a
prefix for tools such as the linker. If computeTargetTriple() results in
a different triple, we update the RawTargetTriple and now search for
i386-unknown-freebsd12.2-ld when -m32 is passed. It is important to note
that we do not normalize the triple passed to -target since adding
additional could result in an unexpected behaviour change. For example,
`clang -target x86_64-freebsd13` should search for x86_64-freebsd13-ld
and not the normalized x86_64-unknown-freebsd13-ld and
`clang -target x86_64-freebsd13 -m32` tries to find i386-unknown-freebsd13-ld.

Depends on D99996 <https://reviews.llvm.org/D99996> (not functionally, but required to compile correctly)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100054

Files:
  clang/include/clang/Driver/Driver.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  clang/test/Driver/Inputs/basic_freebsd64_tree/usr/bin/i386-unknown-freebsd12.2-ld
  clang/test/Driver/Inputs/basic_freebsd64_tree/usr/bin/x86_64-unknown-freebsd12.2-ld
  clang/test/Driver/freebsd-m32.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100054.335876.patch
Type: text/x-patch
Size: 12670 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210407/c493fafe/attachment-0001.bin>


More information about the cfe-commits mailing list