Skip to contentSkip to conversation

x86: vdso: Fix leaky vdso link with CC=clang

PATCH In review Alistair Strachan 3 participants 6 messages Jul 12, 2018 – Jul 13, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: vdso: Fix leaky vdso link with CC=clang

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.

Most of the time this goes unnoticed because the host linker is new enough to work anyway, but this cannot be reliably assumed.

Extract the needed --target and --gcc-toolchain flags added in the top level Makefile from KBUILD_CFLAGS. These flags direct clang to the appropriate toolchain to link the vdsos.

Cc Andy Lutomirski <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 arch/x86/entry/vdso/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/entry/vdso/Makefile +2 -1
index 261802b1cc50..062ee94d2d26 100644
@@ -163,7 +163,8 @@ quiet_cmd_vdso = VDSO    $@
 		 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
 
 VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=both) \
-	$(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
+	$(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS) \
+	$(filter --target=% --gcc-toolchain=%,$(KBUILD_CFLAGS))
 GCOV_PROFILE := n
 
 #
#1 lore raw
Quoted 10 lines · Alistair Strachan

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.

Is this another clang bug that you want a workaround for in the kernel?

-hpa

#2 lore raw
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · Alistair Strachan

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)

Quoted 6 lines
Quoted 4 lines

This happens because the host environment leaked into the cross compiler environment due to the way clang searches for suitable GCC toolchains.

Is this another clang bug that you want a workaround for in the kernel?

Clang is a retargetable compiler (specified with --target=<something>) and so it has a mechanism for searching for suitable binutils (from another "GCC toolchain") to perform assembly and linkage. This mechanism relies on both --target and --gcc-toolchain when cross-compiling, otherwise it will fall back to searching /usr.

The --target and --gcc-toolchain flags are already specified correctly in the top level Makefile, but the vdso Makefile rolls its own linker flags and doesn't use KBUILD_CFLAGS. Therefore, these flags get incorrectly dropped from the vdso $CC link command line, and an inconsistency is created between the "GCC toolchain" used to generate the objects for the vdso, and the linker used to link them.

#3 lore raw
Quoted 21 lines · Alistair Strachan
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · Alistair Strachan

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)

Quoted 6 lines
Quoted 4 lines

This happens because the host environment leaked into the cross compiler environment due to the way clang searches for suitable GCC toolchains.

Is this another clang bug that you want a workaround for in the kernel?

Clang is a retargetable compiler (specified with --target=<something>) and so it has a mechanism for searching for suitable binutils (from another "GCC toolchain") to perform assembly and linkage. This mechanism relies on both --target and --gcc-toolchain when cross-compiling, otherwise it will fall back to searching /usr.

Quoted 7 lines

The --target and --gcc-toolchain flags are already specified correctly in the top level Makefile, but the vdso Makefile rolls its own linker flags and doesn't use KBUILD_CFLAGS. Therefore, these flags get incorrectly dropped from the vdso $CC link command line, and an inconsistency is created between the "GCC toolchain" used to generate the objects for the vdso, and the linker used to link them.

It sounds like there needs to be a more fundamental symbol than KBUILD_CFLAGS to contain these kinds of things.

-hpa

#4 lore raw
Quoted 33 lines · H. Peter Anvin
Quoted 23 lines · Alistair Strachan
Quoted 8 lines · H. Peter Anvin
Quoted 7 lines · Alistair Strachan

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)

Quoted 6 lines
Quoted 4 lines

This happens because the host environment leaked into the cross compiler environment due to the way clang searches for suitable GCC toolchains.

Is this another clang bug that you want a workaround for in the kernel?

Clang is a retargetable compiler (specified with --target=<something>) and so it has a mechanism for searching for suitable binutils (from another "GCC toolchain") to perform assembly and linkage. This mechanism relies on both --target and --gcc-toolchain when cross-compiling, otherwise it will fall back to searching /usr.

Quoted 7 lines

The --target and --gcc-toolchain flags are already specified correctly in the top level Makefile, but the vdso Makefile rolls its own linker flags and doesn't use KBUILD_CFLAGS. Therefore, these flags get incorrectly dropped from the vdso $CC link command line, and an inconsistency is created between the "GCC toolchain" used to generate the objects for the vdso, and the linker used to link them.

Quoted 2 lines

It sounds like there needs to be a more fundamental symbol than KBUILD_CFLAGS to contain these kinds of things.

How about $(CC)?

Quoted 2 lines

-hpa

#5 lore raw
Quoted 33 lines · Andy Lutomirski
Quoted 33 lines · H. Peter Anvin
Quoted 30 lines · Alistair Strachan
Quoted 8 lines · H. Peter Anvin
Quoted 7 lines · Alistair Strachan

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)

Quoted 6 lines
Quoted 4 lines

This happens because the host environment leaked into the cross compiler environment due to the way clang searches for suitable GCC toolchains.

Is this another clang bug that you want a workaround for in the kernel?

Clang is a retargetable compiler (specified with --target=<something>) and so it has a mechanism for searching for suitable binutils (from another "GCC toolchain") to perform assembly and linkage. This mechanism relies on both --target and --gcc-toolchain when cross-compiling, otherwise it will fall back to searching /usr.

The --target and --gcc-toolchain flags are already specified correctly in the top level Makefile, but the vdso Makefile rolls its own linker flags and doesn't use KBUILD_CFLAGS. Therefore, these flags get incorrectly dropped from the vdso $CC link command line, and an inconsistency is created between the "GCC toolchain" used to generate the objects for the vdso, and the linker used to link them.

Quoted 4 lines
Quoted 2 lines

It sounds like there needs to be a more fundamental symbol than KBUILD_CFLAGS to contain these kinds of things.

How about $(CC)?

I'm guessing, but I think this wasn't done originally because CC is something the user might reasonably specify on the command line (the other bit comes from CROSS_COMPILE), so doing this via CC would require us to override the CC passed in on the command line. Not sure how to do that, since the vdso makefile is executed with a submake, so the usual "override CC := $(CC) something else" followed by "export CC" doesn't work.