Skip to contentSkip to conversation

glibc link fails on x86_64 with fPIC error

Buildroot mws 3 participants 7 messages Nov 6, 2018 1 message not in the archive

lore
Share & tools
lore

mws

author
#0 lore raw

I'm using buildroot-2018.08.2 to build for x86_64 using essentially the defaults for that release (glibc 2.27, gcc 7.3.0) but enabling glibc for the toolchain. The toolchain build goes very well until it gets to glibc in the elf/ subdirectory at which point it blows up with an fPIC error on the link test shown below.

I've tried varying gcc version, binutils version to see if this is some defaults problem with no luck. Has anyone else seen this before or have advice on fixing? Fundamentally it seems like basic out-of-the-box x86_64 + glibc is not able to build with this buildroot release.

---

buildroot/host/bin/x86_64-buildroot-linux-gnu-gcc -nostdlib -nostartfiles
-r -o buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/librtld.os '-Wl,-(' buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/dl-allobjs.os buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/rtld-libc.a -lgcc '-Wl,-)' \

-Wl,-Map,buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/librtld.os.map
buildroot/host/bin/x86_64-buildroot-linux-gnu-gcc -nostdlib -nostartfiles
-shared -o buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/ld.so.new

\
          -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs      

\

buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/librtld.os -Wl,--version-script=buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/ld.map

\
          -Wl,-soname=ld-linux-x86-64.so.2                      \
          -Wl,-defsym=_begin=0

buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/librtld.os:
In function `dl_main':
rtld.c:(.text+0x25ab): undefined reference to `__open'
rtld.c:(.text+0x2b19): undefined reference to `__access'
rtld.c:(.text+0x442c): undefined reference to `__access' buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/librtld.os:
In function `lose.isra.5':
dl-load.c:(.text+0x486a): undefined reference to `__close' buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/librtld.os:
In function `_dl_map_object_from_fd':
dl-load.c:(.text+0x491c): undefined reference to `__GI___fxstat64' buildroot/host/lib/gcc/x86_64-buildroot-linux-gnu/7.3.0/../../../../x86_64-buildroot-linux-gnu/bin/ld:
buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/librtld.os:
relocation R_X86_64_PC32 against undefined symbol `__GI___fxstat64' can not
be used when making a shared object; recompile with -fPIC buildroot/host/lib/gcc/x86_64-buildroot-linux-gnu/7.3.0/../../../../x86_64-buildroot-linux-gnu/bin/ld:
final link failed: Bad value
collect2: error: ld returned 1 exit status
make[4]: *** [buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/ld.so] Error 1
make[3]: *** [elf/subdir_lib] Error 2
make[2]: *** [all] Error 2
make[1]: *** [buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/.stamp_built] Error 2
make: *** [_all] Error 2

--
Sent from: http://buildroot-busybox.2317881.n4.nabble.com/

#1 lore raw

Mike,

Quoted 7 lines · mws

I'm using buildroot-2018.08.2 to build for x86_64 using essentially the defaults for that release (glibc 2.27, gcc 7.3.0) but enabling glibc for the toolchain. The toolchain build goes very well until it gets to glibc in the elf/ subdirectory at which point it blows up with an fPIC error on the link test shown below.

If looks like some of the hardening features are turned on like relro. Would you mind doing a savedefconfig and provide that defconfig (should be small so just inline here in a response is fine)?

Quoted 64 lines

I've tried varying gcc version, binutils version to see if this is some defaults problem with no luck. Has anyone else seen this before or have advice on fixing? Fundamentally it seems like basic out-of-the-box x86_64 + glibc is not able to build with this buildroot release.

---

buildroot/host/bin/x86_64-buildroot-linux-gnu-gcc -nostdlib -nostartfiles
-r -o buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/librtld.os '-Wl,-(' buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/dl-allobjs.os buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/rtld-libc.a

(quoted diff) +0 -2
-lgcc '-Wl,-)' \
 
-Wl,-Map,buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/librtld.os.map

buildroot/host/bin/x86_64-buildroot-linux-gnu-gcc -nostdlib -nostartfiles
-shared -o buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/ld.so.new

\
          -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs

\

buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/librtld.os -Wl,--version-script=buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/ld.map

\
          -Wl,-soname=ld-linux-x86-64.so.2                      \
          -Wl,-defsym=_begin=0

buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/librtld.os:
In function `dl_main':
rtld.c:(.text+0x25ab): undefined reference to `__open'
rtld.c:(.text+0x2b19): undefined reference to `__access'
rtld.c:(.text+0x442c): undefined reference to `__access' buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/librtld.os:
In function `lose.isra.5':
dl-load.c:(.text+0x486a): undefined reference to `__close' buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/librtld.os:
In function `_dl_map_object_from_fd':
dl-load.c:(.text+0x491c): undefined reference to `__GI___fxstat64' buildroot/host/lib/gcc/x86_64-buildroot-linux-gnu/7.3.0/../../../../x86_64-buildroot-linux-gnu/bin/ld:
buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/librtld.os:
relocation R_X86_64_PC32 against undefined symbol `__GI___fxstat64' can not
be used when making a shared object; recompile with -fPIC buildroot/host/lib/gcc/x86_64-buildroot-linux-gnu/7.3.0/../../../../x86_64-buildroot-linux-gnu/bin/ld:
final link failed: Bad value
collect2: error: ld returned 1 exit status
make[4]: *** [buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/build/elf/ld.so] Error 1
make[3]: *** [elf/subdir_lib] Error 2
make[2]: *** [all] Error 2
make[1]: *** [buildroot/build/glibc-glibc-2.27-57-g6c99e37f6fb640a50a3113b2dbee5d5389843c1e/.stamp_built] Error 2
make: *** [_all] Error 2

