[PATCH] debug: Link tst-sprintf-fortify-rdonly-static with -Wl,-z,relro [BZ 33183]
John David Anglin
dave.anglin@bell.net
Wed Jul 23 21:06:14 GMT 2025
On 2025-07-23 4:50 p.m., Florian Weimer wrote:
> * John David Anglin:
>
>> Fixes tst-sprintf-fortify-rdonly-static on hppa-linux.
>>
>> Okay?
>>
>> Dave
>> ---
>>
>> debug: Link tst-sprintf-fortify-rdonly-static with -Wl,-z,relro [BZ 33183]
>>
>> This test requires relro_format be placed in the PT_GNU_RELRO segment.
>> The ELF linker enables -z relro support by default on all Linux targets
>> except FRV, HPPA, IA64 and MIPS. On these targets, we need to explicitly
>> link with -z relro to place relro_format in the PT_GNU_RELRO segment.
>>
>> Signed-off-by: John David Anglin <dave.anglin@bell.net>
>>
>> diff --git a/debug/Makefile b/debug/Makefile
>> index 919bf91c42..6c857a56da 100644
>> --- a/debug/Makefile
>> +++ b/debug/Makefile
>> @@ -187,6 +187,7 @@ CFLAGS-tst-sprintf-fortify-rdonly-dlopen.c += $(no-fortify-source) -D_FORTIFY_SO
>> CFLAGS-tst-sprintf-fortify-rdonly-static.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
>> CFLAGS-tst-fortify-syslog.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
>> CFLAGS-tst-fortify-wide.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
>> +LDFLAGS-tst-sprintf-fortify-rdonly-static += $(relro-LDFLAGS)
>>
>> $(objpfx)tst-sprintf-fortify-rdonly: $(objpfx)tst-sprintf-fortify-rdonly-mod.so
>> $(objpfx)tst-sprintf-fortify-rdonly.out: \
>
> The issue here is that (at least without static PIE), there's no
> relocation, and RELRO isn't active. (Whether the program header exists
> or not does not matter.) So the RELRO region isn't actually read-only.
Based on my testing, static PIE was disabled on hppa for reasons unrelated to
PIE (we get a pc-relative stub overflow in one test). I may try to address this
in gcc but it is tricky. We have no exact way of calculating how many pc-relative
branches need a stub table entry.
> Therefore, I would prefer a different fix:
>
> For !SHARED builds, _dl_readonly_area should not treat the RELRO area of
> the main link map as read-only.
>
> And then we build tst-sprintf-fortify-rdonly-static slightly
> differently, adjusting the test expecation.
Will you implement this fix?
Thanks,
Dave
--
John David Anglin dave.anglin@bell.net
More information about the Libc-alpha
mailing list