Re: Why is main's system clang (12.0.1-rc2) using /usr/local/bin/aarch64-unknown-freebsd14.0-ld ? (such breaks things)

From: Mark Millard via toolchain <toolchain_at_freebsd.org>
Date: Fri, 16 Jul 2021 00:53:48 -0700
On 2021-Jul-16, at 00:42, David Chisnall <theraven at FreeBSD.org> wrote:

> On 16/07/2021 01:21, Mark Millard via freebsd-toolchain wrote:
>> Context:
>> # uname -apKU
>> FreeBSD CA72_16Gp_ZFS 14.0-CURRENT FreeBSD 14.0-CURRENT #10 main-n247756-348c41d1815d-dirty: Mon Jul  5 10:23:55 PDT 2021     root_at_CA72_16Gp_ZFS:/usr/obj/BUILDs/main-CA72-nodbg-clang/usr/main-src/arm64.aarch64/sys/GENERIC-NODBG-CA72  arm64 aarch64 1400025 1400025
>> Showing a trivial example . . .
>> # cat trivial.cpp
>> // # c++ -v -o trival trivial.cpp
>> int main() {
>> }
>> # c++ -v
>> FreeBSD clang version 12.0.1 (git_at_github.com:llvm/llvm-project.git llvmorg-12.0.1-rc2-0-ge7dac564cd0e)
>> Target: aarch64-unknown-freebsd14.0
>> Thread model: posix
>> InstalledDir: /usr/bin
>> # c++ -v -o trivial trivial.cpp
>> FreeBSD clang version 12.0.1 (git_at_github.com:llvm/llvm-project.git llvmorg-12.0.1-rc2-0-ge7dac564cd0e)
>> Target: aarch64-unknown-freebsd14.0
>> Thread model: posix
>> InstalledDir: /usr/bin
>>  "/usr/bin/c++" -cc1 -triple aarch64-unknown-freebsd14.0 -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name trivial.cpp -mrelocation-model static -mframe-pointer=non-leaf -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu generic -target-feature +neon -target-abi aapcs -fallow-half-arguments-and-returns -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /usr/lib/clang/12.0.1 -internal-isystem /usr/include/c++/v1 -fdeprecated-macro -fdebug-compilation-dir /usr/home/root/c_tests -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -faddrsig -o /tmp/trivial-5d90b5.o -x c++ trivial.cpp
>> clang -cc1 version 12.0.1 based upon LLVM 12.0.1 default target aarch64-unknown-freebsd14.0
>> #include "..." search starts here:
>> #include <...> search starts here:
>>  /usr/include/c++/v1
>>  /usr/lib/clang/12.0.1/include
>>  /usr/include
>> End of search list.
>>  "/usr/local/bin/aarch64-unknown-freebsd14.0-ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --enable-new-dtags -o trivial /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/trivial-5d90b5.o -lc++ -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o
>> CA72_16Gp_ZFS# c++ -v
>> FreeBSD clang version 12.0.1 (git_at_github.com:llvm/llvm-project.git llvmorg-12.0.1-rc2-0-ge7dac564cd0e)
>> Target: aarch64-unknown-freebsd14.0
>> Thread model: posix
>> InstalledDir: /usr/bin
>> Note the "/usr/local/bin/aarch64-unknown-freebsd14.0-ld" path
>> for ld.
>> I've an example where this usage leads to:
>> /usr/local/bin/aarch64-unknown-freebsd14.0-ld: /usr/bin/../lib/LLVMgold.so: error loading plugin: Cannot open "/usr/bin/../lib/LLVMgold.so"
>> clang++: error: linker command failed with exit code 1 (use -v to see invocation)
> 
> This is the documented behaviour for clang when cross-compiling.

The host is aarch64 and the target is aarch64 and the command was:

# c++ -v -o trivial trivial.cpp

So: no cross compile is involved.

> You can specify a target in one of two ways with clang:
> 
> - Via the -target flag.

Not used in the command line reported for the trivial example:

# c++ -v -o trivial trivial.cpp

> - By invoking clang with a symlink named {target}-clang[++]

Also not involved.

> Clang will look for all of the tools in your path (or in the tree specified with -B if you provide an alternative location for tools).

# echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/home/root/bin

No -B in:

# c++ -v -o trivial trivial.cpp

> If clang finds {target}-{tool name} then it will invoke this in preference to {tool name}.  This avoids situations where, for example, your system ld is BFD ld (or any other linker that doesn't support cross-linking) and you are cross compiling.

I'm not cross compiling.

> In general, if you are cross building anything and not specifying --sysroot (to tell it where to find headers and libraries for the target) and -B (to tell it where to find tools) then you are probably doing something wrong.
> 

I'm not cross compiling.

I've no clue why the linker name it is looking for is:
aarch64-unknown-freebsd14.0-ld : seems wrong to me when
not corss compiling.

But:

# find / -name aarch64-unknown-freebsd14.0-ld -print | more
/usr/local/bin/aarch64-unknown-freebsd14.0-ld

So: it did find the only instance of what it looked for. It
just looked for the wrong thing.

===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)
Received on Fri Jul 16 2021 - 07:53:48 UTC

Original text of this message