* [PATCH v2] Enable DT_RELR in glibc shared libraries and PIEs automatically
@ 2022-05-16 13:17 H.J. Lu
2022-05-16 13:44 ` Florian Weimer
0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2022-05-16 13:17 UTC (permalink / raw)
To: libc-alpha
Enable DT_RELR in glibc shared libraries and position independent
executables (PIE) automatically if linker supports -z pack-relative-relocs.
---
Makeconfig | 12 ++++++++++++
Makerules | 2 ++
elf/Makefile | 5 ++++-
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/Makeconfig b/Makeconfig
index 760f14e92f..c87d644044 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -362,6 +362,15 @@ relro-LDFLAGS = -Wl,-z,relro
LDFLAGS.so += $(relro-LDFLAGS)
LDFLAGS-rtld += $(relro-LDFLAGS)
+# Linker options to enable and disable DT_RELR.
+ifeq ($(have-dt-relr),yes)
+dt-relr-ldflag = -Wl,-z,pack-relative-relocs
+no-dt-relr-ldflag = -Wl,-z,nopack-relative-relocs
+else
+dt-relr-ldflag =
+no-dt-relr-ldflag =
+endif
+
ifeq (no,$(build-pie-default))
pie-default = $(no-pie-ccflag)
else # build-pie-default
@@ -370,6 +379,7 @@ pic-default = -DPIC
pie-default = $(pie-ccflag)
ifeq (yes,$(enable-static-pie))
+static-pie-dt-relr-ldflag = $(dt-relr-ldflag)
ifeq (yes,$(have-static-pie))
static-pie-ldflag = -static-pie
else
@@ -404,6 +414,7 @@ link-extra-libs-tests = $(libsupport)
# Command for linking PIE programs with the C library.
ifndef +link-pie
+link-pie-before-inputs = $(if $($(@F)-no-pie),$(no-pie-ldflag),-pie) \
+ $(if $($(@F)-no-dt-relr),$(no-dt-relr-ldflag),$(dt-relr-ldflag)) \
-Wl,-O1 -nostdlib -nostartfiles \
$(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
$(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
@@ -436,6 +447,7 @@ endif
ifndef +link-static
+link-static-before-inputs = -nostdlib -nostartfiles -static \
$(if $($(@F)-no-pie),$(no-pie-ldflag),$(static-pie-ldflag)) \
+ $(if $($(@F)-no-dt-relr),$(no-dt-relr-ldflag),$(static-pie-dt-relr-ldflag)) \
$(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
$(firstword $(CRT-$(@F)) $(csu-objpfx)$(real-static-start-installed-name)) \
$(+preinit) $(+prectorT)
diff --git a/Makerules b/Makerules
index 354528b8c7..dfe89e9e39 100644
--- a/Makerules
+++ b/Makerules
@@ -536,6 +536,7 @@ lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(link-libc-deps)
define build-shlib-helper
$(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \
$(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
+ $(if $($(@F)-no-dt-relr),$(no-dt-relr-ldflag),$(dt-relr-ldflag)) \
$(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
$(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
-Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
@@ -588,6 +589,7 @@ endef
define build-module-helper
$(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
$(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
+ $(if $($(@F)-no-dt-relr),$(no-dt-relr-ldflag),$(dt-relr-ldflag)) \
-B$(csu-objpfx) $(load-map-file) \
$(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
$(link-test-modules-rpath-link) \
diff --git a/elf/Makefile b/elf/Makefile
index fc9860edee..fa98e188df 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -1335,6 +1335,7 @@ $(objpfx)ld.so: $(objpfx)librtld.os $(ld-map)
# if the sanity check below fails.
$(LINK.o) -nostdlib -nostartfiles -shared -o $@.new \
$(LDFLAGS-rtld) -Wl,-z,defs $(z-now-$(bind-now)) \
+ $(dt-relr-ldflag) \
$(filter-out $(map-file),$^) $(load-map-file) \
-Wl,-soname=$(rtld-installed-name)
$(call after-link,$@.new)
@@ -1659,6 +1660,7 @@ $(objpfx)nodlopen2.out: $(objpfx)nodlopenmod2.so
$(objpfx)filtmod1.so: $(objpfx)filtmod1.os $(objpfx)filtmod2.so
$(LINK.o) -shared -o $@ -B$(csu-objpfx) $(LDFLAGS.so) \
+ $(dt-relr-ldflag) \
-L$(subst :, -L,$(rpath-link)) \
-Wl,-rpath-link=$(rpath-link) \
$< -Wl,-F,$(objpfx)filtmod2.so
@@ -2462,7 +2464,7 @@ $(objpfx)tst-big-note: $(objpfx)tst-big-note-lib.so
# artificial, large note in tst-big-note-lib.o and invalidate the
# test.
$(objpfx)tst-big-note-lib.so: $(objpfx)tst-big-note-lib.o
- $(LINK.o) -shared -o $@ $(LDFLAGS.so) $<
+ $(LINK.o) -shared -o $@ $(LDFLAGS.so) $(dt-relr-ldflag) $<
$(objpfx)tst-unwind-ctor: $(objpfx)tst-unwind-ctor-lib.so
@@ -2771,6 +2773,7 @@ $(objpfx)tst-ro-dynamic: $(objpfx)tst-ro-dynamic-mod.so
$(objpfx)tst-ro-dynamic-mod.so: $(objpfx)tst-ro-dynamic-mod.os \
tst-ro-dynamic-mod.map
$(LINK.o) -nostdlib -nostartfiles -shared -o $@ \
+ $(dt-relr-ldflag) \
-Wl,--script=tst-ro-dynamic-mod.map \
$(objpfx)tst-ro-dynamic-mod.os
--
2.36.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] Enable DT_RELR in glibc shared libraries and PIEs automatically
2022-05-16 13:17 [PATCH v2] Enable DT_RELR in glibc shared libraries and PIEs automatically H.J. Lu
@ 2022-05-16 13:44 ` Florian Weimer
2022-05-20 22:50 ` Fangrui Song
0 siblings, 1 reply; 4+ messages in thread
From: Florian Weimer @ 2022-05-16 13:44 UTC (permalink / raw)
To: H.J. Lu via Libc-alpha
* H. J. Lu via Libc-alpha:
> Enable DT_RELR in glibc shared libraries and position independent
> executables (PIE) automatically if linker supports -z
> pack-relative-relocs.
Thanks for updating the commit subject.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Florian
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] Enable DT_RELR in glibc shared libraries and PIEs automatically
2022-05-16 13:44 ` Florian Weimer
@ 2022-05-20 22:50 ` Fangrui Song
2022-05-21 1:51 ` H.J. Lu
0 siblings, 1 reply; 4+ messages in thread
From: Fangrui Song @ 2022-05-20 22:50 UTC (permalink / raw)
To: Florian Weimer; +Cc: H.J. Lu via Libc-alpha
On 2022-05-16, Florian Weimer via Libc-alpha wrote:
>* H. J. Lu via Libc-alpha:
>
>> Enable DT_RELR in glibc shared libraries and position independent
>> executables (PIE) automatically if linker supports -z
>> pack-relative-relocs.
>
>Thanks for updating the commit subject.
>
>Reviewed-by: Florian Weimer <fweimer@redhat.com>
>
>Florian
>
Thanks for the patch.
Question: does gdb need DT_RELR support to debug such a shared object?
`gdb elf/ld.so` will report
BFD: path/to/elf/ld.so: unknown type [0x13] section `.relr.dyn'
but I do not know whether any functionality is affected in the absence
of SHT_RELR support.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] Enable DT_RELR in glibc shared libraries and PIEs automatically
2022-05-20 22:50 ` Fangrui Song
@ 2022-05-21 1:51 ` H.J. Lu
0 siblings, 0 replies; 4+ messages in thread
From: H.J. Lu @ 2022-05-21 1:51 UTC (permalink / raw)
To: Fangrui Song; +Cc: Florian Weimer, H.J. Lu via Libc-alpha
On Fri, May 20, 2022 at 3:50 PM Fangrui Song via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> On 2022-05-16, Florian Weimer via Libc-alpha wrote:
> >* H. J. Lu via Libc-alpha:
> >
> >> Enable DT_RELR in glibc shared libraries and position independent
> >> executables (PIE) automatically if linker supports -z
> >> pack-relative-relocs.
> >
> >Thanks for updating the commit subject.
> >
> >Reviewed-by: Florian Weimer <fweimer@redhat.com>
> >
> >Florian
> >
>
> Thanks for the patch.
>
> Question: does gdb need DT_RELR support to debug such a shared object?
> `gdb elf/ld.so` will report
>
> BFD: path/to/elf/ld.so: unknown type [0x13] section `.relr.dyn'
>
> but I do not know whether any functionality is affected in the absence
> of SHT_RELR support.
You need GDB 12 or 11.2 for DT_RELR.
--
H.J.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-05-21 1:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16 13:17 [PATCH v2] Enable DT_RELR in glibc shared libraries and PIEs automatically H.J. Lu
2022-05-16 13:44 ` Florian Weimer
2022-05-20 22:50 ` Fangrui Song
2022-05-21 1:51 ` H.J. Lu
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).