summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp')
-rw-r--r--lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp104
1 files changed, 48 insertions, 56 deletions
diff --git a/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp b/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp
index 51e2f3f719c..3286fe06453 100644
--- a/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp
+++ b/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp
@@ -76,16 +76,16 @@ public:
return -1;
}
- std::error_code getReferenceInfo(const normalized::Relocation &reloc,
- const DefinedAtom *inAtom,
- uint32_t offsetInAtom,
- uint64_t fixupAddress, bool swap,
- FindAtomBySectionAndAddress atomFromAddress,
- FindAtomBySymbolIndex atomFromSymbolIndex,
- Reference::KindValue *kind,
- const lld::Atom **target,
- Reference::Addend *addend) override;
- std::error_code
+ llvm::Error getReferenceInfo(const normalized::Relocation &reloc,
+ const DefinedAtom *inAtom,
+ uint32_t offsetInAtom,
+ uint64_t fixupAddress, bool swap,
+ FindAtomBySectionAndAddress atomFromAddress,
+ FindAtomBySymbolIndex atomFromSymbolIndex,
+ Reference::KindValue *kind,
+ const lld::Atom **target,
+ Reference::Addend *addend) override;
+ llvm::Error
getPairReferenceInfo(const normalized::Relocation &reloc1,
const normalized::Relocation &reloc2,
const DefinedAtom *inAtom,
@@ -518,13 +518,12 @@ uint32_t ArchHandler_arm::clearThumbBit(uint32_t value, const Atom *target) {
return value;
}
-std::error_code ArchHandler_arm::getReferenceInfo(
+llvm::Error ArchHandler_arm::getReferenceInfo(
const Relocation &reloc, const DefinedAtom *inAtom, uint32_t offsetInAtom,
uint64_t fixupAddress, bool isBig,
FindAtomBySectionAndAddress atomFromAddress,
FindAtomBySymbolIndex atomFromSymbolIndex, Reference::KindValue *kind,
const lld::Atom **target, Reference::Addend *addend) {
- typedef std::error_code E;
const uint8_t *fixupContent = &inAtom->rawContent()[offsetInAtom];
uint64_t targetAddress;
uint32_t instruction = *(const ulittle32_t *)fixupContent;
@@ -536,12 +535,12 @@ std::error_code ArchHandler_arm::getReferenceInfo(
*kind = thumb_b22;
else
*kind = thumb_bl22;
- if (E ec = atomFromSymbolIndex(reloc.symbol, target))
+ if (auto ec = atomFromSymbolIndex(reloc.symbol, target))
return ec;
// Instruction contains branch to addend.
displacement = getDisplacementFromThumbBranch(instruction, fixupAddress);
*addend = fixupAddress + 4 + displacement;
- return std::error_code();
+ return llvm::Error();
case ARM_THUMB_RELOC_BR22 | rPcRel | rLength4:
// ex: bl _foo (and _foo is defined)
if ((instruction & 0xD000F800) == 0x9000F000)
@@ -559,12 +558,12 @@ std::error_code ArchHandler_arm::getReferenceInfo(
*kind = thumb_bl22;
displacement = getDisplacementFromThumbBranch(instruction, fixupAddress);
targetAddress = fixupAddress + 4 + displacement;
- if (E ec = atomFromAddress(0, reloc.value, target, addend))
+ if (auto ec = atomFromAddress(0, reloc.value, target, addend))
return ec;
// reloc.value is target atom's address. Instruction contains branch
// to atom+addend.
*addend += (targetAddress - reloc.value);
- return std::error_code();
+ return llvm::Error();
case ARM_RELOC_BR24 | rPcRel | rExtern | rLength4:
// ex: bl _foo (and _foo is undefined)
if (((instruction & 0x0F000000) == 0x0A000000)
@@ -572,12 +571,12 @@ std::error_code ArchHandler_arm::getReferenceInfo(
*kind = arm_b24;
else
*kind = arm_bl24;
- if (E ec = atomFromSymbolIndex(reloc.symbol, target))
+ if (auto ec = atomFromSymbolIndex(reloc.symbol, target))
return ec;
// Instruction contains branch to addend.
displacement = getDisplacementFromArmBranch(instruction);
*addend = fixupAddress + 8 + displacement;
- return std::error_code();
+ return llvm::Error();
case ARM_RELOC_BR24 | rPcRel | rLength4:
// ex: bl _foo (and _foo is defined)
if (((instruction & 0x0F000000) == 0x0A000000)
@@ -597,40 +596,40 @@ std::error_code ArchHandler_arm::getReferenceInfo(
*kind = arm_bl24;
displacement = getDisplacementFromArmBranch(instruction);
targetAddress = fixupAddress + 8 + displacement;
- if (E ec = atomFromAddress(0, reloc.value, target, addend))
+ if (auto ec = atomFromAddress(0, reloc.value, target, addend))
return ec;
// reloc.value is target atom's address. Instruction contains branch
// to atom+addend.
*addend += (targetAddress - reloc.value);
- return std::error_code();
+ return llvm::Error();
case ARM_RELOC_VANILLA | rExtern | rLength4:
// ex: .long _foo (and _foo is undefined)
*kind = pointer32;
- if (E ec = atomFromSymbolIndex(reloc.symbol, target))
+ if (auto ec = atomFromSymbolIndex(reloc.symbol, target))
return ec;
*addend = instruction;
- return std::error_code();
+ return llvm::Error();
case ARM_RELOC_VANILLA | rLength4:
// ex: .long _foo (and _foo is defined)
*kind = pointer32;
- if (E ec = atomFromAddress(reloc.symbol, instruction, target, addend))
+ if (auto ec = atomFromAddress(reloc.symbol, instruction, target, addend))
return ec;
*addend = clearThumbBit((uint32_t) * addend, *target);
- return std::error_code();
+ return llvm::Error();
case ARM_RELOC_VANILLA | rScattered | rLength4:
// ex: .long _foo+a (and _foo is defined)
*kind = pointer32;
- if (E ec = atomFromAddress(0, reloc.value, target, addend))
+ if (auto ec = atomFromAddress(0, reloc.value, target, addend))
return ec;
*addend += (clearThumbBit(instruction, *target) - reloc.value);
- return std::error_code();
+ return llvm::Error();
default:
- return make_dynamic_error_code("unsupported arm relocation type");
+ return llvm::make_error<GenericError>("unsupported arm relocation type");
}
- return std::error_code();
+ return llvm::Error();
}
-std::error_code
+llvm::Error
ArchHandler_arm::getPairReferenceInfo(const normalized::Relocation &reloc1,
const normalized::Relocation &reloc2,
const DefinedAtom *inAtom,
@@ -783,10 +782,9 @@ ArchHandler_arm::getPairReferenceInfo(const normalized::Relocation &reloc1,
pointerDiff = true;
break;
default:
- return make_dynamic_error_code("unsupported arm relocation pair");
+ return llvm::make_error<GenericError>("unsupported arm relocation pair");
}
const uint8_t *fixupContent = &inAtom->rawContent()[offsetInAtom];
- std::error_code ec;
uint32_t instruction = *(const ulittle32_t *)fixupContent;
uint32_t value;
uint32_t fromAddress;
@@ -799,14 +797,12 @@ ArchHandler_arm::getPairReferenceInfo(const normalized::Relocation &reloc1,
if (pointerDiff) {
toAddress = reloc1.value;
fromAddress = reloc2.value;
- ec = atomFromAddr(0, toAddress, target, &offsetInTo);
- if (ec)
+ if (auto ec = atomFromAddr(0, toAddress, target, &offsetInTo))
return ec;
- ec = atomFromAddr(0, fromAddress, &fromTarget, &offsetInFrom);
- if (ec)
+ if (auto ec = atomFromAddr(0, fromAddress, &fromTarget, &offsetInFrom))
return ec;
if (scatterable && (fromTarget != inAtom))
- return make_dynamic_error_code(
+ return llvm::make_error<GenericError>(
"SECTDIFF relocation where subtrahend label is not in atom");
*kind = delta32;
value = clearThumbBit(instruction, *target);
@@ -814,35 +810,33 @@ ArchHandler_arm::getPairReferenceInfo(const normalized::Relocation &reloc1,
} else if (funcRel) {
toAddress = reloc1.value;
fromAddress = reloc2.value;
- ec = atomFromAddr(0, toAddress, target, &offsetInTo);
- if (ec)
+ if (auto ec = atomFromAddr(0, toAddress, target, &offsetInTo))
return ec;
- ec = atomFromAddr(0, fromAddress, &fromTarget, &offsetInFrom);
- if (ec)
+ if (auto ec = atomFromAddr(0, fromAddress, &fromTarget, &offsetInFrom))
return ec;
if (fromTarget != inAtom)
- return make_dynamic_error_code("ARM_RELOC_HALF_SECTDIFF relocation "
- "where subtrahend label is not in atom");
+ return llvm::make_error<GenericError>("ARM_RELOC_HALF_SECTDIFF relocation"
+ " where subtrahend label is not in atom");
other16 = (reloc2.offset & 0xFFFF);
if (thumbReloc) {
if (top) {
if (!isThumbMovt(instruction))
- return make_dynamic_error_code("expected movt instruction");
+ return llvm::make_error<GenericError>("expected movt instruction");
}
else {
if (!isThumbMovw(instruction))
- return make_dynamic_error_code("expected movw instruction");
+ return llvm::make_error<GenericError>("expected movw instruction");
}
instruction16 = getWordFromThumbMov(instruction);
}
else {
if (top) {
if (!isArmMovt(instruction))
- return make_dynamic_error_code("expected movt instruction");
+ return llvm::make_error<GenericError>("expected movt instruction");
}
else {
if (!isArmMovw(instruction))
- return make_dynamic_error_code("expected movw instruction");
+ return llvm::make_error<GenericError>("expected movw instruction");
}
instruction16 = getWordFromArmMov(instruction);
}
@@ -853,28 +847,28 @@ ArchHandler_arm::getPairReferenceInfo(const normalized::Relocation &reloc1,
value = clearThumbBit(value, *target);
int64_t ta = (int64_t) value - (toAddress - fromAddress);
*addend = ta - offsetInFrom;
- return std::error_code();
+ return llvm::Error();
} else {
uint32_t sectIndex;
if (thumbReloc) {
if (top) {
if (!isThumbMovt(instruction))
- return make_dynamic_error_code("expected movt instruction");
+ return llvm::make_error<GenericError>("expected movt instruction");
}
else {
if (!isThumbMovw(instruction))
- return make_dynamic_error_code("expected movw instruction");
+ return llvm::make_error<GenericError>("expected movw instruction");
}
instruction16 = getWordFromThumbMov(instruction);
}
else {
if (top) {
if (!isArmMovt(instruction))
- return make_dynamic_error_code("expected movt instruction");
+ return llvm::make_error<GenericError>("expected movt instruction");
}
else {
if (!isArmMovw(instruction))
- return make_dynamic_error_code("expected movw instruction");
+ return llvm::make_error<GenericError>("expected movw instruction");
}
instruction16 = getWordFromArmMov(instruction);
}
@@ -884,8 +878,7 @@ ArchHandler_arm::getPairReferenceInfo(const normalized::Relocation &reloc1,
else
value = (other16 << 16) | instruction16;
if (reloc1.isExtern) {
- ec = atomFromSymbolIndex(reloc1.symbol, target);
- if (ec)
+ if (auto ec = atomFromSymbolIndex(reloc1.symbol, target))
return ec;
*addend = value;
} else {
@@ -896,14 +889,13 @@ ArchHandler_arm::getPairReferenceInfo(const normalized::Relocation &reloc1,
toAddress = value;
sectIndex = reloc1.symbol;
}
- ec = atomFromAddr(sectIndex, toAddress, target, &offsetInTo);
- if (ec)
+ if (auto ec = atomFromAddr(sectIndex, toAddress, target, &offsetInTo))
return ec;
*addend = value - toAddress;
}
}
- return std::error_code();
+ return llvm::Error();
}
void ArchHandler_arm::applyFixupFinal(const Reference &ref, uint8_t *loc,
OpenPOWER on IntegriCloud