Issue
I'm trying to build an application using the Yocto SDK. The compilation worked well, but when it comes to linking, following linker errors occurs:
...
/opt/mydistro/1.0.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.3.0/real-ld: /opt/mydistro/1.0.0/sysroots/cortexa9t2hf-neon-poky-linux-gnueabi/usr/lib/libc.a(getcontext.o): in function `getcontext':
/usr/src/debug/glibc/2.29-r0/git/stdlib/../sysdeps/unix/sysv/linux/arm/getcontext.S:101: undefined reference to `_rtld_global_ro'
/opt/mydistro/1.0.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.3.0/real-ld: /opt/mydistro/1.0.0/sysroots/cortexa9t2hf-neon-poky-linux-gnueabi/usr/lib/libc.a(setcontext.o): in function `__startcontext':
/usr/src/debug/glibc/2.29-r0/git/stdlib/../sysdeps/unix/sysv/linux/arm/setcontext.S:100: undefined reference to `_rtld_global_ro'
collect2: error: ld returned 1 exit status
makefile:116: recipe for target 'ortable' failed
make: *** [ortable] Error 1
I have really no clue, why the object '_rtld_global_ro'
cannot be found. Could someone tell me what is going wrong and what I can do to link the application, please? Maybe, there is a workaround for this?
Other applications could be build with same setup without this issue (sourcing the SDK using following command):
source /opt/mydistro/1.0.0/environment-setup-cortexa9t2hf-neon-poky-linux-gnueabi
Here is the image bb file (which I have used for building the SDK using the command bitbake my-image -c populate_sdk
).
require recipes-extended/images/core-image-full-cmdline.bb
IMAGE_INSTALL_append = " \
emmy-w1-driver-sdiosdio \
emmy-w1-systemd \
eth-systemd \
can-systemd \
can-utils \
lighttpd \
dnsmasq \
parted \
swupdate \
swupdate-www \
u-boot-fw-utils \
linux-firmware-imx-sdma-imx6q \
"
TOOLCHAIN_HOST_TASK_append = " nativesdk-perl-modules"
SDKIMAGE_FEATURES_append = " staticdev-pkgs"
Solution
This is an issue in the upstream glibc sources: The ARM assembler version of setcontext
assumes that all PIC code is dynamic linked, which means that static linking fails if glibc was built in static PIE mode (because that actives PIC without providing the dynamic linker code).
You either need to build glibc without static PIE support (I did not even know this was a supported configuration for 32-bit ARM), or replace the PIC
macro with SHARED
in sysdeps/unix/sysv/linux/arm/setcontext.S
.
Answered By - Florian Weimer