Skip to content

Commit 834457a

Browse files
committed
[ELF] Simplify relocateNonAlloc diagnostic
1 parent a6140af commit 834457a

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

lld/ELF/InputSection.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,14 +1104,6 @@ void InputSection::relocateNonAlloc(Ctx &ctx, uint8_t *buf,
11041104
continue;
11051105
}
11061106

1107-
std::string msg = getLocation(offset) + ": has non-ABS relocation " +
1108-
toStr(ctx, type) + " against symbol '" + toStr(ctx, sym) +
1109-
"'";
1110-
if (expr != R_PC && !(emachine == EM_386 && type == R_386_GOTPC)) {
1111-
Err(ctx) << msg;
1112-
return;
1113-
}
1114-
11151107
// If the control reaches here, we found a PC-relative relocation in a
11161108
// non-ALLOC section. Since non-ALLOC section is not loaded into memory
11171109
// at runtime, the notion of PC-relative doesn't make sense here. So,
@@ -1124,10 +1116,14 @@ void InputSection::relocateNonAlloc(Ctx &ctx, uint8_t *buf,
11241116
// against _GLOBAL_OFFSET_TABLE_ for .debug_info. The bug has been fixed in
11251117
// 2017 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82630), but we need to
11261118
// keep this bug-compatible code for a while.
1127-
Warn(ctx) << msg;
1128-
target.relocateNoSym(
1129-
bufLoc, type,
1130-
SignExtend64<bits>(sym.getVA(ctx, addend - offset - outSecOff)));
1119+
bool isErr = expr != R_PC && !(emachine == EM_386 && type == R_386_GOTPC);
1120+
auto diag = isErr ? Err(ctx) : Warn(ctx);
1121+
diag << getLocation(offset) << ": has non-ABS relocation " << type
1122+
<< " against symbol '" << &sym << "'";
1123+
if (!isErr)
1124+
target.relocateNoSym(
1125+
bufLoc, type,
1126+
SignExtend64<bits>(sym.getVA(ctx, addend - offset - outSecOff)));
11311127
}
11321128
}
11331129

0 commit comments

Comments
 (0)