[lld] 427d359 - [lld-macho][NFC] Drop unnecessary macho:: namespace prefix on unambiguous references to Symbol
Greg McGary via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 30 14:58:50 PDT 2021
Author: Greg McGary
Date: 2021-03-30T14:58:35-07:00
New Revision: 427d3597219ec16c1bc92a0f4c9e39015e80c923
URL: https://github.com/llvm/llvm-project/commit/427d3597219ec16c1bc92a0f4c9e39015e80c923
DIFF: https://github.com/llvm/llvm-project/commit/427d3597219ec16c1bc92a0f4c9e39015e80c923.diff
LOG: [lld-macho][NFC] Drop unnecessary macho:: namespace prefix on unambiguous references to Symbol
Within `lld/macho/`, only `InputFiles.cpp` and `Symbols.h` require the `macho::` namespace qualifier to disambiguate references to `class Symbol`.
Add braces to outer `for` of a 5-level single-line `if`/`for` nest.
Differential Revision: https://reviews.llvm.org/D99555
Added:
Modified:
lld/MachO/Arch/ARM64.cpp
lld/MachO/Arch/X86_64.cpp
lld/MachO/Driver.cpp
lld/MachO/InputSection.cpp
lld/MachO/MapFile.cpp
lld/MachO/UnwindInfoSection.cpp
lld/MachO/Writer.cpp
Removed:
################################################################################
diff --git a/lld/MachO/Arch/ARM64.cpp b/lld/MachO/Arch/ARM64.cpp
index 14fcee290d128..55c688bc65b49 100644
--- a/lld/MachO/Arch/ARM64.cpp
+++ b/lld/MachO/Arch/ARM64.cpp
@@ -33,7 +33,7 @@ struct ARM64 : TargetInfo {
void relocateOne(uint8_t *loc, const Reloc &, uint64_t va,
uint64_t pc) const override;
- void writeStub(uint8_t *buf, const macho::Symbol &) const override;
+ void writeStub(uint8_t *buf, const Symbol &) const override;
void writeStubHelperHeader(uint8_t *buf) const override;
void writeStubHelperEntry(uint8_t *buf, const DylibSymbol &,
uint64_t entryAddr) const override;
@@ -217,7 +217,7 @@ static constexpr uint32_t stubCode[] = {
0xd61f0200, // 08: br x16
};
-void ARM64::writeStub(uint8_t *buf8, const macho::Symbol &sym) const {
+void ARM64::writeStub(uint8_t *buf8, const Symbol &sym) const {
auto *buf32 = reinterpret_cast<uint32_t *>(buf8);
uint64_t pcPageBits =
pageBits(in.stubs->addr + sym.stubsIndex * sizeof(stubCode));
diff --git a/lld/MachO/Arch/X86_64.cpp b/lld/MachO/Arch/X86_64.cpp
index d4bb841a571ff..44e7d37294a53 100644
--- a/lld/MachO/Arch/X86_64.cpp
+++ b/lld/MachO/Arch/X86_64.cpp
@@ -30,7 +30,7 @@ struct X86_64 : TargetInfo {
void relocateOne(uint8_t *loc, const Reloc &, uint64_t va,
uint64_t relocVA) const override;
- void writeStub(uint8_t *buf, const macho::Symbol &) const override;
+ void writeStub(uint8_t *buf, const Symbol &) const override;
void writeStubHelperHeader(uint8_t *buf) const override;
void writeStubHelperEntry(uint8_t *buf, const DylibSymbol &,
uint64_t entryAddr) const override;
@@ -138,7 +138,7 @@ static constexpr uint8_t stub[] = {
0xff, 0x25, 0, 0, 0, 0, // jmpq *__la_symbol_ptr(%rip)
};
-void X86_64::writeStub(uint8_t *buf, const macho::Symbol &sym) const {
+void X86_64::writeStub(uint8_t *buf, const Symbol &sym) const {
memcpy(buf, stub, 2); // just copy the two nonzero bytes
uint64_t stubAddr = in.stubs->addr + sym.stubsIndex * sizeof(stub);
writeRipRelative({&sym, "stub"}, buf, stubAddr, sizeof(stub),
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 96f8195aefe05..46ff984a0ef71 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -513,7 +513,7 @@ static void compileBitcodeFiles() {
// any CommonSymbols.
static void replaceCommonSymbols() {
TimeTraceScope timeScope("Replace common symbols");
- for (macho::Symbol *sym : symtab->getSymbols()) {
+ for (Symbol *sym : symtab->getSymbols()) {
auto *common = dyn_cast<CommonSymbol>(sym);
if (common == nullptr)
continue;
diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp
index 03d2fc54a5962..a925449bf89a2 100644
--- a/lld/MachO/InputSection.cpp
+++ b/lld/MachO/InputSection.cpp
@@ -34,8 +34,7 @@ uint64_t InputSection::getFileSize() const {
uint64_t InputSection::getVA() const { return parent->addr + outSecOff; }
-static uint64_t resolveSymbolVA(uint8_t *loc, const lld::macho::Symbol &sym,
- uint8_t type) {
+static uint64_t resolveSymbolVA(uint8_t *loc, const Symbol &sym, uint8_t type) {
const RelocAttrs &relocAttrs = target->getRelocAttrs(type);
if (relocAttrs.hasAttr(RelocAttrBits::BRANCH)) {
if (sym.isInStubs())
diff --git a/lld/MachO/MapFile.cpp b/lld/MachO/MapFile.cpp
index 621b52f7403e5..acc89e405a541 100644
--- a/lld/MachO/MapFile.cpp
+++ b/lld/MachO/MapFile.cpp
@@ -76,7 +76,7 @@ static std::vector<Defined *> getSymbols() {
// Construct a map from symbols to their stringified representations.
// Demangling symbols (which is what toString() does) is slow, so
// we do that in batch using parallel-for.
-static DenseMap<macho::Symbol *, std::string>
+static DenseMap<Symbol *, std::string>
getSymbolStrings(ArrayRef<Defined *> syms) {
std::vector<std::string> str(syms.size());
parallelForEachN(0, syms.size(), [&](size_t i) {
@@ -84,7 +84,7 @@ getSymbolStrings(ArrayRef<Defined *> syms) {
os << toString(*syms[i]);
});
- DenseMap<macho::Symbol *, std::string> ret;
+ DenseMap<Symbol *, std::string> ret;
for (size_t i = 0, e = syms.size(); i < e; ++i)
ret[syms[i]] = std::move(str[i]);
return ret;
@@ -126,7 +126,7 @@ void macho::writeMapFile() {
// Collect symbol info that we want to print out.
std::vector<Defined *> syms = getSymbols();
SymbolMapTy sectionSyms = getSectionSyms(syms);
- DenseMap<lld::macho::Symbol *, std::string> symStr = getSymbolStrings(syms);
+ DenseMap<Symbol *, std::string> symStr = getSymbolStrings(syms);
// Dump table of sections
os << "# Sections:\n";
@@ -144,7 +144,7 @@ void macho::writeMapFile() {
os << "# Symbols:\n";
os << "# Address\t File Name\n";
for (InputSection *isec : inputSections) {
- for (macho::Symbol *sym : sectionSyms[isec]) {
+ for (Symbol *sym : sectionSyms[isec]) {
os << format("0x%08llX\t[%3u] %s\n", sym->getVA(),
readerToFileOrdinal[sym->getFile()], symStr[sym].c_str());
}
diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp
index 0f26ea386cb60..ed7ae5785f782 100644
--- a/lld/MachO/UnwindInfoSection.cpp
+++ b/lld/MachO/UnwindInfoSection.cpp
@@ -100,7 +100,7 @@ bool UnwindInfoSection::isNeeded() const {
return (compactUnwindSection != nullptr);
}
-SmallDenseMap<std::pair<InputSection *, uint64_t /* addend */>, macho::Symbol *>
+SmallDenseMap<std::pair<InputSection *, uint64_t /* addend */>, Symbol *>
personalityTable;
// Compact unwind relocations have
diff erent semantics, so we handle them in a
@@ -118,7 +118,7 @@ void macho::prepareCompactUnwind(InputSection *isec) {
offsetof(struct CompactUnwindEntry64, personality))
continue;
- if (auto *s = r.referent.dyn_cast<lld::macho::Symbol *>()) {
+ if (auto *s = r.referent.dyn_cast<Symbol *>()) {
if (auto *undefined = dyn_cast<Undefined>(s)) {
treatUndefinedSymbol(*undefined);
// treatUndefinedSymbol() can replace s with a DylibSymbol; re-check.
@@ -127,7 +127,7 @@ void macho::prepareCompactUnwind(InputSection *isec) {
}
if (auto *defined = dyn_cast<Defined>(s)) {
// Check if we have created a synthetic symbol at the same address.
- macho::Symbol *&personality =
+ Symbol *&personality =
personalityTable[{defined->isec, defined->value}];
if (personality == nullptr) {
personality = defined;
@@ -146,7 +146,7 @@ void macho::prepareCompactUnwind(InputSection *isec) {
// Personality functions can be referenced via section relocations
// if they live in the same object file. Create placeholder synthetic
// symbols for them in the GOT.
- macho::Symbol *&s = personalityTable[{referentIsec, r.addend}];
+ Symbol *&s = personalityTable[{referentIsec, r.addend}];
if (s == nullptr) {
s = make<Defined>("<internal>", nullptr, referentIsec, r.addend, false,
false, false);
@@ -181,7 +181,7 @@ static void relocateCompactUnwind(MergedOutputSection *compactUnwindSection,
for (const Reloc &r : isec->relocs) {
uint64_t referentVA = 0;
- if (auto *referentSym = r.referent.dyn_cast<macho::Symbol *>()) {
+ if (auto *referentSym = r.referent.dyn_cast<Symbol *>()) {
if (!isa<Undefined>(referentSym)) {
assert(referentSym->isInGot());
if (auto *defined = dyn_cast<Defined>(referentSym))
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index 38a6627b63e93..aa85aa3cc268f 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -484,8 +484,8 @@ static bool needsBinding(const Symbol *sym) {
return false;
}
-static void prepareSymbolRelocation(lld::macho::Symbol *sym,
- const InputSection *isec, const Reloc &r) {
+static void prepareSymbolRelocation(Symbol *sym, const InputSection *isec,
+ const Reloc &r) {
const RelocAttrs &relocAttrs = target->getRelocAttrs(r.type);
if (relocAttrs.hasAttr(RelocAttrBits::BRANCH)) {
@@ -520,10 +520,10 @@ void Writer::scanRelocations() {
// minuend, and doesn't have the usual UNSIGNED semantics. We don't want
// to emit rebase opcodes for it.
it = std::next(it);
- assert(isa<Defined>(it->referent.dyn_cast<lld::macho::Symbol *>()));
+ assert(isa<Defined>(it->referent.dyn_cast<Symbol *>()));
continue;
}
- if (auto *sym = r.referent.dyn_cast<lld::macho::Symbol *>()) {
+ if (auto *sym = r.referent.dyn_cast<Symbol *>()) {
if (auto *undefined = dyn_cast<Undefined>(sym))
treatUndefinedSymbol(*undefined);
// treatUndefinedSymbol() can replace sym with a DylibSymbol; re-check.
@@ -540,7 +540,7 @@ void Writer::scanRelocations() {
void Writer::scanSymbols() {
TimeTraceScope timeScope("Scan symbols");
- for (const macho::Symbol *sym : symtab->getSymbols()) {
+ for (const Symbol *sym : symtab->getSymbols()) {
if (const auto *defined = dyn_cast<Defined>(sym)) {
if (defined->overridesWeakDef)
in.weakBinding->addNonWeakDefinition(defined);
@@ -660,11 +660,12 @@ static DenseMap<const InputSection *, size_t> buildInputSectionPriorities() {
};
// TODO: Make sure this handles weak symbols correctly.
- for (const InputFile *file : inputFiles)
+ for (const InputFile *file : inputFiles) {
if (isa<ObjFile>(file))
- for (lld::macho::Symbol *sym : file->symbols)
+ for (Symbol *sym : file->symbols)
if (auto *d = dyn_cast<Defined>(sym))
addSym(*d);
+ }
return sectionPriorities;
}
More information about the llvm-commits
mailing list