Skip to content

Commit ee4a389

Browse files
committed
simplify
1 parent 4c0d6be commit ee4a389

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lld/ELF/InputSection.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -899,14 +899,14 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
899899
const auto emachine = config->emachine;
900900
const bool isDebug = isDebugSection(*this);
901901
const bool isDebugLine = isDebug && name == ".debug_line";
902-
std::optional<uint64_t> tombstone, debugTombstone;
902+
std::optional<uint64_t> tombstone;
903903
if (isDebug) {
904904
if (name == ".debug_loc" || name == ".debug_ranges")
905-
debugTombstone = 1;
905+
tombstone = 1;
906906
else if (name == ".debug_names")
907-
debugTombstone = UINT64_MAX; // DWARF Issue 231013.1
907+
tombstone = UINT64_MAX; // tombstone value
908908
else
909-
debugTombstone = 0;
909+
tombstone = 0;
910910
}
911911
for (const auto &patAndValue : llvm::reverse(config->deadRelocInNonAlloc))
912912
if (patAndValue.first.match(this->name)) {
@@ -960,7 +960,7 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
960960
return;
961961
}
962962

963-
if (tombstone || (isDebug && (expr == R_ABS || expr == R_DTPREL))) {
963+
if (tombstone && (expr == R_ABS || expr == R_DTPREL)) {
964964
// Resolve relocations in .debug_* referencing (discarded symbols or ICF
965965
// folded section symbols) to a tombstone value. Resolving to addend is
966966
// unsatisfactory because the result address range may collide with a
@@ -991,13 +991,13 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
991991
// value. Enable -1 in a future release.
992992
if (!sym.getOutputSection() || (ds && ds->folded && !isDebugLine)) {
993993
// If -z dead-reloc-in-nonalloc= is specified, respect it.
994-
uint64_t value;
995-
if (tombstone)
996-
value = SignExtend64<bits>(*tombstone);
997-
else if (type == target.symbolicRel)
998-
value = *debugTombstone;
999-
else // .debug_names uses 32-bit local TU offsets for DWARF32
1000-
value = static_cast<uint32_t>(*debugTombstone);
994+
uint64_t value = SignExtend64<bits>(*tombstone);
995+
// For a 32-bit local TU reference in .debug_names, X86_64::relocate
996+
// requires that the unsigned value for R_X86_64_32 is truncated to
997+
// 32-bit. Other 64-bit targets's don't discern signed/unsigned 32-bit
998+
// absolute relocations and do not need this change.
999+
if (emachine == EM_X86_64 && type == R_X86_64_32)
1000+
value = static_cast<uint32_t>(value);
10011001
target.relocateNoSym(bufLoc, type, value);
10021002
continue;
10031003
}

0 commit comments

Comments
 (0)