[llvm-bugs] [Bug 45693] New: Fails to detect toolchain for cross-compilation for bare metal

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Apr 27 02:23:25 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=45693

            Bug ID: 45693
           Summary: Fails to detect toolchain for cross-compilation for
                    bare metal
           Product: clang
           Version: 10.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: shumenda at gmx.de
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Clang fails to detect the correct toolchain `aarch64-none-elf`, even though the
binaries with the appropriate prefix are on the path and callable using
`aarch64-none-elf-<SUFFIX>`. I am using the GCC provided by ARM.

According to <https://clang.llvm.org/docs/CrossCompilation.html>:

> 2. When you have installed via a package manager (modern Linux distributions have cross-compiler
>    packages available), make sure the target triple you set is also the prefix of your
>    cross-compiler toolchain.

```
$ cat main.c
int main(int argc, const char *argv[]) {
    return 0;
}
void _exit() { }

$ whereis aarch64-none-elf-gcc
aarch64-none-elf-gcc: <snip>/aarch64-none-elf/bin/aarch64-none-elf-gcc
$ whereis aarch64-none-elf-ld
aarch64-none-elf-ld: <snip>/aarch64-none-elf/bin/aarch64-none-elf-ld

$ clang-10 -ffreestanding --target=aarch64-none-elf -v main.c
clang version 10.0.0-+rc4-1 
Target: aarch64-none-unknown-elf
Thread model: posix
InstalledDir: /usr/bin
 "/usr/lib/llvm-10/bin/clang" -cc1 -triple aarch64-none-unknown-elf -emit-obj
-mrelax-all -disable-free -disable-llvm-verifier -discard-value-names
-main-file-name main.c -mrelocation-model static -mthread-model posix
-mframe-pointer=non-leaf -fmath-errno -fno-rounding-math -masm-verbose
-mconstructor-aliases -target-cpu generic -target-feature +neon -target-abi
aapcs -fallow-half-arguments-and-returns -dwarf-column-info
-fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir
/usr/lib/llvm-10/lib/clang/10.0.0 -fdebug-compilation-dir $MYDIR/mwe-bug
-ferror-limit 19 -fmessage-length 0 -fno-signed-char -fgnuc-version=4.2.1
-fobjc-runtime=gcc -fdiagnostics-show-option -faddrsig -o /tmp/main-23e708.o -x
c main.c
clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target
x86_64-pc-linux-gnu
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/llvm-10/lib/clang/10.0.0/include
 /usr/include
End of search list.
 "/usr/bin/gcc" -v -o a.out /tmp/main-23e708.o
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 8.3.0-6'
--with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-8
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie
--with-system-zlib --with-target-system-zlib --enable-objc-gc=auto
--enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Debian 8.3.0-6) 
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'a.out' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/8/collect2 -plugin
/usr/lib/gcc/x86_64-linux-gnu/8/liblto_plugin.so
-plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccuHuXrq.res -plugin-opt=-pass-through=-lgcc
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id
--eh-frame-hdr -m elf_x86_64 --hash-style=gnu -dynamic-linker
/lib64/ld-linux-x86-64.so.2 -pie -o a.out
/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o
/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/8/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/8
-L/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu
-L/usr/lib/gcc/x86_64-linux-gnu/8/../../../../lib -L/lib/x86_64-linux-gnu
-L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib
-L/usr/lib/gcc/x86_64-linux-gnu/8/../../.. /tmp/main-23e708.o -lgcc
--push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed
-lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/8/crtendS.o
/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crtn.o
/usr/bin/ld: unknown architecture of input file `/tmp/main-23e708.o' is
incompatible with i386:x86-64 output
collect2: error: ld returned 1 exit status
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see
invocation)
```

In `##llvm` I was told to use the (apparently obsolete) `-ccc-gcc-name
aarch64-none-elf-gcc` which
works. However, I would like to benefit from the advertised default behaviour
that Clang will pick
up the correct toolchain if installed and the correct triple is supplied to
Clang.

Using `--sysroot` doesn't work either because it still doesn't pick up the
prefix.

Thanks

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200427/9e31e3b7/attachment.html>


More information about the llvm-bugs mailing list