public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug dynamic-link/31799] New: -static-pie -Wl,-Ttext-segment=0x50000 doesn't work
@ 2024-05-25 22:59 hjl.tools at gmail dot com
2024-05-25 23:00 ` [Bug dynamic-link/31799] " hjl.tools at gmail dot com
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: hjl.tools at gmail dot com @ 2024-05-25 22:59 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=31799
Bug ID: 31799
Summary: -static-pie -Wl,-Ttext-segment=0x50000 doesn't work
Product: glibc
Version: 2.40
Status: NEW
Severity: normal
Priority: P2
Component: dynamic-link
Assignee: unassigned at sourceware dot org
Reporter: hjl.tools at gmail dot com
Target Milestone: ---
[hjl@gnu-cfl-3 tmp]$ cat x.c
int
main ()
{
return 0;
}
[hjl@gnu-cfl-3 tmp]$ gcc -fPIE -static-pie -Wl,-Ttext-segment=0x50000 x.c
[hjl@gnu-cfl-3 tmp]$ readelf -h a.out
ELF Header:
Magic: 7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - GNU
ABI Version: 0
Type: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x57750
Start of program headers: 64 (bytes into file)
Start of section headers: 824960 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 12
Size of section headers: 64 (bytes)
Number of section headers: 37
Section header string table index: 36
[hjl@gnu-cfl-3 tmp]$ ./a.out
Segmentation fault (core dumped)
[hjl@gnu-cfl-3 tmp]$
Static PIE is marked ET_EXEC if its load address isn't 0. It is done to sure
that -Wl,-Ttext-segment=0x50000 works.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug dynamic-link/31799] -static-pie -Wl,-Ttext-segment=0x50000 doesn't work
2024-05-25 22:59 [Bug dynamic-link/31799] New: -static-pie -Wl,-Ttext-segment=0x50000 doesn't work hjl.tools at gmail dot com
@ 2024-05-25 23:00 ` hjl.tools at gmail dot com
2024-05-26 13:53 ` hjl.tools at gmail dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: hjl.tools at gmail dot com @ 2024-05-25 23:00 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=31799
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |2.40
Assignee|unassigned at sourceware dot org |hjl.tools at gmail dot com
Status|NEW |ASSIGNED
--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> ---
This works:
diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c
index 10c23d0bf0..939113f688 100644
--- a/elf/dl-reloc-static-pie.c
+++ b/elf/dl-reloc-static-pie.c
@@ -32,16 +32,20 @@
/* Relocate static executable with PIE. */
+extern const ElfW(Ehdr) __ehdr_start attribute_hidden;
+
void
_dl_relocate_static_pie (void)
{
struct link_map *main_map = _dl_get_dl_main_map ();
/* Figure out the run-time load address of static PIE. */
- main_map->l_addr = elf_machine_load_address ();
+ ElfW(Addr) l_addr = elf_machine_load_address ();
+ if (__ehdr_start.e_type == ET_DYN)
+ main_map->l_addr = l_addr;
/* Read our own dynamic section and fill in the info array. */
- main_map->l_ld = ((void *) main_map->l_addr + elf_machine_dynamic ());
+ main_map->l_ld = ((void *) l_addr + elf_machine_dynamic ());
const ElfW(Phdr) *ph, *phdr = GL(dl_phdr);
size_t phnum = GL(dl_phnum);
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug dynamic-link/31799] -static-pie -Wl,-Ttext-segment=0x50000 doesn't work
2024-05-25 22:59 [Bug dynamic-link/31799] New: -static-pie -Wl,-Ttext-segment=0x50000 doesn't work hjl.tools at gmail dot com
2024-05-25 23:00 ` [Bug dynamic-link/31799] " hjl.tools at gmail dot com
@ 2024-05-26 13:53 ` hjl.tools at gmail dot com
2024-05-26 13:56 ` hjl.tools at gmail dot com
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: hjl.tools at gmail dot com @ 2024-05-26 13:53 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=31799
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://sourceware.org/bugz
| |illa/show_bug.cgi?id=31795
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug dynamic-link/31799] -static-pie -Wl,-Ttext-segment=0x50000 doesn't work
2024-05-25 22:59 [Bug dynamic-link/31799] New: -static-pie -Wl,-Ttext-segment=0x50000 doesn't work hjl.tools at gmail dot com
2024-05-25 23:00 ` [Bug dynamic-link/31799] " hjl.tools at gmail dot com
2024-05-26 13:53 ` hjl.tools at gmail dot com
@ 2024-05-26 13:56 ` hjl.tools at gmail dot com
2024-05-27 2:28 ` i at maskray dot me
2024-05-27 13:13 ` fweimer at redhat dot com
4 siblings, 0 replies; 6+ messages in thread
From: hjl.tools at gmail dot com @ 2024-05-26 13:56 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=31799
--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
For static PIE, its dynamic section entries contain the relocated values for
the
load address. We can't relocate them again.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug dynamic-link/31799] -static-pie -Wl,-Ttext-segment=0x50000 doesn't work
2024-05-25 22:59 [Bug dynamic-link/31799] New: -static-pie -Wl,-Ttext-segment=0x50000 doesn't work hjl.tools at gmail dot com
` (2 preceding siblings ...)
2024-05-26 13:56 ` hjl.tools at gmail dot com
@ 2024-05-27 2:28 ` i at maskray dot me
2024-05-27 13:13 ` fweimer at redhat dot com
4 siblings, 0 replies; 6+ messages in thread
From: i at maskray dot me @ 2024-05-27 2:28 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=31799
Fangrui Song <i at maskray dot me> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |i at maskray dot me
--- Comment #3 from Fangrui Song <i at maskray dot me> ---
> Static PIE is marked ET_EXEC if its load address isn't 0. It is done to sure that -Wl,-Ttext-segment=0x50000 works.
I think we should revisit the 2013 GNU ld special case.
See https://sourceware.org/bugzilla/show_bug.cgi?id=31795#c37 : the --no-pie
option added in 2021 makes the special case unnecessary.
musl supports the first PT_LOAD having a non-zero p_vaddr.
Fixing the segfault is desired.
However, there is probably no requirement that loaders (kernel / rtld) should
make the image base >= p_vaddr.
```
% ~/musl/out/debug/obj/musl-gcc -fpie a.c -static-pie -fuse-ld=lld
-Wl,--image-base=0x50000 -o a
% ./a
0x7f036cf6b599
% gcc -fpie a.c -static-pie -fuse-ld=lld -Wl,--image-base=0x50000 -o a
% ./a
[1] 2347408 segmentation fault ./a
```
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug dynamic-link/31799] -static-pie -Wl,-Ttext-segment=0x50000 doesn't work
2024-05-25 22:59 [Bug dynamic-link/31799] New: -static-pie -Wl,-Ttext-segment=0x50000 doesn't work hjl.tools at gmail dot com
` (3 preceding siblings ...)
2024-05-27 2:28 ` i at maskray dot me
@ 2024-05-27 13:13 ` fweimer at redhat dot com
4 siblings, 0 replies; 6+ messages in thread
From: fweimer at redhat dot com @ 2024-05-27 13:13 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=31799
Florian Weimer <fweimer at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Flags| |security-
CC| |fweimer at redhat dot com
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-05-27 13:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-25 22:59 [Bug dynamic-link/31799] New: -static-pie -Wl,-Ttext-segment=0x50000 doesn't work hjl.tools at gmail dot com
2024-05-25 23:00 ` [Bug dynamic-link/31799] " hjl.tools at gmail dot com
2024-05-26 13:53 ` hjl.tools at gmail dot com
2024-05-26 13:56 ` hjl.tools at gmail dot com
2024-05-27 2:28 ` i at maskray dot me
2024-05-27 13:13 ` fweimer at redhat dot com
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).