@@ -899,14 +899,14 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
899
899
const auto emachine = config->emachine ;
900
900
const bool isDebug = isDebugSection (*this );
901
901
const bool isDebugLine = isDebug && name == " .debug_line" ;
902
- std::optional<uint64_t > tombstone, debugTombstone ;
902
+ std::optional<uint64_t > tombstone;
903
903
if (isDebug) {
904
904
if (name == " .debug_loc" || name == " .debug_ranges" )
905
- debugTombstone = 1 ;
905
+ tombstone = 1 ;
906
906
else if (name == " .debug_names" )
907
- debugTombstone = UINT64_MAX; // DWARF Issue 231013.1
907
+ tombstone = UINT64_MAX; // tombstone value
908
908
else
909
- debugTombstone = 0 ;
909
+ tombstone = 0 ;
910
910
}
911
911
for (const auto &patAndValue : llvm::reverse (config->deadRelocInNonAlloc ))
912
912
if (patAndValue.first .match (this ->name )) {
@@ -960,7 +960,7 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
960
960
return ;
961
961
}
962
962
963
- if (tombstone || (isDebug && (expr == R_ABS || expr == R_DTPREL) )) {
963
+ if (tombstone && (expr == R_ABS || expr == R_DTPREL)) {
964
964
// Resolve relocations in .debug_* referencing (discarded symbols or ICF
965
965
// folded section symbols) to a tombstone value. Resolving to addend is
966
966
// unsatisfactory because the result address range may collide with a
@@ -991,13 +991,13 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
991
991
// value. Enable -1 in a future release.
992
992
if (!sym.getOutputSection () || (ds && ds->folded && !isDebugLine)) {
993
993
// 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 );
1001
1001
target.relocateNoSym (bufLoc, type, value);
1002
1002
continue ;
1003
1003
}
0 commit comments