linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nathan Chancellor <natechancellor@gmail.com>
To: Fangrui Song <maskray@google.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	Masahiro Yamada <masahiroy@kernel.org>,
	linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org,
	clang-built-linux@googlegroups.com, linux-kbuild@vger.kernel.org,
	Nick Desaulniers <ndesaulniers@google.com>,
	Sami Tolvanen <samitolvanen@google.com>,
	Dmitry Golovin <dima@golovin.in>,
	Sedat Dilek <sedat.dilek@gmail.com>
Subject: Re: [PATCH v4 4/5] MIPS: VDSO: Use $(LD) instead of $(CC) to link VDSO
Date: Tue, 28 Apr 2020 17:44:25 -0700	[thread overview]
Message-ID: <20200429004425.GA566019@ubuntu-s3-xlarge-x86> (raw)
In-Reply-To: <20200428225401.7yrld7u2xr67t4xf@google.com>

On Tue, Apr 28, 2020 at 03:54:01PM -0700, Fangrui Song wrote:
> 
> On 2020-04-28, Nathan Chancellor wrote:
> > 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 fe00e50b2db8c ("ARM: 8858/1: vdso: use $(LD)
> > instead of $(CC) to link VDSO") and commit 691efbedc60d2 ("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>
> > ---
> > 
> > v3 -> v4:
> > 
> > * Improve commit message to show that ld command is effectively the
> >  same as the one generated by GCC.
> > 
> > * Add '-G 0' and '--eh-frame-hdr' because they were added by GCC.
> 
> My understanding is that we start to use more -fasynchronous-unwind-tables to eliminate .eh_frame in object files.
> Without .eh_frame, LD --eh-frame-hdr is really not useful.

Ah, I was not paying attention; I figured that this was necessary
because the x86 VDSO broke without it:

cd01544a268ad ("x86/vdso: Pass --eh-frame-hdr to the linker")

However, they explicitly add -fasynchronous-unwind-tables so it seems
like this indeed can be removed. Kind of odd that GCC passes it along
even with -fno-asynchronous-unwind-tables. I will do that in v5 once I
get some feedback on whether or not anything else breaks.

Cheers,
Nathan

> Sigh...  -G 0. This is an option ignored by LLD. GCC devs probably should
> have used the long option --gpsize rather than take the short option -G.
> Even better, -z gpsize= or similar if this option is specific to ELF.
> > v2 -> v3:
> > 
> > * New patch.
> > 
> > arch/mips/vdso/Makefile | 13 ++++---------
> > 1 file changed, 4 insertions(+), 9 deletions(-)
> > 
> > diff --git a/arch/mips/vdso/Makefile b/arch/mips/vdso/Makefile
> > index 92b53d1df42c3..2e64c7600eead 100644
> > --- a/arch/mips/vdso/Makefile
> > +++ b/arch/mips/vdso/Makefile
> > @@ -60,10 +60,9 @@ ifdef CONFIG_MIPS_DISABLE_VDSO
> > endif
> > 
> > # VDSO linker flags.
> > -VDSO_LDFLAGS := \
> > -	-Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1 \
> > -	$(addprefix -Wl$(comma),$(filter -E%,$(KBUILD_CFLAGS))) \
> > -	-nostdlib -shared -Wl,--hash-style=sysv -Wl,--build-id
> > +ldflags-y := -Bsymbolic --no-undefined -soname=linux-vdso.so.1 \
> > +	$(filter -E%,$(KBUILD_CFLAGS)) -nostdlib -shared \
> > +	-G 0 --eh-frame-hdr --hash-style=sysv --build-id -T
> > 
> > CFLAGS_REMOVE_vdso.o = -pg
> > 
> > @@ -82,11 +81,7 @@ quiet_cmd_vdso_mips_check = VDSOCHK $@
> > #
> > 
> > quiet_cmd_vdsold_and_vdso_check = LD      $@
> > -      cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check); $(cmd_vdso_mips_check)
> > -
> > -quiet_cmd_vdsold = VDSO    $@
> > -      cmd_vdsold = $(CC) $(c_flags) $(VDSO_LDFLAGS) \
> > -                   -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@
> > +      cmd_vdsold_and_vdso_check = $(cmd_ld); $(cmd_vdso_check); $(cmd_vdso_mips_check)
> > 
> > quiet_cmd_vdsoas_o_S = AS      $@
> >       cmd_vdsoas_o_S = $(CC) $(a_flags) -c -o $@ $<
> > -- 
> > 2.26.2
> > 

  reply	other threads:[~2020-04-29  0:44 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-19 18:04 [PATCH 1/2] kbuild: add CONFIG_LD_IS_LLD Nathan Chancellor
2020-04-19 18:04 ` [PATCH 2/2] MIPS: VDSO: Do not disable VDSO when linking with ld.lld Nathan Chancellor
2020-04-19 18:17   ` Nathan Chancellor
2020-04-19 19:32     ` Masahiro Yamada
2020-04-19 20:05       ` Nathan Chancellor
2020-04-19 20:21 ` [PATCH v2 1/3] kbuild: add CONFIG_LD_IS_LLD Nathan Chancellor
2020-04-19 20:21   ` [PATCH v2 2/3] MIPS: VDSO: Move disabling the VDSO logic to Kconfig Nathan Chancellor
2020-04-20  9:53     ` Sedat Dilek
2020-04-21  2:42       ` Nathan Chancellor
2020-04-23 14:41         ` Masahiro Yamada
2020-04-19 20:21   ` [PATCH v2 3/3] MIPS: VDSO: Allow ld.lld to link the VDSO Nathan Chancellor
2020-04-23 14:38   ` [PATCH v2 1/3] kbuild: add CONFIG_LD_IS_LLD Masahiro Yamada
2020-04-23 17:18   ` [PATCH v3 1/4] " Nathan Chancellor
2020-04-23 17:18     ` [PATCH v3 2/4] MIPS: VDSO: Move disabling the VDSO logic to Kconfig Nathan Chancellor
2020-04-23 17:18     ` [PATCH v3 3/4] MIPS: VDSO: Use $(LD) instead of $(CC) to link VDSO Nathan Chancellor
2020-04-26 16:27       ` Thomas Bogendoerfer
2020-04-27  2:08         ` Nathan Chancellor
2020-04-27 16:22           ` Maciej W. Rozycki
2020-04-27 23:24             ` Nathan Chancellor
2020-04-29 17:46               ` Maciej W. Rozycki
2020-04-30  3:14                 ` Nathan Chancellor
2020-04-28  2:17         ` Nathan Chancellor
2020-04-23 17:18     ` [PATCH v3 4/4] MIPS: VDSO: Allow ld.lld to link the VDSO Nathan Chancellor
2020-04-28 22:14     ` [PATCH v5 0/5] Allow ld.lld to link the MIPS VDSO Nathan Chancellor
2020-04-28 22:14       ` [PATCH v4 1/5] kbuild: add CONFIG_LD_IS_LLD Nathan Chancellor
2020-04-29  7:13         ` Sedat Dilek
2020-04-30  3:05           ` Nathan Chancellor
2020-04-28 22:14       ` [PATCH v4 2/5] MIPS: VDSO: Move disabling the VDSO logic to Kconfig Nathan Chancellor
2020-04-28 22:14       ` [PATCH v4 3/5] MIPS: Unconditionally specify '-EB' or '-EL' Nathan Chancellor
2020-04-28 22:14       ` [PATCH v4 4/5] MIPS: VDSO: Use $(LD) instead of $(CC) to link VDSO Nathan Chancellor
2020-04-28 22:54         ` Fangrui Song
2020-04-29  0:44           ` Nathan Chancellor [this message]
2020-05-02 13:34           ` Maciej W. Rozycki
2020-05-02 13:50         ` Maciej W. Rozycki
2020-05-02 15:49           ` Nathan Chancellor
2020-04-28 22:14       ` [PATCH v4 5/5] MIPS: VDSO: Allow ld.lld to link the VDSO Nathan Chancellor
2020-04-29  7:04       ` [PATCH v5 0/5] Allow ld.lld to link the MIPS VDSO Sedat Dilek
2020-04-30  3:06         ` Nathan Chancellor
2020-05-12  8:05       ` Thomas Bogendoerfer
2020-05-12  8:28         ` Nathan Chancellor
2020-05-13 11:18           ` Thomas Bogendoerfer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200429004425.GA566019@ubuntu-s3-xlarge-x86 \
    --to=natechancellor@gmail.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=dima@golovin.in \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=maskray@google.com \
    --cc=ndesaulniers@google.com \
    --cc=samitolvanen@google.com \
    --cc=sedat.dilek@gmail.com \
    --cc=tsbogend@alpha.franken.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).