diff options
author | George Rimar <grimar@accesssoftek.com> | 2018-03-21 09:19:34 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2018-03-21 09:19:34 +0000 |
commit | 89481f363a4311d679daa81ca1365460132f8935 (patch) | |
tree | d4d6fee84583c8023014688ca5058a28a6841472 | |
parent | 2b88406e7b33ec5e38c803ee4871208a81395a90 (diff) | |
download | bcm5719-llvm-89481f363a4311d679daa81ca1365460132f8935.tar.gz bcm5719-llvm-89481f363a4311d679daa81ca1365460132f8935.zip |
[ELF] - Teach LLD to hint about -fdebug-types-section.
Patch teaches LLD to hint user about -fdebug-types-section flag
if relocation overflow happens in debug section.
Differential revision: https://reviews.llvm.org/D40954
llvm-svn: 328081
-rw-r--r-- | lld/ELF/Target.cpp | 16 | ||||
-rw-r--r-- | lld/ELF/Target.h | 24 | ||||
-rw-r--r-- | lld/test/ELF/x86-64-reloc-debug-overflow.s | 9 |
3 files changed, 37 insertions, 12 deletions
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index b528fd583c1..c19cb5f6827 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -87,7 +87,7 @@ TargetInfo *elf::getTarget() { fatal("unknown target machine"); } -template <class ELFT> static std::string getErrorLoc(const uint8_t *Loc) { +template <class ELFT> static ErrorPlace getErrPlace(const uint8_t *Loc) { for (InputSectionBase *D : InputSections) { auto *IS = dyn_cast<InputSection>(D); if (!IS || !IS->getParent()) @@ -95,21 +95,21 @@ template <class ELFT> static std::string getErrorLoc(const uint8_t *Loc) { uint8_t *ISLoc = IS->getParent()->Loc + IS->OutSecOff; if (ISLoc <= Loc && Loc < ISLoc + IS->getSize()) - return IS->template getLocation<ELFT>(Loc - ISLoc) + ": "; + return {IS, IS->template getLocation<ELFT>(Loc - ISLoc) + ": "}; } - return ""; + return {}; } -std::string elf::getErrorLocation(const uint8_t *Loc) { +ErrorPlace elf::getErrorPlace(const uint8_t *Loc) { switch (Config->EKind) { case ELF32LEKind: - return getErrorLoc<ELF32LE>(Loc); + return getErrPlace<ELF32LE>(Loc); case ELF32BEKind: - return getErrorLoc<ELF32BE>(Loc); + return getErrPlace<ELF32BE>(Loc); case ELF64LEKind: - return getErrorLoc<ELF64LE>(Loc); + return getErrPlace<ELF64LE>(Loc); case ELF64BEKind: - return getErrorLoc<ELF64BE>(Loc); + return getErrPlace<ELF64BE>(Loc); default: llvm_unreachable("unknown ELF type"); } diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h index 4e9705870b9..f02b7ac4188 100644 --- a/lld/ELF/Target.h +++ b/lld/ELF/Target.h @@ -143,7 +143,17 @@ TargetInfo *getX86TargetInfo(); TargetInfo *getX86_64TargetInfo(); template <class ELFT> TargetInfo *getMipsTargetInfo(); -std::string getErrorLocation(const uint8_t *Loc); +struct ErrorPlace { + InputSectionBase *IS; + std::string Loc; +}; + +// Returns input section and corresponding source string for the given location. +ErrorPlace getErrorPlace(const uint8_t *Loc); + +static inline std::string getErrorLocation(const uint8_t *Loc) { + return getErrorPlace(Loc).Loc; +} uint64_t getPPC64TocBase(); uint64_t getAArch64Page(uint64_t Expr); @@ -155,9 +165,15 @@ template <class ELFT> bool isMipsPIC(const Defined *Sym); static inline void reportRangeError(uint8_t *Loc, RelType Type, const Twine &V, int64_t Min, uint64_t Max) { - error(getErrorLocation(Loc) + "relocation " + lld::toString(Type) + - " out of range: " + V + " is not in [" + Twine(Min) + ", " + - Twine(Max) + "]"); + ErrorPlace ErrPlace = getErrorPlace(Loc); + StringRef Hint; + if (ErrPlace.IS && ErrPlace.IS->Name.startswith(".debug")) + Hint = "; consider recompiling with -fdebug-types-section to reduce size " + "of debug sections"; + + error(ErrPlace.Loc + "relocation " + lld::toString(Type) + + " out of range: " + V.str() + " is not in [" + Twine(Min).str() + ", " + + Twine(Max).str() + "]" + Hint); } template <unsigned N> diff --git a/lld/test/ELF/x86-64-reloc-debug-overflow.s b/lld/test/ELF/x86-64-reloc-debug-overflow.s new file mode 100644 index 00000000000..364c3bf3133 --- /dev/null +++ b/lld/test/ELF/x86-64-reloc-debug-overflow.s @@ -0,0 +1,9 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-error.s -o %tabs +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: not ld.lld -shared %tabs %t -o %t2 2>&1 | FileCheck %s + +# CHECK: (.debug_info+0x0): relocation R_X86_64_32 out of range: 281474976710656 is not in [0, 4294967295]; consider recompiling with -fdebug-types-section to reduce size of debug sections + +.section .debug_info,"",@progbits + .long .debug_info + 0x1000000000000 |