Merge duplicate code. NFC.
llvm-svn: 272032
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index 562c971..b8db6f5 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -75,6 +75,11 @@
error("improper alignment for relocation " + S);
}
+static void warnDynRel(uint32_t Type) {
+ error("relocation " + getELFRelocationTypeName(Config->EMachine, Type) +
+ " cannot be used when making a shared object; recompile with -fPIC.");
+}
+
namespace {
class X86TargetInfo final : public TargetInfo {
public:
@@ -1195,10 +1200,8 @@
uint32_t AArch64TargetInfo::getDynRel(uint32_t Type) const {
if (Type == R_AARCH64_ABS32 || Type == R_AARCH64_ABS64)
return Type;
- StringRef S = getELFRelocationTypeName(EM_AARCH64, Type);
- error("relocation " + S + " cannot be used when making a shared object; "
- "recompile with -fPIC.");
// Keep it going with a dummy value so that we can find more reloc errors.
+ warnDynRel(Type);
return R_AARCH64_ABS32;
}
@@ -1487,10 +1490,8 @@
uint32_t ARMTargetInfo::getDynRel(uint32_t Type) const {
if (Type == R_ARM_ABS32)
return Type;
- StringRef S = getELFRelocationTypeName(EM_ARM, Type);
- error("relocation " + S + " cannot be used when making a shared object; "
- "recompile with -fPIC.");
// Keep it going with a dummy value so that we can find more reloc errors.
+ warnDynRel(Type);
return R_ARM_ABS32;
}
@@ -1664,10 +1665,8 @@
uint32_t MipsTargetInfo<ELFT>::getDynRel(uint32_t Type) const {
if (Type == R_MIPS_32 || Type == R_MIPS_64)
return RelativeRel;
- StringRef S = getELFRelocationTypeName(EM_MIPS, Type);
- error("relocation " + S + " cannot be used when making a shared object; "
- "recompile with -fPIC.");
// Keep it going with a dummy value so that we can find more reloc errors.
+ warnDynRel(Type);
return R_MIPS_32;
}