Skip to content

Commit

Permalink
Add debugger rendezvous DT_DEBUG .dynamic entry
Browse files Browse the repository at this point in the history
The runtime linker may store a pointer to a data structure used by
debuggers.

Differential Revision:	http://reviews.llvm.org/D15775

llvm-svn: 256942
  • Loading branch information
emaste committed Jan 6, 2016
1 parent 35e7b1a commit f5d3cf6
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 56 deletions.
5 changes: 5 additions & 0 deletions lld/ELF/OutputSections.cpp
Expand Up @@ -639,6 +639,9 @@ template <class ELFT> void DynamicSection<ELFT>::finalize() {
if (DtFlags1)
++NumEntries; // DT_FLAGS_1

if (!Config->Entry.empty())
++NumEntries; // DT_DEBUG

if (Config->EMachine == EM_MIPS) {
++NumEntries; // DT_MIPS_RLD_VERSION
++NumEntries; // DT_MIPS_FLAGS
Expand Down Expand Up @@ -737,6 +740,8 @@ template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) {
WriteVal(DT_FLAGS, DtFlags);
if (DtFlags1)
WriteVal(DT_FLAGS_1, DtFlags1);
if (!Config->Entry.empty())
WriteVal(DT_DEBUG, 0);

// See "Dynamic Section" in Chapter 5 in the following document
// for detailed description:
Expand Down
1 change: 1 addition & 0 deletions lld/test/ELF/dynamic-reloc.s
Expand Up @@ -53,6 +53,7 @@
// CHECK-NEXT: 0x000000000000000A STRSZ
// CHECK-NEXT: 0x0000000000000004 HASH
// CHECK-NEXT: 0x0000000000000001 NEEDED SharedLibrary ({{.*}}2.so)
// CHECK-NEXT: 0x0000000000000015 DEBUG 0x0
// CHECK-NEXT: 0x0000000000000000 NULL 0x0
// CHECK-NEXT: ]

Expand Down
18 changes: 9 additions & 9 deletions lld/test/ELF/got.s
Expand Up @@ -12,7 +12,7 @@
// CHECK-NEXT: SHF_ALLOC
// CHECK-NEXT: SHF_WRITE
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x120A0
// CHECK-NEXT: Address: 0x120B0
// CHECK-NEXT: Offset:
// CHECK-NEXT: Size: 16
// CHECK-NEXT: Link: 0
Expand All @@ -21,22 +21,22 @@

// CHECK: Relocations [
// CHECK-NEXT: Section ({{.*}}) .rela.dyn {
// CHECK-NEXT: 0x120A0 R_X86_64_GLOB_DAT bar 0x0
// CHECK-NEXT: 0x120A8 R_X86_64_GLOB_DAT zed 0x0
// CHECK-NEXT: 0x120B0 R_X86_64_GLOB_DAT bar 0x0
// CHECK-NEXT: 0x120B8 R_X86_64_GLOB_DAT zed 0x0
// CHECK-NEXT: }
// CHECK-NEXT: ]


// Unfortunately FileCheck can't do math, so we have to check for explicit
// values:
// 0x120A0 - (0x11000 + 2) - 4 = 4250
// 0x120A0 - (0x11006 + 2) - 4 = 4244
// 0x120A8 - (0x1100c + 2) - 4 = 4246
// 0x120B0 - (0x11000 + 2) - 4 = 4266
// 0x120B0 - (0x11006 + 2) - 4 = 4260
// 0x120A8 - (0x1100c + 2) - 4 = 4262

// DISASM: _start:
// DISASM-NEXT: 11000: {{.*}} jmpq *4250(%rip)
// DISASM-NEXT: 11006: {{.*}} jmpq *4244(%rip)
// DISASM-NEXT: 1100c: {{.*}} jmpq *4246(%rip)
// DISASM-NEXT: 11000: {{.*}} jmpq *4266(%rip)
// DISASM-NEXT: 11006: {{.*}} jmpq *4260(%rip)
// DISASM-NEXT: 1100c: {{.*}} jmpq *4262(%rip)

.global _start
_start:
Expand Down
12 changes: 6 additions & 6 deletions lld/test/ELF/local-got.s
Expand Up @@ -14,11 +14,11 @@ _start:
foo:
nop

// 0x120A0 - 0x11000 - 5 = 4251
// 0x120A8 - 0x11005 - 5 = 4254
// 0x120B0 - 0x11000 - 5 = 4251
// 0x120B8 - 0x11005 - 5 = 4254
// DISASM: _start:
// DISASM-NEXT: 11000: {{.*}} callq 4251
// DISASM-NEXT: 11005: {{.*}} callq 4254
// DISASM-NEXT: 11000: {{.*}} callq 4267
// DISASM-NEXT: 11005: {{.*}} callq 4270

// DISASM: foo:
// DISASM-NEXT: 1100a: {{.*}} nop
Expand All @@ -29,7 +29,7 @@ foo:
// CHECK-NEXT: SHF_ALLOC
// CHECK-NEXT: SHF_WRITE
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x120A0
// CHECK-NEXT: Address: 0x120B0
// CHECK-NEXT: Offset:
// CHECK-NEXT: Size: 16
// CHECK-NEXT: Link: 0
Expand All @@ -43,6 +43,6 @@ foo:

// CHECK: Relocations [
// CHECK-NEXT: Section ({{.*}}) .rela.dyn {
// CHECK-NEXT: 0x120A0 R_X86_64_GLOB_DAT bar 0x0
// CHECK-NEXT: 0x120B0 R_X86_64_GLOB_DAT bar 0x0
// CHECK-NEXT: }
// CHECK-NEXT: ]
4 changes: 2 additions & 2 deletions lld/test/ELF/relocation-i686.s
Expand Up @@ -55,7 +55,7 @@ movl bar@GOT, %eax
// ADDR-NEXT: SHF_ALLOC
// ADDR-NEXT: SHF_WRITE
// ADDR-NEXT: ]
// ADDR-NEXT: Address: 0x12070
// ADDR-NEXT: Address: 0x12078

.section .R_386_GOTPC,"ax",@progbits
R_386_GOTPC:
Expand All @@ -65,7 +65,7 @@ R_386_GOTPC:

// CHECK: Disassembly of section .R_386_GOTPC:
// CHECK-NEXT: R_386_GOTPC:
// CHECK-NEXT: 11014: {{.*}} movl $4188, %eax
// CHECK-NEXT: 11014: {{.*}} movl $4196, %eax

.section .dynamic_reloc, "ax",@progbits
call bar
Expand Down
6 changes: 3 additions & 3 deletions lld/test/ELF/relocation.s
Expand Up @@ -22,7 +22,7 @@
// SEC-NEXT: SHF_ALLOC
// SEC-NEXT: SHF_WRITE
// SEC-NEXT: ]
// SEC-NEXT: Address: 0x120E0
// SEC-NEXT: Address: 0x120F0
// SEC-NEXT: Offset:
// SEC-NEXT: Size: 8
// SEC-NEXT: Link: 0
Expand Down Expand Up @@ -111,7 +111,7 @@ R_X86_64_64:
R_X86_64_GOTPCREL:
.long zed@gotpcrel

// 0x120E8 - 0x101D8 = 7952
// 0x120F8 - 0x101D8 = 7952
// 7952 = 0x101f0000 in little endian
// CHECK: Contents of section .R_X86_64_GOTPCREL
// CHECK-NEXT: 101d0 101f0000
// CHECK-NEXT: 101d0 201f0000
20 changes: 10 additions & 10 deletions lld/test/ELF/relro.s
Expand Up @@ -17,8 +17,8 @@
// FULLRELRO-NEXT: SHF_ALLOC
// FULLRELRO-NEXT: SHF_WRITE
// FULLRELRO-NEXT: ]
// FULLRELRO-NEXT: Address: 0x12100
// FULLRELRO-NEXT: Offset: 0x2100
// FULLRELRO-NEXT: Address: 0x12110
// FULLRELRO-NEXT: Offset: 0x2110
// FULLRELRO-NEXT: Size: 8
// FULLRELRO-NEXT: Link: 0
// FULLRELRO-NEXT: Info: 0
Expand All @@ -36,8 +36,8 @@
// FULLRELRO-NEXT: SHF_ALLOC
// FULLRELRO-NEXT: SHF_WRITE
// FULLRELRO-NEXT: ]
// FULLRELRO-NEXT: Address: 0x12108
// FULLRELRO-NEXT: Offset: 0x2108
// FULLRELRO-NEXT: Address: 0x12118
// FULLRELRO-NEXT: Offset: 0x2118
// FULLRELRO-NEXT: Size: 32
// FULLRELRO-NEXT: Link: 0
// FULLRELRO-NEXT: Info: 0
Expand Down Expand Up @@ -103,8 +103,8 @@
// FULLRELRO-NEXT: Offset: 0x
// FULLRELRO-NEXT: VirtualAddress: [[RWADDR]]
// FULLRELRO-NEXT: PhysicalAddress:
// FULLRELRO-NEXT: FileSize: 296
// FULLRELRO-NEXT: MemSize: 296
// FULLRELRO-NEXT: FileSize: 312
// FULLRELRO-NEXT: MemSize: 312
// FULLRELRO-NEXT: Flags [
// FULLRELRO-NEXT: PF_R
// FULLRELRO-NEXT: ]
Expand All @@ -119,8 +119,8 @@
// PARTRELRO-NEXT: SHF_ALLOC
// PARTRELRO-NEXT: SHF_WRITE
// PARTRELRO-NEXT: ]
// PARTRELRO-NEXT: Address: 0x120E0
// PARTRELRO-NEXT: Offset: 0x20E0
// PARTRELRO-NEXT: Address: 0x120F0
// PARTRELRO-NEXT: Offset: 0x20F0
// PARTRELRO-NEXT: Size: 8
// PARTRELRO-NEXT: Link: 0
// PARTRELRO-NEXT: Info: 0
Expand Down Expand Up @@ -219,8 +219,8 @@
// PARTRELRO-NEXT: Offset: 0x2000
// PARTRELRO-NEXT: VirtualAddress: [[RWADDR]]
// PARTRELRO-NEXT: PhysicalAddress:
// PARTRELRO-NEXT: FileSize: 232
// PARTRELRO-NEXT: MemSize: 232
// PARTRELRO-NEXT: FileSize: 248
// PARTRELRO-NEXT: MemSize: 248
// PARTRELRO-NEXT: Flags [
// PARTRELRO-NEXT: PF_R
// PARTRELRO-NEXT: ]
Expand Down
1 change: 1 addition & 0 deletions lld/test/ELF/shared-be.s
Expand Up @@ -25,6 +25,7 @@
// CHECK-NEXT: 0x0000000000000009 RELAENT [[RELENT]] (bytes)
// CHECK: 0x000000000000001D RUNPATH foo:bar
// CHECK-NEXT: 0x0000000000000001 NEEDED SharedLibrary ({{.*}}2.so)
// CHECK-NEXT: 0x0000000000000015 DEBUG 0x0
// CHECK-NEXT: 0x0000000000000000 NULL 0x0
// CHECK-NEXT: ]

Expand Down
1 change: 1 addition & 0 deletions lld/test/ELF/shared.s
Expand Up @@ -253,6 +253,7 @@
// CHECK-NEXT: 0x00000004 HASH [[HASHADDR]]
// CHECK-NEXT: 0x0000001D RUNPATH foo:bar
// CHECK-NEXT: 0x00000001 NEEDED SharedLibrary ({{.*}}2.so)
// CHECK-NEXT: 0x00000015 DEBUG 0x0
// CHECK-NEXT: 0x00000000 NULL 0x0
// CHECK-NEXT: ]

Expand Down
16 changes: 8 additions & 8 deletions lld/test/ELF/tls-got.s
Expand Up @@ -14,7 +14,7 @@
// CHECK-NEXT: SHF_WRITE
// CHECK-NEXT: ]
// CHECK-NEXT: Address: [[ADDR:.*]]
// CHECK-NEXT: Offset: 0x20A0
// CHECK-NEXT: Offset: 0x20B0
// CHECK-NEXT: Size: 16
// CHECK-NEXT: Link: 0
// CHECK-NEXT: Info: 0
Expand All @@ -25,20 +25,20 @@
// CHECK: Relocations [
// CHECK-NEXT: Section (4) .rela.dyn {
// CHECK-NEXT: [[ADDR]] R_X86_64_TPOFF64 tls1 0x0
// CHECK-NEXT: 0x120A8 R_X86_64_TPOFF64 tls0 0x0
// CHECK-NEXT: 0x120B8 R_X86_64_TPOFF64 tls0 0x0
// CHECK-NEXT: }
// CHECK-NEXT: ]

//0x11000 + 4249 + 7 = 0x120A0
//0x1100A + 4247 + 7 = 0x120A8
//0x11014 + 4237 + 7 = 0x120A8
//0x11000 + 4249 + 7 = 0x120B0
//0x1100A + 4247 + 7 = 0x120B8
//0x11014 + 4237 + 7 = 0x120B8
//DISASM: Disassembly of section .text:
//DISASM-NEXT: main:
//DISASM-NEXT: 11000: 48 8b 05 99 10 00 00 movq 4249(%rip), %rax
//DISASM-NEXT: 11000: 48 8b 05 a9 10 00 00 movq 4265(%rip), %rax
//DISASM-NEXT: 11007: 64 8b 00 movl %fs:(%rax), %eax
//DISASM-NEXT: 1100a: 48 8b 05 97 10 00 00 movq 4247(%rip), %rax
//DISASM-NEXT: 1100a: 48 8b 05 a7 10 00 00 movq 4263(%rip), %rax
//DISASM-NEXT: 11011: 64 8b 00 movl %fs:(%rax), %eax
//DISASM-NEXT: 11014: 48 8b 05 8d 10 00 00 movq 4237(%rip), %rax
//DISASM-NEXT: 11014: 48 8b 05 9d 10 00 00 movq 4253(%rip), %rax
//DISASM-NEXT: 1101b: 64 8b 00 movl %fs:(%rax), %eax
//DISASM-NEXT: 1101e: c3 retq

Expand Down
16 changes: 8 additions & 8 deletions lld/test/ELF/tls-opt-gdie.s
Expand Up @@ -13,8 +13,8 @@
//RELOC-NEXT: SHF_ALLOC
//RELOC-NEXT: SHF_WRITE
//RELOC-NEXT: ]
//RELOC-NEXT: Address: 0x120E0
//RELOC-NEXT: Offset: 0x20E0
//RELOC-NEXT: Address: 0x120F0
//RELOC-NEXT: Offset: 0x20F0
//RELOC-NEXT: Size: 16
//RELOC-NEXT: Link: 0
//RELOC-NEXT: Info: 0
Expand All @@ -23,22 +23,22 @@
//RELOC-NEXT: }
//RELOC: Relocations [
//RELOC-NEXT: Section (4) .rela.dyn {
//RELOC-NEXT: 0x120E0 R_X86_64_TPOFF64 tlsshared0 0x0
//RELOC-NEXT: 0x120E8 R_X86_64_TPOFF64 tlsshared1 0x0
//RELOC-NEXT: 0x120F0 R_X86_64_TPOFF64 tlsshared0 0x0
//RELOC-NEXT: 0x120F8 R_X86_64_TPOFF64 tlsshared1 0x0
//RELOC-NEXT: }
//RELOC-NEXT: Section (5) .rela.plt {
//RELOC-NEXT: 0x13018 R_X86_64_JUMP_SLOT __tls_get_addr 0x0
//RELOC-NEXT: }
//RELOC-NEXT: ]

//0x11009 + (4304 + 7) = 0x120E0
//0x11019 + (4296 + 7) = 0x120E8
//0x11009 + (4304 + 7) = 0x120F0
//0x11019 + (4296 + 7) = 0x120F8
// DISASM: Disassembly of section .text:
// DISASM-NEXT: _start:
// DISASM-NEXT: 11000: 64 48 8b 04 25 00 00 00 00 movq %fs:0, %rax
// DISASM-NEXT: 11009: 48 03 05 d0 10 00 00 addq 4304(%rip), %rax
// DISASM-NEXT: 11009: 48 03 05 e0 10 00 00 addq 4320(%rip), %rax
// DISASM-NEXT: 11010: 64 48 8b 04 25 00 00 00 00 movq %fs:0, %rax
// DISASM-NEXT: 11019: 48 03 05 c8 10 00 00 addq 4296(%rip), %rax
// DISASM-NEXT: 11019: 48 03 05 d8 10 00 00 addq 4312(%rip), %rax

.section .text
.globl _start
Expand Down
4 changes: 2 additions & 2 deletions lld/test/ELF/tls-opt-gdiele-i686.s
Expand Up @@ -7,8 +7,8 @@

// NORELOC: Relocations [
// NORELOC-NEXT: Section ({{.*}}) .rel.dyn {
// NORELOC-NEXT: 0x12050 R_386_TLS_TPOFF tlsshared0 0x0
// NORELOC-NEXT: 0x12054 R_386_TLS_TPOFF tlsshared1 0x0
// NORELOC-NEXT: 0x12058 R_386_TLS_TPOFF tlsshared0 0x0
// NORELOC-NEXT: 0x1205C R_386_TLS_TPOFF tlsshared1 0x0
// NORELOC-NEXT: }
// NORELOC-NEXT: ]

Expand Down
16 changes: 8 additions & 8 deletions lld/test/ELF/tls-opt-iele-i686-nopic.s
Expand Up @@ -16,8 +16,8 @@
// GOTREL-NEXT: SHF_ALLOC
// GOTREL-NEXT: SHF_WRITE
// GOTREL-NEXT: ]
// GOTREL-NEXT: Address: 0x12050
// GOTREL-NEXT: Offset: 0x2050
// GOTREL-NEXT: Address: 0x12058
// GOTREL-NEXT: Offset: 0x2058
// GOTREL-NEXT: Size: 8
// GOTREL-NEXT: Link: 0
// GOTREL-NEXT: Info: 0
Expand All @@ -26,17 +26,17 @@
// GOTREL-NEXT: }
// GOTREL: Relocations [
// GOTREL-NEXT: Section ({{.*}}) .rel.dyn {
// GOTREL-NEXT: 0x12050 R_386_TLS_TPOFF tlsshared0 0x0
// GOTREL-NEXT: 0x12054 R_386_TLS_TPOFF tlsshared1 0x0
// GOTREL-NEXT: 0x12058 R_386_TLS_TPOFF tlsshared0 0x0
// GOTREL-NEXT: 0x1205C R_386_TLS_TPOFF tlsshared1 0x0
// GOTREL-NEXT: }
// GOTREL-NEXT: ]

// DISASM: Disassembly of section .text:
// DISASM-NEXT: _start:
// 4294967288 = 0xFFFFFFF8
// 4294967292 = 0xFFFFFFFC
// 73808 = (.got)[0] = 0x12050
// 73812 = (.got)[1] = 0x12054
// 73808 = (.got)[0] = 0x12058
// 73812 = (.got)[1] = 0x1205C
// DISASM-NEXT: 11000: c7 c1 f8 ff ff ff movl $4294967288, %ecx
// DISASM-NEXT: 11006: 65 8b 01 movl %gs:(%ecx), %eax
// DISASM-NEXT: 11009: b8 f8 ff ff ff movl $4294967288, %eax
Expand All @@ -49,9 +49,9 @@
// DISASM-NEXT: 11028: 65 8b 00 movl %gs:(%eax), %eax
// DISASM-NEXT: 1102b: 81 c1 fc ff ff ff addl $4294967292, %ecx
// DISASM-NEXT: 11031: 65 8b 01 movl %gs:(%ecx), %eax
// DISASM-NEXT: 11034: 8b 0d 50 20 01 00 movl 73808, %ecx
// DISASM-NEXT: 11034: 8b 0d 58 20 01 00 movl 73816, %ecx
// DISASM-NEXT: 1103a: 65 8b 01 movl %gs:(%ecx), %eax
// DISASM-NEXT: 1103d: 03 0d 54 20 01 00 addl 73812, %ecx
// DISASM-NEXT: 1103d: 03 0d 5c 20 01 00 addl 73820, %ecx
// DISASM-NEXT: 11043: 65 8b 01 movl %gs:(%ecx), %eax

// GOTRELSHARED: Section {
Expand Down

0 comments on commit f5d3cf6

Please sign in to comment.