From nobody Fri Jul 16 07:42:56 2021 X-Original-To: toolchain@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id DC1908D528B for ; Fri, 16 Jul 2021 07:42:58 +0000 (UTC) (envelope-from theraven@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GR3BB5pHlz3j3D for ; Fri, 16 Jul 2021 07:42:58 +0000 (UTC) (envelope-from theraven@FreeBSD.org) Received: from smtp.theravensnest.org (smtp.theravensnest.org [45.77.103.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: theraven) by smtp.freebsd.org (Postfix) with ESMTPSA id AAE7E2A6B0 for ; Fri, 16 Jul 2021 07:42:58 +0000 (UTC) (envelope-from theraven@FreeBSD.org) Received: from [192.168.1.202] (host86-191-32-244.range86-191.btcentralplus.com [86.191.32.244]) by smtp.theravensnest.org (Postfix) with ESMTPSA id C33BC2ADA9 for ; Fri, 16 Jul 2021 08:42:57 +0100 (BST) Subject: Re: Why is main's system clang (12.0.1-rc2) using /usr/local/bin/aarch64-unknown-freebsd14.0-ld ? (such breaks things) To: toolchain@freebsd.org References: <7073D16F-4505-4948-8232-A9618DF2FE5F.ref@yahoo.com> <7073D16F-4505-4948-8232-A9618DF2FE5F@yahoo.com> From: David Chisnall Message-ID: Date: Fri, 16 Jul 2021 08:42:56 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 List-Id: Maintenance List-Archive: https://lists.freebsd.org/archives/freebsd-toolchain List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-toolchain@freebsd.org X-BeenThere: freebsd-toolchain@freebsd.org MIME-Version: 1.0 In-Reply-To: <7073D16F-4505-4948-8232-A9618DF2FE5F@yahoo.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-ThisMailContainsUnwantedMimeParts: N 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@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@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@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@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. You can specify a target in one of two ways with clang: - Via the -target flag. - By invoking clang with a symlink named {target}-clang[++] 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). 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. 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. David