<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/93420>93420</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Static PIE with non-zero load address isn't marked as ET_EXEC
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lld:ELF
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hjl-tools
</td>
</tr>
</table>
<pre>
Static PIE with non-zero load address isn't marked as ET_EXEC:
```
[hjl@gnu-cfl-3 tmp]$ cat x.c
#include <stdio.h>
int
main ()
{
printf ("hello\n");
return 0;
}
[hjl@gnu-cfl-3 tmp]$ gcc -fPIE -static-pie -Wl,--image-base=0x50000 x.c -fuse-ld=lld
[hjl@gnu-cfl-3 tmp]$ readelf -h a.out
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Position-Independent Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x7f540
Start of program headers: 64 (bytes into file)
Start of section headers: 799376 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 11
Size of section headers: 64 (bytes)
Number of section headers: 37
Section header string table index: 35
[hjl@gnu-cfl-3 tmp]$
```
ld does:
```
[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: 0x577a0
Start of program headers: 64 (bytes into file)
Start of section headers: 825120 (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]$
```
Neither output works without the fix for glibc bug:
https://sourceware.org/bugzilla/show_bug.cgi?id=31799
Wit the proposed glibc fix:
https://patchwork.sourceware.org/project/glibc/list/?series=34382
ld output works and lld output doesn't work. When a static PIE is
loaded at the specific address, its PT_DYNAMIC segment entries
contain the relocated values for the load address. ET_EXEC is
checked to avoid relocating them again .
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcV0tv2zgQ_jX0ZSCDpiQrPviQ-LEboMkWSNqmp4IiRxJbmhRIKnH66xeUn2nzbBc9LCH4Ic588w05-sTh3qvaIE5Jfkby-YB3obFu2nzVSbBW-0Fp5f30KvCgBLw_X8CdCg0Ya5Lv6CxoyyVwKR16D8obwooAK-6-oQTuYXH9ZXGzmJH0lNA5oadkTLfX5m9-1nzVJKO16RJR6SSFsGpJPicsA8EDrIdia8lSZYTuJAJJZz5IZYcNSRfb2f5TmbD5seLKAGEnhE2288XZ5gdA65QJ1WaWNai1JfnMEMaicbo3cxg6Z4Dub5Fi_grOtRCQVHGZEt8vWdIqhOSTJmyWJGrFa0xK7pGkc7rOKaU0pghJ1XlMtCTpXGv5ijgOuURdQdIAH9ouwMZn8W4Jf8cpt19xgAteK0HSUwAoKshyyARkY6AM6Ki_6JPXDmKmufcbiKfH4t1ynO085jzw6MAIKzwIu2o1rtAEwmagVQgaAY1U3OwcPqLzyproM4q7IzrnevvJzuKfK8KWp2fnL_D4cHl-Awlc3fuAK_i48z49Oz-O8figO-vr-xaj2fzzZSTz3noVlDXJuZHYopFoAizWKLrAS41QKY1HTC-4aJTpAU7lLTcCJVwo4SzM8VYJ9HBzMk4Oi3XEi65Hu7sLE9w9tFaZsHvCfmZO10WVZ3veV4G7ALaC1tna8RU0fTU8dBxnMafyPqAHZYL9kf4exKOIWR-DFJNJWoy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