After fixing: https://bugzilla.kernel.org/show_bug.cgi?id=36372 with commit a3defbe5c337dbc6da911f8cc49ae3cc3b49b453: http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=a3defbe5c337dbc6da911f8cc49ae3cc3b49b453 Load address in PIE is ignored when address randomization is disabled: [hjl@gnu-6 pie]$ cat foo2.c #include <stdio.h> char foo[132121799]; int main () { foo[sizeof (foo) - 2] = -34; printf ("%p, %d\n", &main, foo[sizeof (foo) - 2]); return 0; } [hjl@gnu-6 pie]$ cc -fPIE -pie foo2.c -Wl,-Ttext-segment=0x6ABC55000000 [hjl@gnu-6 pie]$ readelf -lW a.out Elf file type is DYN (Shared object file) Entry point 0x6abc55000630 There are 8 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align PHDR 0x000040 0x00006abc55000040 0x00006abc55000040 0x0001c0 0x0001c0 R E 0x8 INTERP 0x000200 0x00006abc55000200 0x00006abc55000200 0x00001c 0x00001c R 0x1 [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] LOAD 0x000000 0x00006abc55000000 0x00006abc55000000 0x000944 0x000944 R E 0x200000 LOAD 0x001000 0x00006abc55201000 0x00006abc55201000 0x000254 0x7e00748 RW 0x200000 DYNAMIC 0x001020 0x00006abc55201020 0x00006abc55201020 0x0001d0 0x0001d0 RW 0x8 NOTE 0x00021c 0x00006abc5500021c 0x00006abc5500021c 0x000044 0x000044 R 0x4 GNU_EH_FRAME 0x00081c 0x00006abc5500081c 0x00006abc5500081c 0x000034 0x000034 R 0x4 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10 Section to Segment mapping: Segment Sections... 00 01 .interp 02 .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame 03 .init_array .fini_array .jcr .data.rel.ro .dynamic .got .got.plt .data .bss 04 .dynamic 05 .note.ABI-tag .note.gnu.build-id 06 .eh_frame_hdr 07 [hjl@gnu-6 pie]$ cat /proc/sys/kernel/randomize_va_space 1 [hjl@gnu-6 pie]$ ./a.out 0x6abc55000745, -34 [hjl@gnu-6 pie]$ cat /proc/sys/kernel/randomize_va_space 0 [hjl@gnu-6 pie]$ ./a.out 0x555555554745, -34 [hjl@gnu-6 pie]$
Created attachment 117741 [details] A patch to honor non-zero load addres in PIE
Any hope with this?
I checked a workaround in ld: commit 58e7ebacdd97c858834c07c7dce098aeacd500fb Author: H.J. Lu <hjl.tools@gmail.com> Date: Thu Dec 12 07:41:27 2013 -0800 Set ET_EXEC for -pie -Ttext-segment= bfd/ * elf.c (assign_file_positions_except_relocs): Set e_type in ELF header to ET_EXEC for -pie -Ttext-segment=. 2013-12-10 H.J. Lu <hongjiu.lu@intel.com> * ld-pie/vaddr-0.d: New file. * ld-pie/vaddr-1.d: Likewise. * ld-pie/vaddr.s: Likewise.