• Nathan Chancellor's avatar
    MIPS: VDSO: Use $(LD) instead of $(CC) to link VDSO · 2ff90699
    Nathan Chancellor authored
    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 fe00e50b ("ARM: 8858/1: vdso: use $(LD)
    instead of $(CC) to link VDSO") and commit 691efbed ("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/785Signed-off-by: default avatarNathan Chancellor <natechancellor@gmail.com>
    Signed-off-by: default avatarThomas Bogendoerfer <tsbogend@alpha.franken.de>
    2ff90699
Makefile 6.06 KB