[lld] r321772 - Use references for a few arguments that are never null.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 3 15:26:20 PST 2018
Author: rafael
Date: Wed Jan 3 15:26:20 2018
New Revision: 321772
URL: http://llvm.org/viewvc/llvm-project?rev=321772&view=rev
Log:
Use references for a few arguments that are never null.
Modified:
lld/trunk/ELF/Relocations.cpp
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=321772&r1=321771&r2=321772&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Wed Jan 3 15:26:20 2018
@@ -426,15 +426,15 @@ static RelExpr fromPlt(RelExpr Expr) {
}
// Returns true if a given shared symbol is in a read-only segment in a DSO.
-template <class ELFT> static bool isReadOnly(SharedSymbol *SS) {
+template <class ELFT> static bool isReadOnly(SharedSymbol &SS) {
typedef typename ELFT::Phdr Elf_Phdr;
// Determine if the symbol is read-only by scanning the DSO's program headers.
- const SharedFile<ELFT> &File = SS->getFile<ELFT>();
+ const SharedFile<ELFT> &File = SS.getFile<ELFT>();
for (const Elf_Phdr &Phdr : check(File.getObj().program_headers()))
if ((Phdr.p_type == ELF::PT_LOAD || Phdr.p_type == ELF::PT_GNU_RELRO) &&
- !(Phdr.p_flags & ELF::PF_W) && SS->Value >= Phdr.p_vaddr &&
- SS->Value < Phdr.p_vaddr + Phdr.p_memsz)
+ !(Phdr.p_flags & ELF::PF_W) && SS.Value >= Phdr.p_vaddr &&
+ SS.Value < Phdr.p_vaddr + Phdr.p_memsz)
return true;
return false;
}
@@ -445,15 +445,15 @@ template <class ELFT> static bool isRead
// them are copied by a copy relocation, all of them need to be copied.
// Otherwise, they would refer different places at runtime.
template <class ELFT>
-static std::vector<SharedSymbol *> getSymbolsAt(SharedSymbol *SS) {
+static std::vector<SharedSymbol *> getSymbolsAt(SharedSymbol &SS) {
typedef typename ELFT::Sym Elf_Sym;
- SharedFile<ELFT> &File = SS->getFile<ELFT>();
+ SharedFile<ELFT> &File = SS.getFile<ELFT>();
std::vector<SharedSymbol *> Ret;
for (const Elf_Sym &S : File.getGlobalELFSyms()) {
if (S.st_shndx == SHN_UNDEF || S.st_shndx == SHN_ABS ||
- S.st_value != SS->Value)
+ S.st_value != SS.Value)
continue;
StringRef Name = check(S.getName(File.getStringTable()));
Symbol *Sym = Symtab->find(Name);
@@ -505,17 +505,17 @@ static std::vector<SharedSymbol *> getSy
// to the variable in .bss. This kind of issue is sometimes very hard to
// debug. What's a solution? Instead of exporting a varaible V from a DSO,
// define an accessor getV().
-template <class ELFT> static void addCopyRelSymbol(SharedSymbol *SS) {
+template <class ELFT> static void addCopyRelSymbol(SharedSymbol &SS) {
// Copy relocation against zero-sized symbol doesn't make sense.
- uint64_t SymSize = SS->getSize();
+ uint64_t SymSize = SS.getSize();
if (SymSize == 0)
- fatal("cannot create a copy relocation for symbol " + toString(*SS));
+ fatal("cannot create a copy relocation for symbol " + toString(SS));
// See if this symbol is in a read-only segment. If so, preserve the symbol's
// memory protection by reserving space in the .bss.rel.ro section.
bool IsReadOnly = isReadOnly<ELFT>(SS);
BssSection *Sec = make<BssSection>(IsReadOnly ? ".bss.rel.ro" : ".bss",
- SymSize, SS->Alignment);
+ SymSize, SS.Alignment);
if (IsReadOnly)
InX::BssRelRo->getParent()->addSection(Sec);
else
@@ -531,7 +531,7 @@ template <class ELFT> static void addCop
Sym->Used = true;
}
- InX::RelaDyn->addReloc({Target->CopyRel, Sec, 0, false, SS, 0});
+ InX::RelaDyn->addReloc({Target->CopyRel, Sec, 0, false, &SS, 0});
}
static void errorOrWarn(const Twine &Msg) {
@@ -631,7 +631,7 @@ static RelExpr adjustExpr(Symbol &Sym, R
"'; recompile with -fPIC or remove '-z nocopyreloc'" +
getLocation(S, Sym, RelOff));
- addCopyRelSymbol<ELFT>(B);
+ addCopyRelSymbol<ELFT>(*B);
}
IsConstant = true;
return Expr;
More information about the llvm-commits
mailing list