public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Arsen Arsenović" <arsen@gentoo.org>
To: libc-alpha@sourceware.org
Cc: "Carlos O'Donell" <carlos@redhat.com>,
	"Gentoo Toolchain" <toolchain@gentoo.org>,
	"Arsen Arsenović" <arsen@gentoo.org>
Subject: [PATCH] elf,nptl: Add -z lazy -z norelro to tests that need it
Date: Thu,  2 Mar 2023 12:25:19 +0100	[thread overview]
Message-ID: <20230302112519.914641-1-arsen@gentoo.org> (raw)

Some toolchains, such as that used on Gentoo Hardened, set -z now -z
relro out of the box.  These flags break tests that rely on fixups in
underlinked libraries being applied after a dlopen happens.
---
Morning,

This patch fixes a few test failures that we encounter on Gentoo when
using a toolchain that builds packages with full relro.

All of these failures come down to underlinked test objects, which are
inherently in opposition with it.

Tested on x86_64-pc-linux-gnu against 2.37 and
59a6d5e9477695c41d6feef7ef8636f8f744f3c5, so it should be okay for
backporting too.

Have a lovely day!

 elf/Makefile  | 22 +++++++++++++++++++++-
 nptl/Makefile |  2 +-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/elf/Makefile b/elf/Makefile
index 0d19964d42..3387b7e6c9 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -1190,6 +1190,11 @@ postclean-generated += $(objpfx)/dso-sort-tests-2.generated-makefile \
 ifeq (yes,$(have-tunables))
 $(eval $(call include_dsosort_tests,dso-sort-tests-1.def))
 $(eval $(call include_dsosort_tests,dso-sort-tests-2.def))
+
+# BZ15311 is intentionally underlinked.
+LDFLAGS-tst-bz15311-b.so += -Wl,-z,lazy -Wl,-z,norelro
+LDFLAGS-tst-bz15311-c.so += -Wl,-z,lazy -Wl,-z,norelro
+LDFLAGS-tst-bz15311-d.so += -Wl,-z,lazy -Wl,-z,norelro
 endif
 
 check-abi: $(objpfx)check-abi-ld.out \
@@ -1514,6 +1519,20 @@ LDFLAGS-tst-initorderb2.so = -Wl,--no-as-needed
 LDFLAGS-tst-tlsmod5.so = -nostdlib -Wl,--no-as-needed
 LDFLAGS-tst-tlsmod6.so = -nostdlib -Wl,--no-as-needed
 
+# The following tests are underlinked or rely on fixups being applied after a
+# dlopen call.  On toolchains that set -z now and -z relro by default, this
+# leads to failures to load or fix up the executables being tested.
+LDFLAGS-circlemod2.so = -Wl,-z,lazy
+LDFLAGS-tst-tls20mod-bad.so = -Wl,-z,lazy
+LDFLAGS-reldep6mod1.so += -Wl,-z,lazy -Wl,-z,norelro
+LDFLAGS-constload2.so = -Wl,-z,lazy -Wl,-z,norelro
+LDFLAGS-constload3.so = -Wl,-z,lazy -Wl,-z,norelro
+LDFLAGS-dblloadmod3.so = -Wl,-z,lazy -Wl,-z,norelro
+LDFLAGS-ifuncmod6.so = -Wl,-z,lazy -Wl,-z,norelro
+LDFLAGS-ltglobmod2.so = -Wl,-z,lazy -Wl,-z,norelro
+LDFLAGS-testobj1.so = -Wl,-z,lazy -Wl,-z,norelro
+LDFLAGS-testobj6.so = -Wl,-z,lazy -Wl,-z,norelro
+
 testobj1.so-no-z-defs = yes
 testobj3.so-no-z-defs = yes
 testobj4.so-no-z-defs = yes
@@ -1612,6 +1631,7 @@ $(objpfx)multiload.out: $(objpfx)testobj1.so
 LDFLAGS-origtest = -rdynamic
 $(objpfx)origtest.out: $(objpfx)testobj1.so
 
+$(objpfx)resolvfail.out: $(objpfx)testobj1.so
 ifeq ($(have-thread-library),yes)
 $(objpfx)resolvfail: $(shared-thread-library)
 endif
@@ -2337,7 +2357,7 @@ LDFLAGS-tst-audit25a = -Wl,-z,lazy
 $(objpfx)tst-audit25mod1.so: $(objpfx)tst-audit25mod3.so
 LDFLAGS-tst-audit25mod1.so = -Wl,-z,now
 $(objpfx)tst-audit25mod2.so: $(objpfx)tst-audit25mod4.so
-LDFLAGS-tst-audit25mod2.so = -Wl,-z,lazy
+LDFLAGS-tst-audit25mod2.so = -Wl,-z,lazy -Wl,-z,norelro
 tst-audit25a-ARGS = -- $(host-test-program-cmd)
 
 $(objpfx)tst-audit25b.out: $(objpfx)tst-auditmod25.so
diff --git a/nptl/Makefile b/nptl/Makefile
index 8cec6faee3..140add412c 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -569,7 +569,7 @@ $(objpfx)tst-compat-forwarder: $(objpfx)tst-compat-forwarder-mod.so
 tst-mutex10-ENV = GLIBC_TUNABLES=glibc.elision.enable=1
 
 # Protect against a build using -Wl,-z,now.
-LDFLAGS-tst-audit-threads-mod1.so = -Wl,-z,lazy
+LDFLAGS-tst-audit-threads-mod1.so = -Wl,-z,lazy -Wl,-z,norelro
 LDFLAGS-tst-audit-threads-mod2.so = -Wl,-z,lazy
 LDFLAGS-tst-audit-threads = -Wl,-z,lazy
 $(objpfx)tst-audit-threads: $(objpfx)tst-audit-threads-mod2.so
-- 
2.39.2


             reply	other threads:[~2023-03-02 11:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02 11:25 Arsen Arsenović [this message]
2023-03-03 11:51 ` Florian Weimer
2023-03-03 21:54   ` Arsen Arsenović
2023-03-04 17:46     ` Arsen Arsenović
2023-03-06  9:15       ` Florian Weimer
2023-03-06 14:17         ` Arsen Arsenović
2023-03-06 16:42           ` Arsen Arsenović

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=20230302112519.914641-1-arsen@gentoo.org \
    --to=arsen@gentoo.org \
    --cc=carlos@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=toolchain@gentoo.org \
    /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).