From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id DFDB73858C83 for ; Fri, 22 Apr 2022 18:44:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DFDB73858C83 Received: by mail-pl1-x630.google.com with SMTP id c23so12761873plo.0 for ; Fri, 22 Apr 2022 11:44:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lnZsOLSYs1BzRqxgh5KLtV0Oamx/Oq89T2N6YJyZB9Q=; b=Au7YKtLQgpyRGX2O2zKLIxu57+tsnYpJBION/6/bQT07fBnExaDnFGv+bmhMYzRT7i GzDKCkAg5lyY6QHA5lB1zMuFR2RB4UTD+ruJgSbh1MKOFs2fzf5MTOSNehf3Adlrxjmy W/D1JUSWxrHfMZYbza79ZzgtOe3wIVVt97AYps3iZAwOLjNC3MCBp8FiyIEiPIp5kmUY Jz9IvGB1CpVNj8Pz2EYLPExZN8R2fVLHWsV/Lbpn8dguyiswn/FQAbnANafePTJkW5zv GteohZr4PkgD3Cr6mpW/pCtIhFDFrXrfssZHksoXLlFJVVgZrgyJxHYKaSsGfC2tvKnV +/fw== X-Gm-Message-State: AOAM531UgGaupOMW0n8q9BiI5FFb/6zrE/lgv49YYcElqI4fcUFnqAOY v54WqwTzRX9LDKigpC7LKpMiUGZzasBTqpONYZS4VWnXxHY= X-Google-Smtp-Source: ABdhPJyqiPMUFC4IghOF6BDl/khI2v/xLw7PxzdPlg9rMWQyWA0J6yIRCwLGDDgvGCBKLC6okuWIW6ufwq6Q+tDc3Bg= X-Received: by 2002:a17:90b:1c12:b0:1d2:fc88:4f3b with SMTP id oc18-20020a17090b1c1200b001d2fc884f3bmr17842800pjb.28.1650653097804; Fri, 22 Apr 2022 11:44:57 -0700 (PDT) MIME-Version: 1.0 References: <20220414232129.1886210-1-hjl.tools@gmail.com> <20220414232129.1886210-6-hjl.tools@gmail.com> In-Reply-To: From: "H.J. Lu" Date: Fri, 22 Apr 2022 11:44:21 -0700 Message-ID: Subject: Re: [PATCH v10 5/7] elf: Add more DT_RELR tests To: Adhemerval Zanella Cc: GNU C Library , Fangrui Song Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3025.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Apr 2022 18:45:01 -0000 On Wed, Apr 20, 2022 at 10:41 AM Adhemerval Zanella 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 > > > >> --- > >> 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.