Skip to content

Commit 379d98d

Browse files
Alistair StrachanKAGA-KOKO
authored andcommitted
x86: vdso: Use $LD instead of $CC to link
The vdso{32,64}.so can fail to link with CC=clang when clang tries to find a suitable GCC toolchain to link these libraries with. /usr/bin/ld: arch/x86/entry/vdso/vclock_gettime.o: access beyond end of merged section (782) This happens because the host environment leaked into the cross compiler environment due to the way clang searches for suitable GCC toolchains. Clang is a retargetable compiler, and each invocation of it must provide --target=<something> --gcc-toolchain=<something> to allow it to find the correct binutils for cross compilation. These flags had been added to KBUILD_CFLAGS, but the vdso code uses CC and not KBUILD_CFLAGS (for various reasons) which breaks clang's ability to find the correct linker when cross compiling. Most of the time this goes unnoticed because the host linker is new enough to work anyway, or is incompatible and skipped, but this cannot be reliably assumed. This change alters the vdso makefile to just use LD directly, which bypasses clang and thus the searching problem. The makefile will just use ${CROSS_COMPILE}ld instead, which is always what we want. This matches the method used to link vmlinux. This drops references to DISABLE_LTO; this option doesn't seem to be set anywhere, and not knowing what its possible values are, it's not clear how to convert it from CC to LD flag. Signed-off-by: Alistair Strachan <astrachan@google.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Andy Lutomirski <luto@kernel.org> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: kernel-team@android.com Cc: joel@joelfernandes.org Cc: Andi Kleen <andi.kleen@intel.com> Link: https://lkml.kernel.org/r/20180803173931.117515-1-astrachan@google.com
1 parent 1ffaddd commit 379d98d

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

arch/x86/entry/vdso/Makefile

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ targets += $(vdso_img_sodbg) $(vdso_img-y:%=vdso%.so)
4646

4747
CPPFLAGS_vdso.lds += -P -C
4848

49-
VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
50-
-Wl,--no-undefined \
51-
-Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 \
52-
$(DISABLE_LTO)
49+
VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -soname linux-vdso.so.1 --no-undefined \
50+
-z max-page-size=4096 -z common-page-size=4096
5351

5452
$(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE
5553
$(call if_changed,vdso)
@@ -95,10 +93,8 @@ CFLAGS_REMOVE_vvar.o = -pg
9593
#
9694

9795
CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
98-
VDSO_LDFLAGS_vdsox32.lds = -Wl,-m,elf32_x86_64 \
99-
-Wl,-soname=linux-vdso.so.1 \
100-
-Wl,-z,max-page-size=4096 \
101-
-Wl,-z,common-page-size=4096
96+
VDSO_LDFLAGS_vdsox32.lds = -m elf32_x86_64 -soname linux-vdso.so.1 \
97+
-z max-page-size=4096 -z common-page-size=4096
10298

10399
# x32-rebranded versions
104100
vobjx32s-y := $(vobjs-y:.o=-x32.o)
@@ -123,7 +119,7 @@ $(obj)/vdsox32.so.dbg: $(obj)/vdsox32.lds $(vobjx32s) FORCE
123119
$(call if_changed,vdso)
124120

125121
CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
126-
VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-m,elf_i386 -Wl,-soname=linux-gate.so.1
122+
VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -soname linux-gate.so.1
127123

128124
targets += vdso32/vdso32.lds
129125
targets += vdso32/note.o vdso32/system_call.o vdso32/sigreturn.o
@@ -157,13 +153,13 @@ $(obj)/vdso32.so.dbg: FORCE \
157153
# The DSO images are built using a special linker script.
158154
#
159155
quiet_cmd_vdso = VDSO $@
160-
cmd_vdso = $(CC) -nostdlib -o $@ \
156+
cmd_vdso = $(LD) -nostdlib -o $@ \
161157
$(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
162-
-Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
158+
-T $(filter %.lds,$^) $(filter %.o,$^) && \
163159
sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
164160

165-
VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=both) \
166-
$(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
161+
VDSO_LDFLAGS = -shared $(call ld-option, --hash-style=both) \
162+
$(call ld-option, --build-id) -Bsymbolic
167163
GCOV_PROFILE := n
168164

169165
#

0 commit comments

Comments
 (0)