linux/arch/mips
Nathan Chancellor 2ff906994b MIPS: 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 then the system's default linker,
unless told otherwise through -fuse-ld=... We do not use -fuse-ld=
because it can be brittle and we have support for invoking $(LD)
directly. See commit fe00e50b2d ("ARM: 8858/1: vdso: use $(LD)
instead of $(CC) to link VDSO") and commit 691efbedc6 ("arm64: vdso:
use $(LD) instead of $(CC) to link VDSO") for examples of doing this in
the VDSO.

Do the same thing here. Replace the custom linking logic with $(cmd_ld)
and ldflags-y so that $(LD) is respected. We need to explicitly add two
flags to the linker that were implicitly passed by the compiler:
-G 0 (which comes from ccflags-vdso) and --eh-frame-hdr.

Before this patch (generated by adding '-v' to VDSO_LDFLAGS):

<gcc_prefix>/libexec/gcc/mips64-linux/9.3.0/collect2 \
-plugin <gcc_prefix>/libexec/gcc/mips64-linux/9.3.0/liblto_plugin.so \
-plugin-opt=<gcc_prefix>/libexec/gcc/mips64-linux/9.3.0/lto-wrapper \
-plugin-opt=-fresolution=/tmp/ccGEi5Ka.res \
--eh-frame-hdr \
-G 0 \
-EB \
-mips64r2 \
-shared \
-melf64btsmip \
-o arch/mips/vdso/vdso.so.dbg.raw \
-L<gcc_prefix>/lib/gcc/mips64-linux/9.3.0/64 \
-L<gcc_prefix>/lib/gcc/mips64-linux/9.3.0 \
-L<gcc_prefix>/lib/gcc/mips64-linux/9.3.0/../../../../mips64-linux/lib \
-Bsymbolic \
--no-undefined \
-soname=linux-vdso.so.1 \
-EB \
--hash-style=sysv \
--build-id \
-T arch/mips/vdso/vdso.lds \
arch/mips/vdso/elf.o \
arch/mips/vdso/vgettimeofday.o \
arch/mips/vdso/sigreturn.o

After this patch:

<gcc_prefix>/bin/mips64-linux-ld \
-m elf64btsmip \
-Bsymbolic \
--no-undefined \
-soname=linux-vdso.so.1 \
-EB \
-nostdlib \
-shared \
-G 0 \
--eh-frame-hdr \
--hash-style=sysv \
--build-id \
-T  arch/mips/vdso/vdso.lds \
arch/mips/vdso/elf.o \
arch/mips/vdso/vgettimeofday.o
arch/mips/vdso/sigreturn.o \
-o arch/mips/vdso/vdso.so.dbg.raw

Note that we leave behind -mips64r2. Turns out that ld ignores it (see
get_emulation in ld/ldmain.c). This is true of current trunk and 2.23,
which is the minimum supported version for the kernel:

https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=ld/ldmain.c;hb=aa4209e7b679afd74a3860ce25659e71cc4847d5#l593
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=ld/ldmain.c;hb=a55e30b51bc6227d8d41f707654d0a5620978dcf#l641

Before this patch, LD=ld.lld did nothing:

$ llvm-readelf -p.comment arch/mips/vdso/vdso.so.dbg | sed 's/(.*//'
String dump of section '.comment':
[     0] ClangBuiltLinux clang version 11.0.0

After this patch, it does:

$ llvm-readelf -p.comment arch/mips/vdso/vdso.so.dbg | sed 's/(.*//'
String dump of section '.comment':
[     0] Linker: LLD 11.0.0
[    62] ClangBuiltLinux clang version 11.0.0

Link: https://github.com/ClangBuiltLinux/linux/issues/785
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
2020-05-12 10:02:00 +02:00
..
alchemy MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
ar7 MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
ath25
ath79 MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
bcm47xx
bcm63xx MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
bmips
boot MIPS: Truncate link address into 32bit for 32bit kernel 2020-05-07 10:31:01 +02:00
cavium-octeon MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
cobalt
configs MIPS: Remove NEC MARKEINS/EMMA 2020-05-09 18:05:57 +02:00
crypto
dec MIPS: asm: Rename some macros to avoid build errors 2020-05-07 13:20:05 +02:00
fw MIPS: CFE: Remove dead code in cfe_getfwinfo() 2020-05-07 10:29:42 +02:00
generic
include MIPS: Remove NEC MARKEINS/EMMA 2020-05-09 18:05:57 +02:00
jazz
jz4740 MIPS: ingenic: Replace <linux/clk-provider.h> by <linux/of_clk.h> 2020-05-07 11:59:55 +02:00
kernel MIPS: Replace zero-length array with flexible-array 2020-05-08 12:01:02 +02:00
kvm MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
lantiq
lib
loongson2ef mips: loongsoon2ef: remove private clk api 2020-04-16 17:34:23 +02:00
loongson32
loongson64 MIPS: Loongson: Add DMA support for LS7A 2020-05-08 12:00:07 +02:00
math-emu MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
mm MIPS: unexport __flush_icache_user_range 2020-05-11 17:59:47 +02:00
mti-malta
net
netlogic MIPS: Netlogic: remove unneeded semicolon in fmn_message_handler() 2020-04-19 16:05:19 +02:00
oprofile MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
paravirt
pci MIPS: Remove NEC MARKEINS/EMMA 2020-05-09 18:05:57 +02:00
pic32
pistachio
pnx833x
power
ralink MIPS: ralink: mt7621: Fix soc_device introduction 2020-03-28 17:26:36 +01:00
rb532
sgi-ip22
sgi-ip27
sgi-ip30
sgi-ip32
sibyte
sni
tools MIPS: tools: Move "returns" after "loongson3-llsc-check" 2020-05-04 10:18:41 +02:00
txx9 MIPS: TXx9: Fix Kconfig warnings 2020-04-14 12:52:28 +02:00
vdso MIPS: VDSO: Use $(LD) instead of $(CC) to link VDSO 2020-05-12 10:02:00 +02:00
vr41xx
Kbuild
Kbuild.platforms MIPS: Remove NEC MARKEINS/EMMA 2020-05-09 18:05:57 +02:00
Kconfig MIPS: VDSO: Move disabling the VDSO logic to Kconfig 2020-05-12 10:01:45 +02:00
Kconfig.debug
Makefile MIPS: Unconditionally specify '-EB' or '-EL' 2020-05-12 10:01:53 +02:00
Makefile.postlink