Bug 187841

Summary: x32 VDSO fails to build (relocation overflow) when Gold is the system default linker
Product: Platform Specific/Hardware Reporter: Matt Whitlock (kernel)
Component: x86-64Assignee: platform_x86_64 (platform_x86_64)
Status: NEW ---    
Severity: normal CC: devurandom, evanjsx, ivan, markus, rion4ik, sergei.a.trusov, sophietheopossum, xaviermiller
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 4.8.8-gentoo Subsystem:
Regression: No Bisected commit-id:

Description Matt Whitlock 2016-11-16 09:40:26 UTC
While executing the recipe for arch/x86/entry/vdso/vdsox32.so:

  gcc -nostdlib -o arch/x86/entry/vdso/vdsox32.so.dbg -fPIC -shared  -Wl,--hash-style=both  -Wl,--build-id -Wl,-Bsymbolic  -Wl,-m,elf32_x86_64 -Wl,-soname=linux-vdso.so.1 -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 -Wl,-T,arch/x86/entry/vdso/vdsox32.lds arch/x86/entry/vdso/vdso-note-x32.o arch/x86/entry/vdso/vclock_gettime-x32.o arch/x86/entry/vdso/vgetcpu-x32.o && sh ./arch/x86/entry/vdso/checkundef.sh 'nm' 'arch/x86/entry/vdso/vdsox32.so.dbg'

arch/x86/entry/vdso/vclock_gettime-x32.o:vclock_gettime.c:function __vdso_clock_gettime: error: relocation overflow: reference to 'vvar_vsyscall_gtod_data'
arch/x86/entry/vdso/vclock_gettime-x32.o:vclock_gettime.c:function __vdso_gettimeofday: error: relocation overflow: reference to 'vvar_vsyscall_gtod_data'
arch/x86/entry/vdso/vclock_gettime-x32.o:vclock_gettime.c:function __vdso_time: error: relocation overflow: reference to 'vvar_vsyscall_gtod_data'
collect2: error: ld returned 1 exit status

This error causes the subsequent call to objcopy to fail, thus aborting the build.

  objcopy -S  arch/x86/entry/vdso/vdsox32.so.dbg arch/x86/entry/vdso/vdsox32.so
objcopy: 'arch/x86/entry/vdso/vdsox32.so.dbg': No such file
make[3]: *** [arch/x86/entry/vdso/Makefile:124: arch/x86/entry/vdso/vdsox32.so] Error 1


$ ld --version | head -n1
GNU gold (Gentoo 2.27 p1.0 2.27) 1.12


A workaround is to force usage of the BFD linker when linking the x32 VDSO:

--- arch/x86/entry/vdso/Makefile~	2016-10-02 23:24:33.000000000 +0000
+++ arch/x86/entry/vdso/Makefile	2016-11-16 09:35:13.406216597 +0000
@@ -97,6 +97,7 @@
 
 CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
 VDSO_LDFLAGS_vdsox32.lds = -Wl,-m,elf32_x86_64 \
+			   -fuse-ld=bfd \
 			   -Wl,-soname=linux-vdso.so.1 \
 			   -Wl,-z,max-page-size=4096 \
 			   -Wl,-z,common-page-size=4096

Then vdsox32.so.dbg links without error.

This problem just started happening upon upgrading from binutils 2.26.1 to 2.27.
Comment 1 Markus Trippelsdorf 2017-03-07 16:33:28 UTC
See: https://sourceware.org/bugzilla/show_bug.cgi?id=20833
Comment 2 Rion 2018-07-22 16:34:36 UTC
same problem. same solution
gentoo-sources-4.14.56
Comment 3 Matt Whitlock 2018-10-25 00:43:34 UTC
The workaround in Comment #0 is no longer sufficient as of Linux 4.19. Now I additionally must specify "LD=ld.bfd" on the 'make' command line.
Comment 4 seirra blake 2018-12-27 23:41:04 UTC
with 4.20 i couldn't even do that, i had to temporarily change default linker
Comment 5 Sergei Trusov 2019-06-08 06:29:44 UTC
With 5.1 I am using the following hack:

--- linux/Makefile.orig
+++ linux/Makefile
@@ -393,7 +393,7 @@
 
 # Make variables (CC, etc...)
 AS             = $(CROSS_COMPILE)as
-LD             = $(CROSS_COMPILE)ld
+LD             = $(CROSS_COMPILE)ld.bfd
 CC             = $(CROSS_COMPILE)gcc
 CPP            = $(CC) -E
 AR             = $(CROSS_COMPILE)ar

Please note this is for .config with

# CONFIG_X86_X32 is not set

So may be #0 is additionally needed.