public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: GNU C Library <libc-alpha@sourceware.org>,
	Fangrui Song <maskray@google.com>
Subject: Re: [PATCH v10 5/7] elf: Add more DT_RELR tests
Date: Fri, 22 Apr 2022 11:44:21 -0700	[thread overview]
Message-ID: <CAMe9rOoy1k3GNynMi3aze9PWs9qewWk+S0RBUk0vphw8x8=wyQ@mail.gmail.com> (raw)
In-Reply-To: <d624aee4-c80c-2b00-ee85-9fcbeff866e5@linaro.org>

On Wed, Apr 20, 2022 at 10:41 AM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 20/04/2022 14:24, Adhemerval Zanella wrote:
> >
> >
> > On 14/04/2022 20:21, H.J. Lu wrote:
> >> Verify that:
> >>
> >> 1. A DT_RELR shared library without DT_NEEDED works.
> >> 2. A DT_RELR shared library without DT_VERNEED works.
> >> 3. A DT_RELR shared library without libc.so on DT_NEEDED works.
> >
> > LGTM, thanks.
> >
> > Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
> >
> >> ---
> >>  elf/Makefile           | 71 ++++++++++++++++++++++++++++++++++++++++--
> >>  elf/tst-relr-mod2.c    | 46 +++++++++++++++++++++++++++
> >>  elf/tst-relr-mod3a.c   | 49 +++++++++++++++++++++++++++++
> >>  elf/tst-relr-mod3b.c   | 22 +++++++++++++
> >>  elf/tst-relr-mod4a.c   | 19 +++++++++++
> >>  elf/tst-relr-mod4b.c   | 19 +++++++++++
> >>  elf/tst-relr-mod4b.map |  3 ++
> >>  elf/tst-relr2.c        | 27 ++++++++++++++++
> >>  elf/tst-relr3.c        | 27 ++++++++++++++++
> >>  elf/tst-relr4.c        |  1 +
> >>  10 files changed, 281 insertions(+), 3 deletions(-)
> >>  create mode 100644 elf/tst-relr-mod2.c
> >>  create mode 100644 elf/tst-relr-mod3a.c
> >>  create mode 100644 elf/tst-relr-mod3b.c
> >>  create mode 100644 elf/tst-relr-mod4a.c
> >>  create mode 100644 elf/tst-relr-mod4b.c
> >>  create mode 100644 elf/tst-relr-mod4b.map
> >>  create mode 100644 elf/tst-relr2.c
> >>  create mode 100644 elf/tst-relr3.c
> >>  create mode 100644 elf/tst-relr4.c
> >>
> >> diff --git a/elf/Makefile b/elf/Makefile
> >> index 3f3e711dd2..07ac9ec3ef 100644
> >> --- a/elf/Makefile
> >> +++ b/elf/Makefile
> >> @@ -544,7 +544,20 @@ endif
> >>  ifeq ($(have-dt-relr),yes)
> >>  tests += \
> >>    tst-relr \
> >> +  tst-relr2 \
> >> +  tst-relr3 \
> >> +  tst-relr4 \
> >>  # tests
> >> +modules-names-dt-relr = \
> >> +  tst-relr-mod2 \
> >> +  tst-relr-mod3a \
> >> +  tst-relr-mod3b \
> >> +  tst-relr-mod4a \
> >> +  tst-relr-mod4b \
> >> +# modules-names-dt-relr
> >> +modules-names += $(modules-names-dt-relr)
> >> +# These shared libraries have special build rules.
> >> +modules-names-nobuild += $(modules-names-dt-relr)
> >>  ifeq ($(have-fpie),yes)
> >>  tests += \
> >>    tst-relr-pie \
> >> @@ -603,7 +616,7 @@ test-extras += \
> >>    tst-tlsmod17a \
> >>    tst-tlsmod18a \
> >>    # test-extras
> >> -modules-names = \
> >> +modules-names += \
> >>    circlemod1 \
> >>    circlemod1a \
> >>    circlemod2 \
> >> @@ -973,8 +986,13 @@ extra-test-objs += $(addsuffix .os,$(strip $(modules-names)))
> >>
> >>  # filtmod1.so, tst-big-note-lib.so, tst-ro-dynamic-mod.so have special
> >>  # rules.
> >> -modules-names-nobuild := filtmod1 tst-big-note-lib tst-ro-dynamic-mod \
> >> -                     tst-audit24bmod1 tst-audit24bmod2
> >> +modules-names-nobuild += \
> >> +  filtmod1 \
> >> +  tst-audit24bmod1 \
> >> +  tst-audit24bmod2 \
> >> +  tst-big-note-lib \
> >> +  tst-ro-dynamic-mod \
> >> +# modules-names-nobuild
> >>
> >>  tests += $(tests-static)
> >>
> >
> > Ok.
> >
> >> @@ -2768,3 +2786,50 @@ $(objpfx)check-tst-relr-pie.out: $(objpfx)tst-relr-pie
> >>              | sed -ne '/required from libc.so/,$$ p' \
> >>              | grep GLIBC_ABI_DT_RELR > $@; \
> >>      $(evaluate-test)
> >> +
> >> +# The test checks if a DT_RELR shared library without DT_NEEDED works as
> >> +# intended, so it uses an explicit link rule.
> >> +$(objpfx)tst-relr2: $(objpfx)tst-relr-mod2.so
> >> +$(objpfx)tst-relr-mod2.so: $(objpfx)tst-relr-mod2.os
> >> +    $(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
> >> +    $(LDFLAGS-soname-fname) \
> >> +    -shared -o $@.new $(filter-out $(map-file),$^)
> >> +    $(call after-link,$@.new)
> >> +    mv -f $@.new $@
> >> +
> >> +# The test checks if a DT_RELR shared library without DT_VERNEED works as
> >> +# intended, so it uses an explicit link rule.
> >> +$(objpfx)tst-relr3: $(objpfx)tst-relr-mod3a.so
> >> +$(objpfx)tst-relr-mod3b.so: $(objpfx)tst-relr-mod3b.os
> >> +    $(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
> >> +    $(LDFLAGS-soname-fname) \
> >> +    -shared -o $@.new $(filter-out $(map-file),$^)
> >> +    $(call after-link,$@.new)
> >> +    mv -f $@.new $@
> >> +
> >> +$(objpfx)tst-relr-mod3a.so: $(objpfx)tst-relr-mod3a.os \
> >> +  $(objpfx)tst-relr-mod3b.so
> >> +    $(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
> >> +    $(LDFLAGS-soname-fname) \
> >> +    -shared -o $@.new $(filter-out $(map-file),$^)
> >> +    $(call after-link,$@.new)
> >> +    mv -f $@.new $@
> >> +
> >> +# The test checks if a DT_RELR shared library without libc.so on DT_NEEDED
> >> +# works as intended, so it uses an explicit link rule.
> >> +$(objpfx)tst-relr4: $(objpfx)tst-relr-mod4a.so
> >> +$(objpfx)tst-relr-mod4b.so: $(objpfx)tst-relr-mod4b.os
> >> +    $(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
> >> +    $(LDFLAGS-soname-fname) \
> >> +    -Wl,--version-script=tst-relr-mod4b.map \
> >> +    -shared -o $@.new $(filter-out $(map-file),$^)
> >> +    $(call after-link,$@.new)
> >> +    mv -f $@.new $@
> >> +
> >> +$(objpfx)tst-relr-mod4a.so: $(objpfx)tst-relr-mod4a.os \
> >> +  $(objpfx)tst-relr-mod4b.so
> >> +    $(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
> >> +    $(LDFLAGS-soname-fname) \
> >> +    -shared -o $@.new $(filter-out $(map-file),$^)
> >> +    $(call after-link,$@.new)
> >> +    mv -f $@.new $@
> >
> > Ok.
>
> In fact I am seeing issues on i686-linux-gnu where linking is failing with
> a missing __stack_chk_fail_local if --enable-stack-protector is used. I
> think you will need to explicit add libc_nonshared for this specific
> shared objects:
>
> diff --git a/elf/Makefile b/elf/Makefile
> index bf8a61dc30..152e495b8d 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -2795,7 +2795,8 @@ $(objpfx)tst-relr2: $(objpfx)tst-relr-mod2.so
>  $(objpfx)tst-relr-mod2.so: $(objpfx)tst-relr-mod2.os
>         $(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
>         $(LDFLAGS-soname-fname) \
> -       -shared -o $@.new $(filter-out $(map-file),$^)
> +       -shared -o $@.new $(filter-out $(map-file),$^) \
> +       $(common-objpfx)libc_nonshared.a

These shared libraries shouldn't have any undefined symbols.
I am adding these in v11:

+CFLAGS-tst-relr-mod2.c += $(no-stack-protector)
+CFLAGS-tst-relr-mod3a.c += $(no-stack-protector)
+CFLAGS-tst-relr-mod3b.c += $(no-stack-protector)
+CFLAGS-tst-relr-mod4a.c += $(no-stack-protector)
+CFLAGS-tst-relr-mod4b.c += $(no-stack-protector)

>         $(call after-link,$@.new)
>         mv -f $@.new $@
>
> @@ -2805,7 +2806,8 @@ $(objpfx)tst-relr3: $(objpfx)tst-relr-mod3a.so
>  $(objpfx)tst-relr-mod3b.so: $(objpfx)tst-relr-mod3b.os
>         $(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
>         $(LDFLAGS-soname-fname) \
> -       -shared -o $@.new $(filter-out $(map-file),$^)
> +       -shared -o $@.new $(filter-out $(map-file),$^) \
> +       $(common-objpfx)libc_nonshared.a
>         $(call after-link,$@.new)
>         mv -f $@.new $@
>
> @@ -2813,7 +2815,8 @@ $(objpfx)tst-relr-mod3a.so: $(objpfx)tst-relr-mod3a.os \
>    $(objpfx)tst-relr-mod3b.so
>         $(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
>         $(LDFLAGS-soname-fname) \
> -       -shared -o $@.new $(filter-out $(map-file),$^)
> +       -shared -o $@.new $(filter-out $(map-file),$^) \
> +       $(common-objpfx)libc_nonshared.a
>         $(call after-link,$@.new)
>         mv -f $@.new $@
>
> @@ -2824,7 +2827,8 @@ $(objpfx)tst-relr-mod4b.so: $(objpfx)tst-relr-mod4b.os
>         $(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
>         $(LDFLAGS-soname-fname) \
>         -Wl,--version-script=tst-relr-mod4b.map \
> -       -shared -o $@.new $(filter-out $(map-file),$^)
> +       -shared -o $@.new $(filter-out $(map-file),$^) \
> +       $(common-objpfx)libc_nonshared.a
>         $(call after-link,$@.new)
>         mv -f $@.new $@
>
> @@ -2832,6 +2836,7 @@ $(objpfx)tst-relr-mod4a.so: $(objpfx)tst-relr-mod4a.os \
>    $(objpfx)tst-relr-mod4b.so
>         $(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
>         $(LDFLAGS-soname-fname) \
> -       -shared -o $@.new $(filter-out $(map-file),$^)
> +       -shared -o $@.new $(filter-out $(map-file),$^) \
> +       $(common-objpfx)libc_nonshared.a
>         $(call after-link,$@.new)
>         mv -f $@.new $@
>

Thanks.

-- 
H.J.

  reply	other threads:[~2022-04-22 18:44 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-14 23:21 [PATCH v10 0/7] Support DT_RELR relative relocation format H.J. Lu
2022-04-14 23:21 ` [PATCH v10 1/7] elf: Define DT_RELR related macros and types H.J. Lu
2022-04-20 12:45   ` Adhemerval Zanella
2022-04-14 23:21 ` [PATCH v10 2/7] Add GLIBC_ABI_DT_RELR for DT_RELR support H.J. Lu
2022-04-20 13:32   ` Adhemerval Zanella
2022-04-14 23:21 ` [PATCH v10 3/7] elf: Support DT_RELR relative relocation format [BZ #27924] H.J. Lu
2022-04-20 13:44   ` Adhemerval Zanella
2022-04-22 18:47     ` H.J. Lu
2022-04-14 23:21 ` [PATCH v10 4/7] elf: Properly handle zero DT_RELA/DT_REL values H.J. Lu
2022-04-20 17:10   ` Adhemerval Zanella
2022-04-14 23:21 ` [PATCH v10 5/7] elf: Add more DT_RELR tests H.J. Lu
2022-04-20 17:24   ` Adhemerval Zanella
2022-04-20 17:41     ` Adhemerval Zanella
2022-04-22 18:44       ` H.J. Lu [this message]
2022-04-14 23:21 ` [PATCH v10 6/7] Add --disable-default-dt-relr H.J. Lu
2022-04-20 17:49   ` Adhemerval Zanella
2022-04-22 18:41     ` H.J. Lu
2022-04-14 23:21 ` [PATCH v10 7/7] NEWS: Mention DT_RELR support H.J. Lu
2022-04-20 17:49   ` Adhemerval Zanella

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='CAMe9rOoy1k3GNynMi3aze9PWs9qewWk+S0RBUk0vphw8x8=wyQ@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    --cc=maskray@google.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).