Skip to content

Commit 2b2a258

Browse files
nathanchanceVasily Gorbik
authored and
Vasily Gorbik
committed
s390/vdso: Use $(LD) instead of $(CC) to link vDSO
Currently, the VDSO is being linked through $(CC). This does not match how the rest of the kernel links objects, which is through the $(LD) variable. When clang is built in a default configuration, it first attempts to use the target triple's default linker, which is just ld. However, the user can override this through the CLANG_DEFAULT_LINKER cmake define so that clang uses another linker by default, such as LLVM's own linker, ld.lld. This can be useful to get more optimized links across various different projects. However, this is problematic for the s390 vDSO because ld.lld does not have any s390 emulatiom support: https://github.com/llvm/llvm-project/blob/llvmorg-10.0.1-rc1/lld/ELF/Driver.cpp#L132-L150 Thus, if a user is using a toolchain with ld.lld as the default, they will see an error, even if they have specified ld.bfd through the LD make variable: $ make -j"$(nproc)" -s ARCH=s390 CROSS_COMPILE=s390x-linux-gnu- LLVM=1 \ LD=s390x-linux-gnu-ld \ defconfig arch/s390/kernel/vdso64/ ld.lld: error: unknown emulation: elf64_s390 clang-11: error: linker command failed with exit code 1 (use -v to see invocation) Normally, '-fuse-ld=bfd' could be used to get around this; however, this can be fragile, depending on paths and variable naming. The cleaner solution for the kernel is to take advantage of the fact that $(LD) can be invoked directly, which bypasses the heuristics of $(CC) and respects the user's choice. Similar changes have been done for ARM, ARM64, and MIPS. Link: https://lkml.kernel.org/r/[email protected] Link: ClangBuiltLinux/linux#1041 Signed-off-by: Nathan Chancellor <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> [[email protected]: add --build-id flag] Signed-off-by: Heiko Carstens <[email protected]> Signed-off-by: Vasily Gorbik <[email protected]>
1 parent 9944801 commit 2b2a258

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

arch/s390/kernel/vdso64/Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ KBUILD_AFLAGS_64 += -m64 -s
1818

1919
KBUILD_CFLAGS_64 := $(filter-out -m64,$(KBUILD_CFLAGS))
2020
KBUILD_CFLAGS_64 += -m64 -fPIC -shared -fno-common -fno-builtin
21-
KBUILD_CFLAGS_64 += -nostdlib -Wl,-soname=linux-vdso64.so.1 \
22-
-Wl,--hash-style=both
21+
ldflags-y := -fPIC -shared -nostdlib -soname=linux-vdso64.so.1 \
22+
--hash-style=both --build-id -T
2323

2424
$(targets:%=$(obj)/%.dbg): KBUILD_CFLAGS = $(KBUILD_CFLAGS_64)
2525
$(targets:%=$(obj)/%.dbg): KBUILD_AFLAGS = $(KBUILD_AFLAGS_64)
@@ -37,8 +37,8 @@ KASAN_SANITIZE := n
3737
$(obj)/vdso64_wrapper.o : $(obj)/vdso64.so
3838

3939
# link rule for the .so file, .lds has to be first
40-
$(obj)/vdso64.so.dbg: $(src)/vdso64.lds $(obj-vdso64) FORCE
41-
$(call if_changed,vdso64ld)
40+
$(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) FORCE
41+
$(call if_changed,ld)
4242

4343
# strip rule for the .so file
4444
$(obj)/%.so: OBJCOPYFLAGS := -S
@@ -50,8 +50,6 @@ $(obj-vdso64): %.o: %.S FORCE
5050
$(call if_changed_dep,vdso64as)
5151

5252
# actual build commands
53-
quiet_cmd_vdso64ld = VDSO64L $@
54-
cmd_vdso64ld = $(CC) $(c_flags) -Wl,-T $(filter %.lds %.o,$^) -o $@
5553
quiet_cmd_vdso64as = VDSO64A $@
5654
cmd_vdso64as = $(CC) $(a_flags) -c -o $@ $<
5755

0 commit comments

Comments
 (0)