FS#70688 - [aarch64-linux-gnu-gcc] Can't link a simple C program using custom --sysroot

Attached to Project: Community Packages
Opened by João Maia (jpmmaia) - Monday, 03 May 2021, 07:26 GMT
Last edited by Buggy McBugFace (bugbot) - Saturday, 25 November 2023, 20:02 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To Anatol Pomozov (anatolik)
Architecture x86_64
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 3
Private No

Details

Description:

Running `aarch64-linux-gnu-gcc hello.c` works fine. However, `aarch64-linux-gnu-gcc --sysroot=/path/to/custom/sysroot hello.c` produces the following errors:

```
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /lib/libc.so.6 when searching for /lib/libc.so.6
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: cannot find /lib/libc.so.6
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /lib/libc.so.6 when searching for /lib/libc.so.6
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /lib/libc_nonshared.a when searching for /lib/libc_nonshared.a
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: cannot find /lib/libc_nonshared.a
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /lib/libc_nonshared.a when searching for /lib/libc_nonshared.a
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: cannot find /lib/ld-linux-aarch64.so.1
```

I have the `community/aarch64-linux-gnu-glibc` package installed.


Additional info:
* package version(s): community/aarch64-linux-gnu-gdb 10.1-2 ; community/aarch64-linux-gnu-glibc 2.33-1

Steps to reproduce:

The above problem happens when using a custom ARM64 sysroot created using debootstrap. However, the same happens if I do the following:

```
$ cp -r /usr/aarch64-linux-gnu .
$ aarch64-linux-gnu-gcc --sysroot=$(pwd)/aarch64-linux-gnu hello.c
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /lib/libc.so.6 when searching for /lib/libc.so.6
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: cannot find /lib/libc.so.6
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /lib/libc.so.6 when searching for /lib/libc.so.6
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /lib/libc_nonshared.a when searching for /lib/libc_nonshared.a
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: cannot find /lib/libc_nonshared.a
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /lib/libc_nonshared.a when searching for /lib/libc_nonshared.a
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: cannot find /lib/ld-linux-aarch64.so.1
```

However, this works fine: `$ aarch64-linux-gnu-gcc --sysroot=/usr/aarch64-linux-gnu hello.c`
This task depends upon

Closed by  Buggy McBugFace (bugbot)
Saturday, 25 November 2023, 20:02 GMT
Reason for closing:  Moved
Additional comments about closing:  https://gitlab.archlinux.org/archlinux/p ackaging/packages/aarch64-linux-gnu-gcc/ issues/1
Comment by Etienne Andre (etiandre) - Wednesday, 12 October 2022, 09:13 GMT
Can reproduce the issue using aarch64-linux-gnu-gcc pkg version 12.2.0-1 using these steps:

echo "int main() {return 0;}" > test.c
aarch64-linux-gnu-gcc --sysroot=/path/to/custom/sysroot test.c

/usr/lib/gcc/aarch64-linux-gnu/12.2.0/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /lib/libc.so.6 when searching for /lib/libc.so.6
/usr/lib/gcc/aarch64-linux-gnu/12.2.0/../../../../aarch64-linux-gnu/bin/ld: cannot find /lib/libc.so.6: file in wrong format
/usr/lib/gcc/aarch64-linux-gnu/12.2.0/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /lib/libc.so.6 when searching for /lib/libc.so.6
/usr/lib/gcc/aarch64-linux-gnu/12.2.0/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /lib/libc_nonshared.a when searching for /lib/libc_nonshared.a
/usr/lib/gcc/aarch64-linux-gnu/12.2.0/../../../../aarch64-linux-gnu/bin/ld: cannot find /lib/libc_nonshared.a: file in wrong format
/usr/lib/gcc/aarch64-linux-gnu/12.2.0/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /lib/libc_nonshared.a when searching for /lib/libc_nonshared.a
/usr/lib/gcc/aarch64-linux-gnu/12.2.0/../../../../aarch64-linux-gnu/bin/ld: cannot find /lib/ld-linux-aarch64.so.1: No such file or directory
collect2: error: ld returned 1 exit status


Seems like ld ignores the --sysroot option and searches libraries in /.

If it's of any use, here is the output of aarch64-linux-gnu-gcc -v:

Using built-in specs.
COLLECT_GCC=aarch64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/12.2.0/lto-wrapper
Target: aarch64-linux-gnu
Configured with: /build/aarch64-linux-gnu-gcc/src/gcc-12.2.0/configure --prefix=/usr --program-prefix=aarch64-linux-gnu- --with-local-prefix=/usr/aarch64-linux-gnu --with-sysroot=/usr/aarch64-linux-gnu --with-build-sysroot=/usr/aarch64-linux-gnu --with-native-system-header-dir=/include --libdir=/usr/lib --libexecdir=/usr/lib --target=aarch64-linux-gnu --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-nls --enable-default-pie --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (GCC)

For reference, here is the output of aarch64-linux-gnu-gcc -v on Ubuntu 18.04, where there is no such issue:

Using built-in specs.
COLLECT_GCC=aarch64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/aarch64-linux-gnu/7/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=aarch64-linux-gnu --program-prefix=aarch64-linux-gnu- --includedir=/usr/aarch64-linux-gnu/include
Thread model: posix
gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
Comment by Chia-I Wu (olv) - Monday, 24 October 2022, 00:07 GMT
I found this bug after I filed  FS#76279 .

gcc correctly find /usr/aarch64-linux-gnu/lib/libc.so. But the file is an ld script that points to /lib/libc.so.6. If you manually modify the script to point to /usr/aarch64-linux-gnu/lib/libc.so.6, it will work.

For comparison, /usr/aarch64-linux-gnu/lib/libc.so points to /usr/aarch64-linux-gnu/lib/libc.so.6 on Debian.

Comment by Chia-I Wu (olv) - Monday, 24 October 2022, 00:12 GMT
By the way, notice how "--with-sysroot" differs on Arch and Ubuntu. I think that makes /usr/aarch64-linux-gnu a special case on Arch. As a result, `aarch64-linux-gnu-gcc --sysroot=/usr/aarch64-linux-gnu` works but other sysroot paths fail.
Comment by Anatol Pomozov (anatolik) - Monday, 24 October 2022, 01:01 GMT
Do you have a patch for PKGBUILD that fixes the problem?
Comment by Chia-I Wu (olv) - Monday, 24 October 2022, 17:23 GMT
No, sorry. I don't have experience building glibc :)

The libc.so ld script is generated here

https://sourceware.org/git/?p=glibc.git;a=blob;f=Makerules;h=d1e139d03c1c448e14aee35af3e54ee7abe2180c;hb=refs/tags/glibc-2.36#l1040

I suppose we need to make sure slibdir expands to /usr/aarch64-linux-gnu/lib
Comment by Buggy McBugFace (bugbot) - Tuesday, 08 August 2023, 19:11 GMT
This is an automated comment as this bug is open for more then 2 years. Please reply if you still experience this bug otherwise this issue will be closed after 1 month.

Loading...