mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-16 12:29:57 +00:00
Fix which file is in an error message.
When reporting an invalid relocation we were blaming the destination file instead of the file with the relocation. llvm-svn: 310084
This commit is contained in:
parent
8de4bbdaa5
commit
3bab91332f
@ -32,7 +32,7 @@ namespace {
|
||||
class AArch64 final : public TargetInfo {
|
||||
public:
|
||||
AArch64();
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
|
||||
const uint8_t *Loc) const override;
|
||||
bool isPicRel(uint32_t Type) const override;
|
||||
void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const override;
|
||||
@ -69,7 +69,7 @@ AArch64::AArch64() {
|
||||
}
|
||||
|
||||
RelExpr AArch64::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
const uint8_t *Loc) const {
|
||||
const InputFile &File, const uint8_t *Loc) const {
|
||||
switch (Type) {
|
||||
default:
|
||||
return R_ABS;
|
||||
|
@ -26,7 +26,7 @@ class AMDGPU final : public TargetInfo {
|
||||
public:
|
||||
AMDGPU();
|
||||
void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
|
||||
const uint8_t *Loc) const override;
|
||||
};
|
||||
} // namespace
|
||||
@ -59,7 +59,7 @@ void AMDGPU::relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const {
|
||||
}
|
||||
|
||||
RelExpr AMDGPU::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
const uint8_t *Loc) const {
|
||||
const InputFile &File, const uint8_t *Loc) const {
|
||||
switch (Type) {
|
||||
case R_AMDGPU_ABS32:
|
||||
case R_AMDGPU_ABS64:
|
||||
@ -73,7 +73,7 @@ RelExpr AMDGPU::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
case R_AMDGPU_GOTPCREL32_HI:
|
||||
return R_GOT_PC;
|
||||
default:
|
||||
error(toString(S.File) + ": unknown relocation type: " + toString(Type));
|
||||
error(toString(&File) + ": unknown relocation type: " + toString(Type));
|
||||
return R_HINT;
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace {
|
||||
class ARM final : public TargetInfo {
|
||||
public:
|
||||
ARM();
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
|
||||
const uint8_t *Loc) const override;
|
||||
bool isPicRel(uint32_t Type) const override;
|
||||
uint32_t getDynRel(uint32_t Type) const override;
|
||||
@ -66,7 +66,7 @@ ARM::ARM() {
|
||||
}
|
||||
|
||||
RelExpr ARM::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
const uint8_t *Loc) const {
|
||||
const InputFile &File, const uint8_t *Loc) const {
|
||||
switch (Type) {
|
||||
default:
|
||||
return R_ABS;
|
||||
|
@ -43,19 +43,19 @@ using namespace lld::elf;
|
||||
namespace {
|
||||
class AVR final : public TargetInfo {
|
||||
public:
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
|
||||
const uint8_t *Loc) const override;
|
||||
void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
RelExpr AVR::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
const uint8_t *Loc) const {
|
||||
const InputFile &File, const uint8_t *Loc) const {
|
||||
switch (Type) {
|
||||
case R_AVR_CALL:
|
||||
return R_ABS;
|
||||
default:
|
||||
error(toString(S.File) + ": unknown relocation type: " + toString(Type));
|
||||
error(toString(&File) + ": unknown relocation type: " + toString(Type));
|
||||
return R_HINT;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ namespace {
|
||||
template <class ELFT> class MIPS final : public TargetInfo {
|
||||
public:
|
||||
MIPS();
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
|
||||
const uint8_t *Loc) const override;
|
||||
int64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const override;
|
||||
bool isPicRel(uint32_t Type) const override;
|
||||
@ -71,6 +71,7 @@ template <class ELFT> MIPS<ELFT>::MIPS() {
|
||||
|
||||
template <class ELFT>
|
||||
RelExpr MIPS<ELFT>::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
const InputFile &File,
|
||||
const uint8_t *Loc) const {
|
||||
// See comment in the calculateMipsRelChain.
|
||||
if (ELFT::Is64Bits || Config->MipsN32Abi)
|
||||
|
@ -23,7 +23,7 @@ class PPC final : public TargetInfo {
|
||||
public:
|
||||
PPC() { GotBaseSymOff = 0x8000; }
|
||||
void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
|
||||
const uint8_t *Loc) const override;
|
||||
};
|
||||
} // namespace
|
||||
@ -49,7 +49,7 @@ void PPC::relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const {
|
||||
}
|
||||
|
||||
RelExpr PPC::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
const uint8_t *Loc) const {
|
||||
const InputFile &File, const uint8_t *Loc) const {
|
||||
switch (Type) {
|
||||
case R_PPC_REL24:
|
||||
case R_PPC_REL32:
|
||||
|
@ -39,7 +39,7 @@ namespace {
|
||||
class PPC64 final : public TargetInfo {
|
||||
public:
|
||||
PPC64();
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
|
||||
const uint8_t *Loc) const override;
|
||||
void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,
|
||||
int32_t Index, unsigned RelOff) const override;
|
||||
@ -83,7 +83,7 @@ PPC64::PPC64() {
|
||||
}
|
||||
|
||||
RelExpr PPC64::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
const uint8_t *Loc) const {
|
||||
const InputFile &File, const uint8_t *Loc) const {
|
||||
switch (Type) {
|
||||
default:
|
||||
return R_ABS;
|
||||
|
@ -24,7 +24,7 @@ namespace {
|
||||
class SPARCV9 final : public TargetInfo {
|
||||
public:
|
||||
SPARCV9();
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
|
||||
const uint8_t *Loc) const override;
|
||||
void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr,
|
||||
int32_t Index, unsigned RelOff) const override;
|
||||
@ -47,7 +47,7 @@ SPARCV9::SPARCV9() {
|
||||
}
|
||||
|
||||
RelExpr SPARCV9::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
const uint8_t *Loc) const {
|
||||
const InputFile &File, const uint8_t *Loc) const {
|
||||
switch (Type) {
|
||||
case R_SPARC_32:
|
||||
case R_SPARC_UA32:
|
||||
@ -68,7 +68,7 @@ RelExpr SPARCV9::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
case R_SPARC_NONE:
|
||||
return R_NONE;
|
||||
default:
|
||||
error(toString(S.File) + ": unknown relocation type: " + toString(Type));
|
||||
error(toString(&File) + ": unknown relocation type: " + toString(Type));
|
||||
return R_HINT;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace {
|
||||
class X86 final : public TargetInfo {
|
||||
public:
|
||||
X86();
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
|
||||
const uint8_t *Loc) const override;
|
||||
int64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const override;
|
||||
void writeGotPltHeader(uint8_t *Buf) const override;
|
||||
@ -64,7 +64,7 @@ X86::X86() {
|
||||
}
|
||||
|
||||
RelExpr X86::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
const uint8_t *Loc) const {
|
||||
const InputFile &File, const uint8_t *Loc) const {
|
||||
switch (Type) {
|
||||
case R_386_8:
|
||||
case R_386_16:
|
||||
@ -101,7 +101,7 @@ RelExpr X86::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
if ((Loc[-1] & 0xc7) != 0x5)
|
||||
return R_GOT_FROM_END;
|
||||
if (Config->Pic)
|
||||
error(toString(S.File) + ": relocation " + toString(Type) + " against '" +
|
||||
error(toString(&File) + ": relocation " + toString(Type) + " against '" +
|
||||
S.getName() +
|
||||
"' without base register can not be used when PIC enabled");
|
||||
return R_GOT;
|
||||
@ -116,7 +116,7 @@ RelExpr X86::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
case R_386_NONE:
|
||||
return R_NONE;
|
||||
default:
|
||||
error(toString(S.File) + ": unknown relocation type: " + toString(Type));
|
||||
error(toString(&File) + ": unknown relocation type: " + toString(Type));
|
||||
return R_HINT;
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace {
|
||||
template <class ELFT> class X86_64 final : public TargetInfo {
|
||||
public:
|
||||
X86_64();
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
|
||||
const uint8_t *Loc) const override;
|
||||
bool isPicRel(uint32_t Type) const override;
|
||||
void writeGotPltHeader(uint8_t *Buf) const override;
|
||||
@ -74,6 +74,7 @@ template <class ELFT> X86_64<ELFT>::X86_64() {
|
||||
|
||||
template <class ELFT>
|
||||
RelExpr X86_64<ELFT>::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
const InputFile &File,
|
||||
const uint8_t *Loc) const {
|
||||
switch (Type) {
|
||||
case R_X86_64_8:
|
||||
@ -109,7 +110,7 @@ RelExpr X86_64<ELFT>::getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
case R_X86_64_NONE:
|
||||
return R_NONE;
|
||||
default:
|
||||
error(toString(S.File) + ": unknown relocation type: " + toString(Type));
|
||||
error(toString(&File) + ": unknown relocation type: " + toString(Type));
|
||||
return R_HINT;
|
||||
}
|
||||
}
|
||||
|
@ -669,7 +669,7 @@ void InputSection::relocateNonAlloc(uint8_t *Buf, ArrayRef<RelTy> Rels) {
|
||||
Addend += Target->getImplicitAddend(BufLoc, Type);
|
||||
|
||||
SymbolBody &Sym = this->getFile<ELFT>()->getRelocTargetSym(Rel);
|
||||
RelExpr Expr = Target->getRelExpr(Type, Sym, BufLoc);
|
||||
RelExpr Expr = Target->getRelExpr(Type, Sym, *File, BufLoc);
|
||||
if (Expr == R_NONE)
|
||||
continue;
|
||||
if (Expr != R_ABS) {
|
||||
|
@ -844,8 +844,8 @@ static void scanRelocs(InputSectionBase &Sec, ArrayRef<RelTy> Rels) {
|
||||
if (!Body.isLocal() && Body.isUndefined() && !Body.symbol()->isWeak())
|
||||
reportUndefined<ELFT>(Body, Sec, Rel.r_offset);
|
||||
|
||||
RelExpr Expr =
|
||||
Target->getRelExpr(Type, Body, Sec.Data.begin() + Rel.r_offset);
|
||||
RelExpr Expr = Target->getRelExpr(Type, Body, *Sec.File,
|
||||
Sec.Data.begin() + Rel.r_offset);
|
||||
|
||||
// Ignore "hint" relocations because they are only markers for relaxation.
|
||||
if (isRelExprOneOf<R_HINT, R_NONE>(Expr))
|
||||
|
@ -55,6 +55,7 @@ public:
|
||||
virtual bool inBranchRange(uint32_t RelocType, uint64_t Src,
|
||||
uint64_t Dst) const;
|
||||
virtual RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
|
||||
const InputFile &File,
|
||||
const uint8_t *Loc) const = 0;
|
||||
virtual void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const = 0;
|
||||
virtual ~TargetInfo();
|
||||
|
@ -1,7 +1,10 @@
|
||||
# RUN: yaml2obj %s -o %t.o
|
||||
# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
|
||||
# CHECK: {{.*}}.o: unknown relocation type: Unknown (152)
|
||||
# CHECK: {{.*}}.o: unknown relocation type: Unknown (153)
|
||||
# REQUIRES: x86
|
||||
# RUN: yaml2obj %s -o %t1.o
|
||||
# RUN: echo ".global foo; foo:" > %t2.s
|
||||
# RUN: llvm-mc %t2.s -o %t2.o -filetype=obj -triple x86_64-pc-linux
|
||||
# RUN: not ld.lld %t1.o %t2.o -o /dev/null 2>&1 | FileCheck %s
|
||||
# CHECK: {{.*}}1.o: unknown relocation type: Unknown (152)
|
||||
# CHECK: {{.*}}1.o: unknown relocation type: Unknown (153)
|
||||
|
||||
!ELF
|
||||
FileHeader:
|
||||
@ -20,8 +23,11 @@ Sections:
|
||||
Info: .text
|
||||
Relocations:
|
||||
- Offset: 0x0000000000000000
|
||||
Symbol: ''
|
||||
Symbol: foo
|
||||
Type: 0x98
|
||||
- Offset: 0x0000000000000000
|
||||
Symbol: ''
|
||||
Symbol: foo
|
||||
Type: 0x99
|
||||
Symbols:
|
||||
Global:
|
||||
- Name: foo
|
||||
|
Loading…
Reference in New Issue
Block a user