--
Sent from: http://buildroot-busybox.2317881.n4.nabble.com/
_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

Signature · 8 lines
Matthew L Weber / Pr Software Engineer
Airborne Information Systems / RC Linux Secure Platforms
MS 131-100, C Ave NE, Cedar Rapids, IA, 52498, USA
www.rockwellcollins.com

Note: Any Export License Required Information and License Restricted
Third Party Intellectual Property (TPIP) content must be encrypted and
sent to matthew.weber at corp.rockwellcollins.com.
author
#2 lore raw
$ cat defconfig
BR2_x86_64=y
BR2_x86_core_avx2=y
BR2_JLEVEL=1
BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
BR2_KERNEL_HEADERS_4_9=y
BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
BR2_PACKAGE_PCIUTILS=y
BR2_PACKAGE_LIBXML2=y
BR2_PACKAGE_ELFUTILS=y
BR2_PACKAGE_LIBCAP=y
BR2_PACKAGE_BASH=y
$ grep -i relro .config
BR2_RELRO_NONE=y
# BR2_RELRO_PARTIAL is not set
# BR2_RELRO_FULL is not set

Thanks for any ideas.

--
Sent from: http://buildroot-busybox.2317881.n4.nabble.com/

#3 lore raw

Hi,

Le 06/11/2018 ? 17:49, mws a ?crit?:

Quoted 4 lines
$ cat defconfig
BR2_x86_64=y
BR2_x86_core_avx2=y
BR2_JLEVEL=1
Quoted 8 lines
BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
BR2_KERNEL_HEADERS_4_9=y
BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
BR2_PACKAGE_PCIUTILS=y
BR2_PACKAGE_LIBXML2=y
BR2_PACKAGE_ELFUTILS=y
BR2_PACKAGE_LIBCAP=y
BR2_PACKAGE_BASH=y

With this defconfig, the toolchain build fine here.

Can you share the full build log ?

Best regards,
Romain

Quoted 17 lines
$ grep -i relro .config
BR2_RELRO_NONE=y
# BR2_RELRO_PARTIAL is not set
# BR2_RELRO_FULL is not set

Thanks for any ideas.

--
Sent from: http://buildroot-busybox.2317881.n4.nabble.com/
_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

Mike,

Quoted 15 lines · Mike Shapiro

$ cat defconfig
BR2_x86_64=y
BR2_x86_core_avx2=y
BR2_JLEVEL=1
BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
BR2_KERNEL_HEADERS_4_9=y
BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
BR2_PACKAGE_PCIUTILS=y
BR2_PACKAGE_LIBXML2=y
BR2_PACKAGE_ELFUTILS=y
BR2_PACKAGE_LIBCAP=y
BR2_PACKAGE_BASH=y

I was able to checkout 2018.08.2, use your defconfig but with BR2_JLEVEL set to 0 and the build was successful. I had the following host machine:
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.4)

Matt

author
#6 lore raw

Thanks Matt and also Roman. In meantime I discovered something interesting:
with libc=musl the build succeeds, but with libc=uClibc-ng it fails in a way similar to glibc, which I think exonerates glibc. Here is the ucLibC failure with the similar linking error:

$ tail -20 tools.log
 AR cr libc/libc_so.a
 STRIP -x -R .note -R .comment libc/libc_so.a
 CC libpthread/nptl/pthread_atfork.oS
 AR cr lib/libpthread_nonshared.a
 STRIP -x -R .note -R .comment lib/libpthread_nonshared.a
 LD libuClibc-1.0.30.so
