[PATCH] D26888: [ELF] - Implemented -N.
Ed Maste via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 28 15:59:33 PST 2016
emaste accepted this revision.
emaste added a comment.
This gives me a working hello world and reasonable looking phdr:
% cat hello_data.c
#include <stdio.h>
int bss_var;
int data_var = 3;
int
main(int argc, char *argv[])
{
printf("hello bss %d data %d\n", bss_var, data_var);
return 0;
}
% cc -fuse-ld=lld -Wl,-N,-z,norelro hello_data.c
% ./a.out
hello bss 0 data 3
% readelf -l a.out
Elf file type is EXEC (Executable file)
Entry point 0x2004d0
There are 7 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000200040 0x0000000000200040
0x0000000000000188 0x0000000000000188 R 8
INTERP 0x00000000000001c8 0x00000000002001c8 0x00000000002001c8
0x0000000000000015 0x0000000000000015 R 1
[Requesting program interpreter: /libexec/ld-elf.so.1]
LOAD 0x0000000000000000 0x0000000000200000 0x0000000000200000
0x00000000000009c0 0x00000000000009cc RWE 1000
DYNAMIC 0x0000000000000868 0x0000000000200868 0x0000000000200868
0x0000000000000120 0x0000000000000120 RW 8
GNU_EH_FRAME 0x00000000000004a0 0x00000000002004a0 0x00000000002004a0
0x0000000000000024 0x0000000000000024 R 1
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RW 0
NOTE 0x00000000000001e0 0x00000000002001e0 0x00000000002001e0
0x0000000000000030 0x0000000000000030 R 4
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .note.tag .rodata .dynsym .gnu.version .gnu.version_r .gnu.hash .hash .dynstr .eh_frame .rela.plt .eh_frame_hdr .text .init .fini .plt .data .ctors .dtors .jcr .dynamic .got.plt .bss
03 .dynamic
04 .eh_frame_hdr
05
06 .note.tag
The RO `GNU_EH_FRAME` may cause trouble in some applications, but FreeBSD's rtld didn't seem to care (and I don't think it should matter for the actual expected use cases for -N).
I did have to use -z norelro though: maybe we should fail if -N is used with relro or force norelro? It's arguable that relro is fundamentally incompatible with -N. Either way, I think this patch should go in as is first.
================
Comment at: ELF/Options.td:165
+def omagic: F<"omagic">, MetaVarName<"<magic>">,
+ HelpText<"Set the text and data sections to be readable and writable">;
+
----------------
Maybe "Combine text and data into one readable and writable segment"? We should definitely refer to segment here not section because the shdr still has .text .data .bss with different perms.
https://reviews.llvm.org/D26888
More information about the llvm-commits
mailing list