[lld] r287943 - Move getLocation from Relocations.cpp to InputSection.cpp.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 25 10:51:53 PST 2016
Author: ruiu
Date: Fri Nov 25 12:51:53 2016
New Revision: 287943
URL: http://llvm.org/viewvc/llvm-project?rev=287943&view=rev
Log:
Move getLocation from Relocations.cpp to InputSection.cpp.
The function was used only within Relocations.cpp, but now we are
using it in many places, so this patch moves it to a file that fits
to the functionality.
Modified:
lld/trunk/ELF/EhFrame.cpp
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/Relocations.cpp
lld/trunk/ELF/Relocations.h
lld/trunk/ELF/SymbolTable.cpp
Modified: lld/trunk/ELF/EhFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/EhFrame.cpp?rev=287943&r1=287942&r2=287943&view=diff
==============================================================================
--- lld/trunk/ELF/EhFrame.cpp (original)
+++ lld/trunk/ELF/EhFrame.cpp Fri Nov 25 12:51:53 2016
@@ -44,8 +44,7 @@ public:
private:
template <class P> void failOn(const P *Loc, const Twine &Msg) {
- fatal(getLocation(*IS, (const uint8_t *)Loc - IS->Data.data()) + ": " +
- Msg);
+ fatal(IS->getLocation((const uint8_t *)Loc - IS->Data.data()) + ": " + Msg);
}
uint8_t readByte();
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=287943&r1=287942&r2=287943&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Fri Nov 25 12:51:53 2016
@@ -198,6 +198,31 @@ InputSectionBase<ELFT> *InputSectionBase
return nullptr;
}
+// Returns a source location string. Used to construct an error message.
+template <class ELFT>
+std::string InputSectionBase<ELFT>::getLocation(typename ELFT::uint Offset) {
+ // First check if we can get desired values from debugging information.
+ std::string LineInfo = File->getLineInfo(this, Offset);
+ if (!LineInfo.empty())
+ return LineInfo;
+
+ // File->SourceFile contains STT_FILE symbol that contains a
+ // source file name. If it's missing, we use an object file name.
+ std::string SrcFile = File->SourceFile;
+ if (SrcFile.empty())
+ SrcFile = toString(File);
+
+ // Find a function symbol that encloses a given location.
+ for (SymbolBody *B : File->getSymbols())
+ if (auto *D = dyn_cast<DefinedRegular<ELFT>>(B))
+ if (D->Section == this && D->Type == STT_FUNC)
+ if (D->Value <= Offset && Offset < D->Value + D->Size)
+ return SrcFile + ":(function " + toString(*D) + ")";
+
+ // If there's no symbol, print out the offset in the section.
+ return (SrcFile + ":(" + Name + "+0x" + utohexstr(Offset) + ")").str();
+}
+
template <class ELFT>
InputSection<ELFT>::InputSection() : InputSectionBase<ELFT>() {}
@@ -467,7 +492,7 @@ void InputSection<ELFT>::relocateNonAllo
SymbolBody &Sym = this->File->getRelocTargetSym(Rel);
if (Target->getRelExpr(Type, Sym) != R_ABS) {
- error(getLocation(*this, Offset) + ": has non-ABS reloc");
+ error(this->getLocation(Offset) + ": has non-ABS reloc");
return;
}
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=287943&r1=287942&r2=287943&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Fri Nov 25 12:51:53 2016
@@ -141,6 +141,9 @@ public:
void uncompress();
+ // Returns a source location string. Used to construct an error message.
+ std::string getLocation(uintX_t Offset);
+
void relocate(uint8_t *Buf, uint8_t *BufEnd);
private:
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=287943&r1=287942&r2=287943&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Fri Nov 25 12:51:53 2016
@@ -343,7 +343,7 @@ static bool isStaticLinkTimeConstant(Rel
if (AbsVal && RelE) {
if (Body.isUndefined() && !Body.isLocal() && Body.symbol()->isWeak())
return true;
- error(getLocation(S, RelOff) + ": relocation " + toString(Type) +
+ error(S.getLocation(RelOff) + ": relocation " + toString(Type) +
" cannot refer to absolute symbol '" + toString(Body) +
"' defined in " + toString(Body.File));
return true;
@@ -443,7 +443,7 @@ static RelExpr adjustExpr(const elf::Obj
// only memory. We can hack around it if we are producing an executable and
// the refered symbol can be preemepted to refer to the executable.
if (Config->Shared || (Config->Pic && !isRelExpr(Expr))) {
- error(getLocation(S, RelOff) + ": can't create dynamic relocation " +
+ error(S.getLocation(RelOff) + ": can't create dynamic relocation " +
toString(Type) + " against " +
(Body.getName().empty() ? "local symbol in readonly segment"
: "symbol '" + toString(Body) + "'") +
@@ -451,8 +451,8 @@ static RelExpr adjustExpr(const elf::Obj
return Expr;
}
if (Body.getVisibility() != STV_DEFAULT) {
- error(getLocation(S, RelOff) + ": cannot preempt symbol '" +
- toString(Body) + "' defined in " + toString(Body.File));
+ error(S.getLocation(RelOff) + ": cannot preempt symbol '" + toString(Body) +
+ "' defined in " + toString(Body.File));
return Expr;
}
if (Body.isObject()) {
@@ -521,43 +521,6 @@ static typename ELFT::uint computeAddend
return Addend;
}
-// Find symbol that encloses given offset. Used for error reporting.
-template <class ELFT>
-static DefinedRegular<ELFT> *getSymbolAt(InputSectionBase<ELFT> *S,
- typename ELFT::uint Offset) {
- for (SymbolBody *B : S->getFile()->getSymbols())
- if (auto *D = dyn_cast<DefinedRegular<ELFT>>(B))
- if (D->Value <= Offset && D->Value + D->Size > Offset && D->Section == S)
- return D;
-
- return nullptr;
-}
-
-template <class ELFT>
-std::string getLocation(InputSectionBase<ELFT> &S, typename ELFT::uint Offset) {
- ObjectFile<ELFT> *File = S.getFile();
-
- // First check if we can get desired values from debugging information.
- std::string LineInfo = File->getLineInfo(&S, Offset);
- if (!LineInfo.empty())
- return LineInfo;
-
- // File->SourceFile contains STT_FILE symbol contents which is a
- // filename. Compilers usually create STT_FILE symbols. If it's
- // missing, we use an actual filename.
- std::string SrcFile = File->SourceFile;
- if (SrcFile.empty())
- SrcFile = toString(File);
-
- // Find a symbol at a given location.
- DefinedRegular<ELFT> *Encl = getSymbolAt(&S, Offset);
- if (Encl && Encl->Type == STT_FUNC)
- return SrcFile + ":(function " + toString(*Encl) + ")";
-
- // If there's no symbol, print out the offset instead of a symbol name.
- return (SrcFile + ":(" + S.Name + "+0x" + utohexstr(Offset) + ")").str();
-}
-
template <class ELFT>
static void reportUndefined(SymbolBody &Sym, InputSectionBase<ELFT> &S,
typename ELFT::uint Offset) {
@@ -569,7 +532,7 @@ static void reportUndefined(SymbolBody &
return;
std::string Msg =
- getLocation(S, Offset) + ": undefined symbol '" + toString(Sym) + "'";
+ S.getLocation(Offset) + ": undefined symbol '" + toString(Sym) + "'";
if (Config->UnresolvedSymbols == UnresolvedPolicy::Warn)
warn(Msg);
@@ -712,7 +675,7 @@ static void scanRelocs(InputSectionBase<
// We don't know anything about the finaly symbol. Just ask the dynamic
// linker to handle the relocation for us.
if (!Target->isPicRel(Type))
- error(getLocation(C, Offset) + ": relocation " + toString(Type) +
+ error(C.getLocation(Offset) + ": relocation " + toString(Type) +
" cannot be used against shared object; recompile with -fPIC.");
AddDyn({Target->getDynRel(Type), &C, Offset, false, &Body, Addend});
@@ -837,14 +800,5 @@ template void createThunks<ELF32LE>(Inpu
template void createThunks<ELF32BE>(InputSectionBase<ELF32BE> &);
template void createThunks<ELF64LE>(InputSectionBase<ELF64LE> &);
template void createThunks<ELF64BE>(InputSectionBase<ELF64BE> &);
-
-template std::string getLocation<ELF32LE>(InputSectionBase<ELF32LE> &S,
- uint32_t Offset);
-template std::string getLocation<ELF32BE>(InputSectionBase<ELF32BE> &S,
- uint32_t Offset);
-template std::string getLocation<ELF64LE>(InputSectionBase<ELF64LE> &S,
- uint64_t Offset);
-template std::string getLocation<ELF64BE>(InputSectionBase<ELF64BE> &S,
- uint64_t Offset);
}
}
Modified: lld/trunk/ELF/Relocations.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.h?rev=287943&r1=287942&r2=287943&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.h (original)
+++ lld/trunk/ELF/Relocations.h Fri Nov 25 12:51:53 2016
@@ -87,9 +87,6 @@ template <class ELFT> void scanRelocatio
template <class ELFT> void createThunks(InputSectionBase<ELFT> &);
template <class ELFT>
-std::string getLocation(InputSectionBase<ELFT> &S, typename ELFT::uint Offset);
-
-template <class ELFT>
static inline typename ELFT::uint getAddend(const typename ELFT::Rel &Rel) {
return 0;
}
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=287943&r1=287942&r2=287943&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Fri Nov 25 12:51:53 2016
@@ -359,8 +359,8 @@ static void reportDuplicate(SymbolBody *
return;
}
- std::string OldLoc = getLocation(*D->Section, D->Value);
- std::string NewLoc = getLocation(*ErrSec, ErrOffset);
+ std::string OldLoc = D->Section->getLocation(D->Value);
+ std::string NewLoc = ErrSec->getLocation(ErrOffset);
print(NewLoc + ": duplicate symbol '" + toString(*Existing) + "'");
print(OldLoc + ": previous definition was here");
More information about the llvm-commits
mailing list