./lib/ld64-uClibc.so.1: warning: multiple common of
`_dl_internal_error_number'
libc/libc_so.a(libdl.oS): warning: previous common is here
./lib/ld64-uClibc.so.1: warning: multiple common of `_dl_error_number'
libc/libc_so.a(libdl.oS): warning: previous common is here
./lib/ld64-uClibc.so.1: warning: multiple common of `_dl_free_function'
libc/libc_so.a(libdl.oS): warning: previous common is here
./lib/ld64-uClibc.so.1: warning: multiple common of `_dl_malloc_function'
libc/libc_so.a(libdl.oS): warning: previous common is here
/home/build/src/docker/buildroot/host/lib/gcc/x86_64-buildroot-linux-uclibc/7.3.0/../../../../x86_64-buildroot-linux-uclibc/bin/ld:
libc/libc_so.a(libc-cancellation.oS): relocation R_X86_64_PC32 against
symbol `__pthread_unwind' can not be used when making a shared object;
recompile with -fPIC
/home/build/src/docker/buildroot/host/lib/gcc/x86_64-buildroot-linux-uclibc/7.3.0/../../../../x86_64-buildroot-linux-uclibc/bin/ld:
final link failed: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libc.so] Error 1
make[1]: ***
[/home/build/src/docker/buildroot/build/uclibc-1.0.30/.stamp_built] Error 2
make: *** [_all] Error 2

So my hypothesis is that something about my build system environment is causing a misconfiguration of the toolchain with respect to gcc's defaults. I am thinking maybe the pic/PIC default or the mcmodel default is somehow different from what glibc or uClibc-ng Makefiles expect it to be, and they are not setting those options to be explicitly the way they should be in their respective Makefiles.

So I need to figure out what part of the toolchain build is looking at the system itself to determine defaults in this area, or alternatively find the specific gcc setting and change its default manually in buildroot's config.

--
Sent from: http://buildroot-busybox.2317881.n4.nabble.com/

#7 lore raw

Hi,

Le 06/11/2018 ? 21:35, mws a ?crit?:

Quoted 14 lines

Thanks Matt and also Roman. In meantime I discovered something interesting:
with libc=musl the build succeeds, but with libc=uClibc-ng it fails in a way similar to glibc, which I think exonerates glibc. Here is the ucLibC failure with the similar linking error:

$ tail -20 tools.log
 AR cr libc/libc_so.a
 STRIP -x -R .note -R .comment libc/libc_so.a
 CC libpthread/nptl/pthread_atfork.oS
 AR cr lib/libpthread_nonshared.a
 STRIP -x -R .note -R .comment lib/libpthread_nonshared.a
 LD libuClibc-1.0.30.so
./lib/ld64-uClibc.so.1: warning: multiple common of
`_dl_internal_error_number'
Quoted 8 lines
libc/libc_so.a(libdl.oS): warning: previous common is here
./lib/ld64-uClibc.so.1: warning: multiple common of `_dl_error_number'
libc/libc_so.a(libdl.oS): warning: previous common is here
./lib/ld64-uClibc.so.1: warning: multiple common of `_dl_free_function'
libc/libc_so.a(libdl.oS): warning: previous common is here
./lib/ld64-uClibc.so.1: warning: multiple common of `_dl_malloc_function'
libc/libc_so.a(libdl.oS): warning: previous common is here
/home/build/src/docker/buildroot/host/lib/gcc/x86_64-buildroot-linux-uclibc/7.3.0/../../../../x86_64-buildroot-linux-uclibc/bin/ld:

Can you try outside of docker ?
Also, we don't recommend to run the build as root.

Best regards,
Romain

Quoted 32 lines

libc/libc_so.a(libc-cancellation.oS): relocation R_X86_64_PC32 against
symbol `__pthread_unwind' can not be used when making a shared object;
recompile with -fPIC /home/build/src/docker/buildroot/host/lib/gcc/x86_64-buildroot-linux-uclibc/7.3.0/../../../../x86_64-buildroot-linux-uclibc/bin/ld:
final link failed: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libc.so] Error 1
make[1]: ***
[/home/build/src/docker/buildroot/build/uclibc-1.0.30/.stamp_built] Error 2
make: *** [_all] Error 2

So my hypothesis is that something about my build system environment is causing a misconfiguration of the toolchain with respect to gcc's defaults. I am thinking maybe the pic/PIC default or the mcmodel default is somehow different from what glibc or uClibc-ng Makefiles expect it to be, and they are not setting those options to be explicitly the way they should be in their respective Makefiles.

So I need to figure out what part of the toolchain build is looking at the system itself to determine defaults in this area, or alternatively find the specific gcc setting and change its default manually in buildroot's config.

--
Sent from: http://buildroot-busybox.2317881.n4.nabble.com/
_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot