Skip to content

Commit

Permalink
Avoid identifiers that are different only in case. NFC.
Browse files Browse the repository at this point in the history
Some variables in lld have the same name as functions ignoring case.
This patch gives them different names, so that my next patch is easier
to read.

llvm-svn: 365003
  • Loading branch information
rui314 committed Jul 3, 2019
1 parent c22e772 commit 11ae59f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 35 deletions.
6 changes: 3 additions & 3 deletions lld/ELF/DWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ namespace {
template <class RelTy> struct LLDRelocationResolver {
// In the ELF ABIs, S sepresents the value of the symbol in the relocation
// entry. For Rela, the addend is stored as part of the relocation entry.
static uint64_t Resolve(object::RelocationRef Ref, uint64_t S,
static uint64_t resolve(object::RelocationRef Ref, uint64_t S,
uint64_t /* A */) {
return S + Ref.getRawDataRefImpl().p;
}
};

template <class ELFT> struct LLDRelocationResolver<Elf_Rel_Impl<ELFT, false>> {
// For Rel, the addend A is supplied by the caller.
static uint64_t Resolve(object::RelocationRef /*Ref*/, uint64_t S,
static uint64_t resolve(object::RelocationRef /*Ref*/, uint64_t S,
uint64_t A) {
return S + A;
}
Expand Down Expand Up @@ -110,7 +110,7 @@ LLDDwarfObj<ELFT>::findAux(const InputSectionBase &Sec, uint64_t Pos,
DataRefImpl D;
D.p = getAddend<ELFT>(Rel);
return RelocAddrEntry{SecIndex, RelocationRef(D, nullptr),
LLDRelocationResolver<RelTy>::Resolve, Val};
LLDRelocationResolver<RelTy>::resolve, Val};
}

template <class ELFT>
Expand Down
10 changes: 5 additions & 5 deletions lld/ELF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static ELFKind getELFKind(MemoryBufferRef MB, StringRef ArchiveName) {
unsigned char Endian;
std::tie(Size, Endian) = getElfArchType(MB.getBuffer());

auto Fatal = [&](StringRef Msg) {
auto Report = [&](StringRef Msg) {
StringRef Filename = MB.getBufferIdentifier();
if (ArchiveName.empty())
fatal(Filename + ": " + Msg);
Expand All @@ -64,16 +64,16 @@ static ELFKind getELFKind(MemoryBufferRef MB, StringRef ArchiveName) {
};

if (!MB.getBuffer().startswith(ElfMagic))
Fatal("not an ELF file");
Report("not an ELF file");
if (Endian != ELFDATA2LSB && Endian != ELFDATA2MSB)
Fatal("corrupted ELF file: invalid data encoding");
Report("corrupted ELF file: invalid data encoding");
if (Size != ELFCLASS32 && Size != ELFCLASS64)
Fatal("corrupted ELF file: invalid file class");
Report("corrupted ELF file: invalid file class");

size_t BufSize = MB.getBuffer().size();
if ((Size == ELFCLASS32 && BufSize < sizeof(Elf32_Ehdr)) ||
(Size == ELFCLASS64 && BufSize < sizeof(Elf64_Ehdr)))
Fatal("corrupted ELF file: file is too short");
Report("corrupted ELF file: file is too short");

if (Size == ELFCLASS32)
return (Endian == ELFDATA2LSB) ? ELF32LEKind : ELF32BEKind;
Expand Down
8 changes: 4 additions & 4 deletions lld/ELF/Relocations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,10 @@ template <class ELFT> static void addCopyRelSymbol(SharedSymbol &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);
if (IsReadOnly)
bool IsRO = isReadOnly<ELFT>(SS);
BssSection *Sec =
make<BssSection>(IsRO ? ".bss.rel.ro" : ".bss", SymSize, SS.Alignment);
if (IsRO)
In.BssRelRo->getParent()->addSection(Sec);
else
In.Bss->getParent()->addSection(Sec);
Expand Down
32 changes: 15 additions & 17 deletions lld/ELF/ScriptParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ using namespace llvm::support::endian;
using namespace lld;
using namespace lld::elf;

static bool isUnderSysroot(StringRef Path);

namespace {
class ScriptParser final : ScriptLexer {
public:
ScriptParser(MemoryBufferRef MB)
: ScriptLexer(MB),
IsUnderSysroot(isUnderSysroot(MB.getBufferIdentifier())) {}
ScriptParser(MemoryBufferRef MB) : ScriptLexer(MB) {
// Initialize IsUnderSysroot
if (Config->Sysroot == "")
return;
StringRef Path = MB.getBufferIdentifier();
for (; !Path.empty(); Path = sys::path::parent_path(Path)) {
if (!sys::fs::equivalent(Config->Sysroot, Path))
continue;
IsUnderSysroot = true;
return;
}
}

void readLinkerScript();
void readVersionScript();
Expand Down Expand Up @@ -118,7 +125,7 @@ class ScriptParser final : ScriptLexer {
readSymbols();

// True if a script being read is in a subdirectory specified by -sysroot.
bool IsUnderSysroot;
bool IsUnderSysroot = false;

// A set to detect an INCLUDE() cycle.
StringSet<> Seen;
Expand All @@ -131,15 +138,6 @@ static StringRef unquote(StringRef S) {
return S;
}

static bool isUnderSysroot(StringRef Path) {
if (Config->Sysroot == "")
return false;
for (; !Path.empty(); Path = sys::path::parent_path(Path))
if (sys::fs::equivalent(Config->Sysroot, Path))
return true;
return false;
}

// Some operations only support one non absolute value. Move the
// absolute one to the right hand side for convenience.
static void moveAbsRight(ExprValue &A, ExprValue &B) {
Expand Down Expand Up @@ -1449,8 +1447,8 @@ std::vector<SymbolVersion> ScriptParser::readVersionExtern() {
std::vector<SymbolVersion> Ret;
while (!errorCount() && peek() != "}") {
StringRef Tok = next();
bool HasWildcard = !Tok.startswith("\"") && hasWildcard(Tok);
Ret.push_back({unquote(Tok), IsCXX, HasWildcard});
Ret.push_back(
{unquote(Tok), IsCXX, !Tok.startswith("\"") && hasWildcard(Tok)});
if (consume("}"))
return Ret;
expect(";");
Expand Down
12 changes: 6 additions & 6 deletions lld/ELF/Symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,18 @@ void elf::maybeWarnUnorderableSymbol(const Symbol *Sym) {
const InputFile *File = Sym->File;
auto *D = dyn_cast<Defined>(Sym);

auto Warn = [&](StringRef S) { warn(toString(File) + S + Sym->getName()); };
auto Report = [&](StringRef S) { warn(toString(File) + S + Sym->getName()); };

if (Sym->isUndefined())
Warn(": unable to order undefined symbol: ");
Report(": unable to order undefined symbol: ");
else if (Sym->isShared())
Warn(": unable to order shared symbol: ");
Report(": unable to order shared symbol: ");
else if (D && !D->Section)
Warn(": unable to order absolute symbol: ");
Report(": unable to order absolute symbol: ");
else if (D && isa<OutputSection>(D->Section))
Warn(": unable to order synthetic symbol: ");
Report(": unable to order synthetic symbol: ");
else if (D && !D->Section->Repl->isLive())
Warn(": unable to order discarded symbol: ");
Report(": unable to order discarded symbol: ");
}

// Returns a symbol for an error message.
Expand Down

0 comments on commit 11ae59f

Please sign in to comment.