Skip to content

Commit 004be40

Browse files
committed
[ELF] Change tombstone values to (.debug_ranges/.debug_loc) 1 and (other .debug_*) 0
tl;dr See D81784 for the 'tombstone value' concept. This patch changes our behavior to be almost the same as GNU ld (except that we also use 1 for .debug_loc): * .debug_ranges & .debug_loc: 1 (LLD<11: 0+addend; GNU ld uses 1 for .debug_ranges) * .debug_*: 0 (LLD<11: 0+addend; GNU ld uses 0; future LLD: -1) We make the tweaks because: 1) The new tombstone is novel and needs more time to be adopted by consumers before it's the default. 2) The old (gold) strategy had problems with zero-length functions - so rather than going back that, we're going to the GNU ld strategy which doesn't have that problem. 3) One slight tweak to (2) is to apply the .debug_ranges workaround to .debug_loc for the same reasons it applies to debug_ranges - to avoid terminating lists early. ----- http://lists.llvm.org/pipermail/llvm-dev/2020-July/143482.html The tombstone value -1 in .debug_line caused problems to lldb (fixed by D83957; will be included in 11.0.0) and breakpad (fixed by https://crrev.com/c/2321300). It may potentially affects other DWARF consumers. For .debug_ranges & .debug_loc: 1, an argument preferring 1 (GNU ld for .debug_ranges) over -2 is that: ``` {-1, -2} <<< base address selection entry {0, length} <<< address range ``` may create a situation where low_pc is greater than high_pc. So we use 1, the GNU ld behavior for .debug_ranges For other .debug_* sections, there haven't been many reports. One issue is that bloaty (src/dwarf.cc) can incorrectly count address ranges in .debug_ranges . To reduce similar disruption, this patch changes the tombstone values to be similar to GNU ld. This does mean another behavior change to the default trunk behavior. Sorry about it. The default trunk behavior will be similar to release/11.x while we work on a transition plan for LLD users. Reviewed By: dblaikie, echristo Differential Revision: https://reviews.llvm.org/D84825
1 parent c50f5de commit 004be40

File tree

7 files changed

+23
-20
lines changed

7 files changed

+23
-20
lines changed

lld/ELF/InputSection.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -945,14 +945,17 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
945945
// the folded-in function, so exclude .debug_line.
946946
//
947947
// For pre-DWARF-v5 .debug_loc and .debug_ranges, -1 is a reserved value
948-
// (base address selection entry), so -2 is used.
948+
// (base address selection entry), use 1 (which is used by GNU ld for
949+
// .debug_ranges).
950+
//
951+
// TODO To reduce disruption, we use 0 instead of -1 as the tombstone
952+
// value. Enable -1 in a future release.
949953
auto *ds = dyn_cast<Defined>(&sym);
950954
if (!sym.getOutputSection() ||
951955
(ds && ds->section->repl != ds->section && !isDebugLine)) {
952956
// If -z dead-reloc-in-nonalloc= is specified, respect it.
953-
const uint64_t value =
954-
tombstone ? SignExtend64<bits>(*tombstone)
955-
: (isDebugLocOrRanges ? UINT64_MAX - 1 : UINT64_MAX);
957+
const uint64_t value = tombstone ? SignExtend64<bits>(*tombstone)
958+
: (isDebugLocOrRanges ? 1 : 0);
956959
target->relocateNoSym(bufLoc, type, value);
957960
continue;
958961
}

lld/test/ELF/dead-reloc-in-nonalloc.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# RUN: -z dead-reloc-in-nonalloc=.not_debug=0xbbbbbbbb %t.o -o - | cmp %t -
1212

1313
# COMMON: Contents of section .debug_addr:
14-
# COMMON-NEXT: 0000 [[ADDR:[0-9a-f]+]] 00000000 ffffffff ffffffff
14+
# COMMON-NEXT: 0000 [[ADDR:[0-9a-f]+]] 00000000 00000000 00000000
1515

1616
# AA: Contents of section .debug_info:
1717
# AA-NEXT: 0000 [[ADDR]] 00000000 aaaaaaaa 00000000

lld/test/ELF/debug-dead-reloc-32.s

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# RUN: llvm-objdump -s %t | FileCheck %s
99

1010
# CHECK: Contents of section .debug_loc:
11-
# CHECK-NEXT: 0000 feffffff
11+
# CHECK-NEXT: 0000 01000000
1212
# CHECK-NEXT: Contents of section .debug_ranges:
13-
# CHECK-NEXT: 0000 feffffff
13+
# CHECK-NEXT: 0000 01000000
1414
# CHECK-NEXT: Contents of section .debug_addr:
15-
# CHECK-NEXT: 0000 ffffffff
15+
# CHECK-NEXT: 0000 00000000
1616

