-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[LLD] Tombstone LocalTU entry in .debug_names #70701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
d2665cc
792155d
854a281
b716d70
19fa33e
a69878b
8e5c0b7
be18f4f
e25f409
03afbda
036dbef
1dfdf18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,6 @@ | |
#include "llvm/Support/Compression.h" | ||
#include "llvm/Support/Endian.h" | ||
#include "llvm/Support/xxhash.h" | ||
#include <algorithm> | ||
#include <mutex> | ||
#include <vector> | ||
|
||
using namespace llvm; | ||
|
@@ -886,8 +884,7 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) { | |
const unsigned bits = sizeof(typename ELFT::uint) * 8; | ||
const TargetInfo &target = *elf::target; | ||
const bool isDebug = isDebugSection(*this); | ||
const bool isDebugLocOrRanges = | ||
isDebug && (name == ".debug_loc" || name == ".debug_ranges"); | ||
const bool isDebugNames = isDebug && name == ".debug_names"; | ||
const bool isDebugLine = isDebug && name == ".debug_line"; | ||
std::optional<uint64_t> tombstone; | ||
for (const auto &patAndValue : llvm::reverse(config->deadRelocInNonAlloc)) | ||
|
@@ -896,6 +893,16 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) { | |
break; | ||
} | ||
|
||
const uint64_t debugTombstone = StringSwitch<uint64_t>(name) | ||
.Case(".debug_ranges", 1) | ||
.Case(".debug_loc", 1) | ||
.Case(".debug_names", llvm::maxUIntN(32)) | ||
.Default(0); | ||
// If -z dead-reloc-in-nonalloc= is specified, respect it. | ||
if (!tombstone && isDebug) | ||
tombstone = debugTombstone; | ||
else if (tombstone) | ||
tombstone = SignExtend64<bits>(*tombstone); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this is sign extended to 64 bits, but then we have a 32 bit relocation, I'd expect this fails/errors out? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is the same as original logic. It would go into if condition if tombstone is specified, and always extend.
|
||
for (const RelTy &rel : rels) { | ||
RelType type = rel.getType(config->isMips64EL); | ||
|
||
|
@@ -917,8 +924,7 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) { | |
if (expr == R_NONE) | ||
continue; | ||
|
||
if (tombstone || | ||
(isDebug && (type == target.symbolicRel || expr == R_DTPREL))) { | ||
if (tombstone) { | ||
// Resolve relocations in .debug_* referencing (discarded symbols or ICF | ||
// folded section symbols) to a tombstone value. Resolving to addend is | ||
// unsatisfactory because the result address range may collide with a | ||
|
@@ -947,12 +953,14 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) { | |
// | ||
// TODO To reduce disruption, we use 0 instead of -1 as the tombstone | ||
// value. Enable -1 in a future release. | ||
|
||
// Extend to 64bit MAX for 64 bit relocations, LocalTU, in .debug_names. | ||
if (isDebugNames && type == target.symbolicRel) | ||
tombstone = SignExtend64<32>(*tombstone); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this only handles one case of 64 bit relocations, but there might be others? & I'm not sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, made it more generic. |
||
|
||
auto *ds = dyn_cast<Defined>(&sym); | ||
if (!sym.getOutputSection() || (ds && ds->folded && !isDebugLine)) { | ||
// If -z dead-reloc-in-nonalloc= is specified, respect it. | ||
const uint64_t value = tombstone ? SignExtend64<bits>(*tombstone) | ||
: (isDebugLocOrRanges ? 1 : 0); | ||
target.relocateNoSym(bufLoc, type, value); | ||
target.relocateNoSym(bufLoc, type, *tombstone); | ||
continue; | ||
} | ||
} | ||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// REQUIRES: x86 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should place the DWARF64 test into the other file. |
||
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/dwarf5-64-debug-names-type-comdat-main.s -o %t.o | ||
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/dwarf5-64-debug-names-type-comdat-helper.s -o %t1.o | ||
// RUN: ld.lld %t.o %t1.o -o %t1 | ||
// RUN: llvm-readelf --relocs %t.o | FileCheck --check-prefix=RELOCMAIN %s | ||
// RUN: llvm-dwarfdump --debug-names %t1 | FileCheck %s | ||
|
||
// Test checks that LLD tombstones TU section that was de-duplicated using COMDAT to the maxium value. | ||
// For some reason llvm-dwarfdump doesn't print out full 64bitt offset at the moment. | ||
// Working around it by checking that relocation is 64 bit. | ||
|
||
// RELOCMAIN: rela.debug_names | ||
// RELOCMAIN-NEXT: Offset | ||
// RELOCMAIN-NEXT: R_X86_64_64 | ||
// RELOCMAIN-SAME: .debug_info + 0 | ||
// RELOCMAIN-NEXT: R_X86_64_64 | ||
// RELOCMAIN-SAME: .debug_info + 0 | ||
|
||
// CHECK: LocalTU[0]: 0x00000000 | ||
// CHECK: LocalTU[0]: 0xffffffffffffffff |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// REQUIRES: x86 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In newer tests we make the comment (non-RUN non-CHECK) marker outstanding. We typically use |
||
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/dwarf5-debug-names-type-comdat-main.s -o %t.o | ||
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/dwarf5-debug-names-type-comdat-helper.s -o %t1.o | ||
// RUN: ld.lld %t.o %t1.o -o %t1 | ||
// RUN: llvm-dwarfdump --debug-names %t1 | FileCheck %s | ||
|
||
// Test checks that LLD tombstones TU section that was de-duplicated using COMDAT to the maxium value. | ||
|
||
// CHECK: LocalTU[0]: 0x00000000 | ||
// CHECK: LocalTU[0]: 0xffffffff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep the headers. mutex is used by std::mutex in this file.