Bug 1716785

Summary: relocation R_X86_64_PC32 against undefined hidden symbol `__dso_handle'
Product: Red Hat Enterprise Linux 8 Reporter: Prabhanjan Gururaj <prabhanjan.gururaj>
Component: gccAssignee: Marek Polacek <mpolacek>
gcc sub component: system-version QA Contact: qe-baseos-tools-bugs
Status: CLOSED NOTABUG Docs Contact:
Severity: high    
Priority: unspecified CC: ahajkova, fweimer, jakub, ohudlick
Version: 8.2   
Target Milestone: rc   
Target Release: 8.0   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-06-04 21:20:15 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Prabhanjan Gururaj 2019-06-04 06:03:03 UTC
Description of problem:
ld fails as below:
ld: /usr/lib64/libc_nonshared.a(pthread_atfork.oS): relocation R_X86_64_PC32 against undefined hidden symbol `__dso_handle' can not be used when making a shared object
ld: final link failed: Bad valu

Version-Release number of selected component (if applicable):
Red Hat Enterprise Linux 8.0 Beta (Ootpa)
kernel-4.18.0-74.el8.x86_64
gcc-c++-8.2.1-3.5.el8.x86_64
gcc-8.2.1-3.5.el8.x86_64



Details:

cc -w  -DLINUX -D_GNU_SOURCE -Werror -DNO_DLPI -D_REENTRANT  -DFLIGHT_RECORDER -DLIC_ENABLE -DRH8 -DLIBNL3 -DUSE_SYSTEMD -fpic  -I/usr/include/libnl3 -I/usr/include -Ih/linux -Ih -Iobjs/product -Ideadman_module -DSACTO -DQS -DENABLE_ENHANCED_SECURITY  -DOM_USE_TLS -o objs/product/libptmalloc_ws.o -c objs/product/libptmalloc_ws.c
Putting child 0x55b4f28faae0 (objs/product/libptmalloc_ws.o) PID 14489 on the chain.
Live child 0x55b4f28faae0 (objs/product/libptmalloc_ws.o) PID 14489
Reaping winning child 0x55b4f28faae0 PID 14489
Removing child 0x55b4f28faae0 PID 14489 from chain.
               Successfully remade target file 'objs/product/libptmalloc_ws.o'.
               Finished prerequisites of target file 'objs/product/libptmalloc.so'.
              Must remake target 'objs/product/libptmalloc.so'.


ld    -shared -o objs/product/libptmalloc.so objs/product/libptmalloc_ws.o objs/product/ptmalloc.o -lm -lc

Putting child 0x55b4f28faae0 (objs/product/libptmalloc.so) PID 14493 on the chain.
Live child 0x55b4f28faae0 (objs/product/libptmalloc.so) PID 14493
/usr/lib64/libc_nonshared.a(pthread_atfork.oS): In function `__pthread_atfork':
(.text+0x7): undefined reference to `__dso_handle'

ld: /usr/lib64/libc_nonshared.a(pthread_atfork.oS): relocation R_X86_64_PC32 against undefined hidden symbol `__dso_handle' can not be used when making a shared object

ld: final link failed: Bad value
Reaping losing child 0x55b4f28faae0 PID 14493
make: *** [build/platform_targets_linux.mk:132: objs/product/libptmalloc.so] Error 1



Expected results:
The same piece of code is getting built successfully on gcc 4.8. I am seeing this issue only after moving to gcc8.2 with rhel8.

Comment 1 Jakub Jelinek 2019-06-04 06:31:11 UTC
ld    -shared -o objs/product/libptmalloc.so objs/product/libptmalloc_ws.o objs/product/ptmalloc.o -lm -lc

This is the bug, you should never invoke ld directly unless you know exactly what you need to specify to get the linking right.
Instead, you should be using the gcc driver to do the linking, i.e.
gcc    -shared -o objs/product/libptmalloc.so objs/product/libptmalloc_ws.o objs/product/ptmalloc.o -lm

Comment 2 Marek Polacek 2019-06-04 21:20:15 UTC
Not a GCC bug.