[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#1009675: marked as done (GCC toolchain is broken on Debian 11 aarch64 when creating shared libraries)



Your message dated Thu, 14 Apr 2022 09:44:35 +0200
with message-id <5cdb5432-f1d9-9bb8-ee67-43905baa44ba@debian.org>
and subject line Re: GCC toolchain is broken on Debian 11 aarch64 when creating shared libraries
has caused the Debian Bug report #1009675,
regarding GCC toolchain is broken on Debian 11 aarch64 when creating shared libraries
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@bugs.debian.org
immediately.)


-- 
1009675: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1009675
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems
--- Begin Message ---
Package: gcc
Version: 10.2.1


When I try to create shared libraries and link to them, I get
"undefined reference to" errors, where linker cannot find referenced
symbols in the shared library.

I tried the same program on Debian 10 x86_64 and it links correctly.

The issue can be reproduced with the following steps:

Create libtest.c:
cat > libtest.c << 'EOF'
#include <stdio.h>

void test(void)
{
        printf("This is a test\n");
}
EOF

Create main.c that uses symbols from libtest:
cat > main.c << 'EOF'
void test(void);
int main(void)
{
        test();
}
EOF

Create libtest.so shared library:
gcc -O2 -fPIC -DPIC -c libtest.c && \
gcc -O2 -fPIC -DPIC -shared -Wl,--default-symver -Wl,-soname,libtest.so.
1 -o libtest.so.1.0 libtest.o && \ ln -sf libtest.so.1.0 libtest.so

Create main executable, linking it with libtest.so:
gcc -O2 -c main.c && \
gcc -O2 -L./ -ltest -o main main.c

The above step fails with the following error:
/bin/ld: /tmp/ccZq9tP1.o: in function `main':
main.c:(.text.startup+0x8): undefined reference to `test'
collect2: error: ld returned 1 exit status


Below are the specifics of my dev environment:

$ uname -a
Linux rp4 5.10.0-13-arm64 #1 SMP Debian 5.10.106-1 (2022-03-17) aarch64
GNU/Linux

$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/";
SUPPORT_URL="https://www.debian.org/support";
BUG_REPORT_URL="https://bugs.debian.org/";

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/10/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian
10.2.1-6' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-10
--program-prefix=aarch64-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-libquadmath --disable-libquadmath-support --enable-plugin
--enable-default-pie --with-system-zlib
--enable-libphobos-checking=release --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --enable-fix-cortex-a53-843419
--disable-werror --enable-checking=release --build=aarch64-linux-gnu
--host=aarch64-linux-gnu --target=aarch64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-mutex Thread
model: posix Supported LTO compression algorithms: zlib zstd gcc
version 10.2.1 20210110 (Debian 10.2.1-6) 

--- End Message ---
--- Begin Message ---
control: close -1
On Thu, 14 Apr 2022 08:28:47 +0100 Sad Clouds <cryintothebluesky@gmail.com> wrote:
Package: gcc
Version: 10.2.1


When I try to create shared libraries and link to them, I get
"undefined reference to" errors, where linker cannot find referenced
symbols in the shared library.

I tried the same program on Debian 10 x86_64 and it links correctly.

The issue can be reproduced with the following steps:

Create libtest.c:
cat > libtest.c << 'EOF'
#include <stdio.h>

void test(void)
{
        printf("This is a test\n");
}
EOF

Create main.c that uses symbols from libtest:
cat > main.c << 'EOF'
void test(void);
int main(void)
{
        test();
}
EOF

Create libtest.so shared library:
gcc -O2 -fPIC -DPIC -c libtest.c && \
gcc -O2 -fPIC -DPIC -shared -Wl,--default-symver -Wl,-soname,libtest.so.
1 -o libtest.so.1.0 libtest.o && \ ln -sf libtest.so.1.0 libtest.so

Create main executable, linking it with libtest.so:
gcc -O2 -c main.c && \
gcc -O2 -L./ -ltest -o main main.c



Wl,as-needed flag (now default) strips libraries from line if not used.
$(CC) $(CPPFLAGS) *.o -L $(LIBS).

You are putting the libraries at the begin, then they are just stripped out.

This should work instead.

gcc -O2 -o main main.c  -L./ -ltest

The above step fails with the following error:
/bin/ld: /tmp/ccZq9tP1.o: in function `main':
main.c:(.text.startup+0x8): undefined reference to `test'
collect2: error: ld returned 1 exit status


Below are the specifics of my dev environment:

$ uname -a
Linux rp4 5.10.0-13-arm64 #1 SMP Debian 5.10.106-1 (2022-03-17) aarch64
GNU/Linux

$ cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/";

--- End Message ---

Reply to: