[PATCH 1/2] x86/vdso: remove -nostdlib compiler flag

4 views
Skip to first unread message

Masahiro Yamada

unread,
Nov 7, 2021, 11:27:03 AM11/7/21
to x...@kernel.org, Thomas Gleixner, Ingo Molnar, Borislav Petkov, H . Peter Anvin, clang-bu...@googlegroups.com, Masahiro Yamada, Andy Lutomirski, Dave Hansen, linux-...@vger.kernel.org
The -nostdlib option requests the compiler to not use the standard
system startup files or libraries when linking. It is effective only
when $(CC) is used as a linker driver.

Since

379d98ddf413 ("x86: vdso: Use $LD instead of $CC to link")

$(LD) is directly used, hence -nostdlib is unneeded.

Signed-off-by: Masahiro Yamada <masa...@kernel.org>
---

arch/x86/entry/vdso/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
index a2dddcc189f6..693f8b9031fb 100644
--- a/arch/x86/entry/vdso/Makefile
+++ b/arch/x86/entry/vdso/Makefile
@@ -172,7 +172,7 @@ $(obj)/vdso32.so.dbg: $(obj)/vdso32/vdso32.lds $(vobjs32) FORCE
# The DSO images are built using a special linker script.
#
quiet_cmd_vdso = VDSO $@
- cmd_vdso = $(LD) -nostdlib -o $@ \
+ cmd_vdso = $(LD) -o $@ \
$(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
-T $(filter %.lds,$^) $(filter %.o,$^) && \
sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
--
2.30.2

Masahiro Yamada

unread,
Nov 7, 2021, 11:27:03 AM11/7/21
to x...@kernel.org, Thomas Gleixner, Ingo Molnar, Borislav Petkov, H . Peter Anvin, clang-bu...@googlegroups.com, Masahiro Yamada, Dave Hansen, linux-...@vger.kernel.org
The -nostdlib option requests the compiler to not use the standard
system startup files or libraries when linking. It is effective only
when $(CC) is used as a linker driver.

$(LD) is directly used for linking purgatory.{ro,chk} here, hence
-nostdlib is unneeded.

Signed-off-by: Masahiro Yamada <masa...@kernel.org>
---

arch/x86/purgatory/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
index 95ea17a9d20c..ae53d54d7959 100644
--- a/arch/x86/purgatory/Makefile
+++ b/arch/x86/purgatory/Makefile
@@ -16,7 +16,7 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS

# When linking purgatory.ro with -r unresolved symbols are not checked,
# also link a purgatory.chk binary without -r to check for unresolved symbols.
-PURGATORY_LDFLAGS := -e purgatory_start -nostdlib -z nodefaultlib
+PURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib
LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS)
LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS)
targets += purgatory.ro purgatory.chk
--
2.30.2

Nick Desaulniers

unread,
Nov 8, 2021, 6:52:47 PM11/8/21
to Masahiro Yamada, Fangrui Song, x...@kernel.org, Thomas Gleixner, Ingo Molnar, Borislav Petkov, H . Peter Anvin, clang-bu...@googlegroups.com, Dave Hansen, linux-...@vger.kernel.org, ll...@lists.linux.dev
On Sun, Nov 7, 2021 at 8:27 AM Masahiro Yamada <masa...@kernel.org> wrote:
>
> The -nostdlib option requests the compiler to not use the standard
> system startup files or libraries when linking. It is effective only
> when $(CC) is used as a linker driver.

Is that right? ld.lld recognizes --nostdlib and has --help text for it.

>
> $(LD) is directly used for linking purgatory.{ro,chk} here, hence
> -nostdlib is unneeded.
>
> Signed-off-by: Masahiro Yamada <masa...@kernel.org>
> ---
>
> arch/x86/purgatory/Makefile | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
> index 95ea17a9d20c..ae53d54d7959 100644
> --- a/arch/x86/purgatory/Makefile
> +++ b/arch/x86/purgatory/Makefile
> @@ -16,7 +16,7 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS
>
> # When linking purgatory.ro with -r unresolved symbols are not checked,
> # also link a purgatory.chk binary without -r to check for unresolved symbols.
> -PURGATORY_LDFLAGS := -e purgatory_start -nostdlib -z nodefaultlib
> +PURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib
> LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS)
> LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS)
> targets += purgatory.ro purgatory.chk
> --
> 2.30.2

--
Thanks,
~Nick Desaulniers

Fangrui Song

unread,
Nov 8, 2021, 7:05:35 PM11/8/21
to Nick Desaulniers, Masahiro Yamada, x...@kernel.org, Thomas Gleixner, Ingo Molnar, Borislav Petkov, H . Peter Anvin, clang-bu...@googlegroups.com, Dave Hansen, linux-...@vger.kernel.org, ll...@lists.linux.dev
On 2021-11-08, Nick Desaulniers wrote:
>On Sun, Nov 7, 2021 at 8:27 AM Masahiro Yamada <masa...@kernel.org> wrote:
>>
>> The -nostdlib option requests the compiler to not use the standard
>> system startup files or libraries when linking. It is effective only
>> when $(CC) is used as a linker driver.
>
>Is that right? ld.lld recognizes --nostdlib and has --help text for it.

GCC/Clang driver -nostdlib != ld.bfd/ld.lld -nostdlib.

ld.lld -nostdlib just ignores SEARCH_DIR in a linker script.
I think ld.bfd's -nostdlib is more complex than that which also has
something to do with its internal linker script location.
Anyway, getting of the obscure ld -nostdlib is a good idea.

Nick Desaulniers

unread,
Nov 10, 2021, 2:54:32 PM11/10/21
to Fangrui Song, Masahiro Yamada, x...@kernel.org, Thomas Gleixner, Ingo Molnar, Borislav Petkov, H . Peter Anvin, clang-bu...@googlegroups.com, Dave Hansen, linux-...@vger.kernel.org, ll...@lists.linux.dev
On Mon, Nov 8, 2021 at 4:05 PM 'Fangrui Song' via Clang Built Linux
<clang-bu...@googlegroups.com> wrote:
>
> On 2021-11-08, Nick Desaulniers wrote:
> >On Sun, Nov 7, 2021 at 8:27 AM Masahiro Yamada <masa...@kernel.org> wrote:
> >>
> >> The -nostdlib option requests the compiler to not use the standard
> >> system startup files or libraries when linking. It is effective only
> >> when $(CC) is used as a linker driver.
> >
> >Is that right? ld.lld recognizes --nostdlib and has --help text for it.
>
> GCC/Clang driver -nostdlib != ld.bfd/ld.lld -nostdlib.
>
> ld.lld -nostdlib just ignores SEARCH_DIR in a linker script.
> I think ld.bfd's -nostdlib is more complex than that which also has
> something to do with its internal linker script location.
> Anyway, getting of the obscure ld -nostdlib is a good idea.

Ok, I verified that the size of arch/x86/purgatory/purgatory.ro,
arch/x86/entry/vdso/vdso64.so, and arch/x86/entry/vdso/vdso32.so don't
change with this series. (ldd is not happy with the .so's regardless).

I also suspect that the linker when invoked directly can't assuming
it's linking object files created from C sources (ie. could have been
assembler sources), so there's no reason to assume that the libc, C
runtime, or compiler runtime would need to be linked against.

Reviewed-by: Nick Desaulniers <ndesau...@google.com>

>
> >>
> >> $(LD) is directly used for linking purgatory.{ro,chk} here, hence
> >> -nostdlib is unneeded.
> >>
> >> Signed-off-by: Masahiro Yamada <masa...@kernel.org>
> >> ---
> >>
> >> arch/x86/purgatory/Makefile | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
> >> index 95ea17a9d20c..ae53d54d7959 100644
> >> --- a/arch/x86/purgatory/Makefile
> >> +++ b/arch/x86/purgatory/Makefile
> >> @@ -16,7 +16,7 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS
> >>
> >> # When linking purgatory.ro with -r unresolved symbols are not checked,
> >> # also link a purgatory.chk binary without -r to check for unresolved symbols.
> >> -PURGATORY_LDFLAGS := -e purgatory_start -nostdlib -z nodefaultlib
> >> +PURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib
> >> LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS)
> >> LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS)
> >> targets += purgatory.ro purgatory.chk
> >> --
> >> 2.30.2
> >
> >--
> >Thanks,
> >~Nick Desaulniers
>
> --
> You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-li...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20211109000531.k23mgrfjn5tomevv%40google.com.



--
Thanks,
~Nick Desaulniers

Nick Desaulniers

unread,
Nov 10, 2021, 3:01:22 PM11/10/21
to Masahiro Yamada, x...@kernel.org, Thomas Gleixner, Ingo Molnar, Borislav Petkov, H . Peter Anvin, clang-bu...@googlegroups.com, Andy Lutomirski, Dave Hansen, linux-...@vger.kernel.org
On Sun, Nov 7, 2021 at 8:27 AM Masahiro Yamada <masa...@kernel.org> wrote:
>
> The -nostdlib option requests the compiler to not use the standard
> system startup files or libraries when linking. It is effective only
> when $(CC) is used as a linker driver.
>
> Since
>
> 379d98ddf413 ("x86: vdso: Use $LD instead of $CC to link")
>
> $(LD) is directly used, hence -nostdlib is unneeded.
>
> Signed-off-by: Masahiro Yamada <masa...@kernel.org>

Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesau...@google.com>

> ---
>
> arch/x86/entry/vdso/Makefile | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
> index a2dddcc189f6..693f8b9031fb 100644
> --- a/arch/x86/entry/vdso/Makefile
> +++ b/arch/x86/entry/vdso/Makefile
> @@ -172,7 +172,7 @@ $(obj)/vdso32.so.dbg: $(obj)/vdso32/vdso32.lds $(vobjs32) FORCE
> # The DSO images are built using a special linker script.
> #
> quiet_cmd_vdso = VDSO $@
> - cmd_vdso = $(LD) -nostdlib -o $@ \
> + cmd_vdso = $(LD) -o $@ \
> $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
> -T $(filter %.lds,$^) $(filter %.o,$^) && \
> sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
> --
> 2.30.2
>
> --
> You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-li...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20211107162641.324688-1-masahiroy%40kernel.org.



--
Thanks,
~Nick Desaulniers
Reply all
Reply to author
Forward
0 new messages