Index: ELF/Target.h =================================================================== --- ELF/Target.h +++ ELF/Target.h @@ -143,7 +143,17 @@ TargetInfo *getX86_64TargetInfo(); template 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 @@ 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 Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -87,7 +87,7 @@ fatal("unknown target machine"); } -template static std::string getErrorLoc(const uint8_t *Loc) { +template static ErrorPlace getErrPlace(const uint8_t *Loc) { for (InputSectionBase *D : InputSections) { auto *IS = dyn_cast(D); if (!IS || !IS->getParent()) @@ -95,21 +95,21 @@ uint8_t *ISLoc = IS->getParent()->Loc + IS->OutSecOff; if (ISLoc <= Loc && Loc < ISLoc + IS->getSize()) - return IS->template getLocation(Loc - ISLoc) + ": "; + return {IS, IS->template getLocation(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(Loc); + return getErrPlace(Loc); case ELF32BEKind: - return getErrorLoc(Loc); + return getErrPlace(Loc); case ELF64LEKind: - return getErrorLoc(Loc); + return getErrPlace(Loc); case ELF64BEKind: - return getErrorLoc(Loc); + return getErrPlace(Loc); default: llvm_unreachable("unknown ELF type"); } Index: test/ELF/x86-64-reloc-debug-overflow.s =================================================================== --- test/ELF/x86-64-reloc-debug-overflow.s +++ test/ELF/x86-64-reloc-debug-overflow.s @@ -0,0 +1,12 @@ +# 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+0x1): relocation R_X86_64_32 out of range: 68719476736 is not in [0, 4294967295]; consider recompiling with -fdebug-types-section to reduce size of debug sections + +# CHECK: (.debug_info+0x8): relocation R_X86_64_32S out of range: -281474976710656 is not in [-2147483648, 2147483647]; consider recompiling with -fdebug-types-section to reduce size of debug sections + +.section .debug_info,"",@progbits + movl $big, %edx + movq $foo - 0x1000000000000, %rdx