1717
.section .text.1,"axe"
1818
.byte 0
@@ -24,6 +24,6 @@
2424
.section .debug_ranges
2525
.long .text.1+16
2626

27-
## Resolved to UINT32_C(-1), with the addend ignored.
27+
## Resolved to UINT32_C(0), with the addend ignored.
2828
.section .debug_addr
2929
.long .text.1+8

lld/test/ELF/debug-dead-reloc-icf.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# RUN: llvm-objdump -s %t | FileCheck %s
1010

1111
# CHECK: Contents of section .debug_info:
12-
# CHECK-NEXT: 0000 {{[0-9a-f]+}}000 00000000 ffffffff ffffffff
12+
# CHECK-NEXT: 0000 {{[0-9a-f]+}}000 00000000 00000000 00000000
1313
# CHECK: Contents of section .debug_line:
1414
# CHECK-NEXT: 0000 [[ADDR:[0-9a-f]+]] 00000000
1515
# CHECK-SAME: [[ADDR]] 00000000

lld/test/ELF/debug-dead-reloc-tls-arm.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# RUN: llvm-objdump -s %t | FileCheck %s
88

99
# CHECK: Contents of section .debug_info:
10-
# CHECK-NEXT: 0000 ffffffff
10+
# CHECK-NEXT: 0000 00000000
1111

1212
.globl _start
1313
_start:

lld/test/ELF/debug-dead-reloc-tls.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
# RUN: llvm-objdump -s %t | FileCheck %s
88

99
# CHECK: Contents of section .debug_info:
10-
# CHECK-NEXT: 0000 ffffffff ffffffff ffffffff ffffffff
11-
# CHECK-NEXT: 0010 ffffffff ffffffff
10+
# CHECK-NEXT: 0000 00000000 00000000 00000000 00000000
11+
# CHECK-NEXT: 0010 00000000 ffffffff
1212

1313
.globl _start
1414
_start:

lld/test/ELF/debug-dead-reloc.s

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
# RUN: llvm-objdump -s %t | FileCheck %s
1010

1111
# CHECK: Contents of section .debug_loc:
12-
# CHECK-NEXT: 0000 feffffff ffffffff feffffff ffffffff
12+
# CHECK-NEXT: 0000 01000000 00000000 01000000 00000000
1313
# CHECK-NEXT: Contents of section .debug_ranges:
14-
# CHECK-NEXT: 0000 feffffff ffffffff feffffff ffffffff
14+
# CHECK-NEXT: 0000 01000000 00000000 01000000 00000000
1515
# CHECK-NEXT: Contents of section .debug_addr:
1616
# CHECK-NEXT: 0000 {{.*}}000 00000000 {{.*}}000 00000000
17-
# CHECK-NEXT: 0010 ffffffff ffffffff {{.*}}000 00000000
17+
# CHECK-NEXT: 0010 00000000 00000000 {{.*}}000 00000000
1818
# CHECK-NEXT: Contents of section .debug_foo:
19-
# CHECK-NEXT: 0000 ffffffff ffffffff 08000000 00000000
20-
# CHECK-NEXT: 0010 ffffffff ffffffff 08000000 00000000
19+
# CHECK-NEXT: 0000 00000000 00000000 08000000 00000000
20+
# CHECK-NEXT: 0010 00000000 00000000 08000000 00000000
2121

2222
## -z dead-reloc-in-nonalloc= can override the tombstone value.
2323
# RUN: ld.lld --gc-sections -z dead-reloc-in-nonalloc=.debug_loc=42 %t.o %t1.o %t1.o -o %t42
@@ -35,7 +35,7 @@
3535
group:
3636
.byte 0
3737

38-
## Resolved to UINT64_C(-2), with the addend ignored.
38+
## Resolved to UINT64_C(1), with the addend ignored.
3939
## UINT64_C(-1) is a reserved value (base address selection entry) which can't be used.
4040
.section .debug_loc
4141
.quad .text.1+8
@@ -44,7 +44,7 @@ group:
4444

4545
.section .debug_addr
4646
## .text.3 is a local symbol. The symbol defined in a non-prevailing group is
47-
## discarded. Resolved to UINT64_C(-1).
47+
## discarded. Resolved to UINT64_C(0).
4848
.quad .text.3+24
4949
## group is a non-local symbol. The relocation from the second %t1.o gets
5050
## resolved to the prevailing copy.

0 commit comments

Comments
 (0)