Skip to content

Commit bd8cfe6

Browse files
committed
[ELF] Wrap things in namespace lld { namespace elf {, NFC
This makes it clear `ELF/**/*.cpp` files define things in the `lld::elf` namespace and simplifies `elf::foo` to `foo`. Reviewed By: atanasyan, grimar, ruiu Differential Revision: https://reviews.llvm.org/D68323 llvm-svn: 373885
1 parent 5761e3c commit bd8cfe6

37 files changed

+439
-341
lines changed

lld/ELF/Arch/AArch64.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
using namespace llvm;
1818
using namespace llvm::support::endian;
1919
using namespace llvm::ELF;
20-
using namespace lld;
21-
using namespace lld::elf;
20+
21+
namespace lld {
22+
namespace elf {
2223

2324
// Page(Expr) is the page address of the expression Expr, defined
2425
// as (Expr & ~0xFFF). (This applies even if the machine page size
2526
// supported by the platform has a different value.)
26-
uint64_t elf::getAArch64Page(uint64_t expr) {
27+
uint64_t getAArch64Page(uint64_t expr) {
2728
return expr & ~static_cast<uint64_t>(0xFFF);
2829
}
2930

@@ -679,4 +680,7 @@ static TargetInfo *getTargetInfo() {
679680
return &t;
680681
}
681682

682-
TargetInfo *elf::getAArch64TargetInfo() { return getTargetInfo(); }
683+
TargetInfo *getAArch64TargetInfo() { return getTargetInfo(); }
684+
685+
} // namespace elf
686+
} // namespace lld

lld/ELF/Arch/AMDGPU.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ using namespace llvm;
1717
using namespace llvm::object;
1818
using namespace llvm::support::endian;
1919
using namespace llvm::ELF;
20-
using namespace lld;
21-
using namespace lld::elf;
20+
21+
namespace lld {
22+
namespace elf {
2223

2324
namespace {
2425
class AMDGPU final : public TargetInfo {
@@ -107,7 +108,10 @@ RelType AMDGPU::getDynRel(RelType type) const {
107108
return R_AMDGPU_NONE;
108109
}
109110

110-
TargetInfo *elf::getAMDGPUTargetInfo() {
111+
TargetInfo *getAMDGPUTargetInfo() {
111112
static AMDGPU target;
112113
return &target;
113114
}
115+
116+
} // namespace elf
117+
} // namespace lld

lld/ELF/Arch/ARM.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
using namespace llvm;
1919
using namespace llvm::support::endian;
2020
using namespace llvm::ELF;
21-
using namespace lld;
22-
using namespace lld::elf;
21+
22+
namespace lld {
23+
namespace elf {
2324

2425
namespace {
2526
class ARM final : public TargetInfo {
@@ -600,7 +601,10 @@ int64_t ARM::getImplicitAddend(const uint8_t *buf, RelType type) const {
600601
}
601602
}
602603

603-
TargetInfo *elf::getARMTargetInfo() {
604+
TargetInfo *getARMTargetInfo() {
604605
static ARM target;
605606
return &target;
606607
}
608+
609+
} // namespace elf
610+
} // namespace lld

lld/ELF/Arch/AVR.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ using namespace llvm;
3636
using namespace llvm::object;
3737
using namespace llvm::support::endian;
3838
using namespace llvm::ELF;
39-
using namespace lld;
40-
using namespace lld::elf;
39+
40+
namespace lld {
41+
namespace elf {
4142

4243
namespace {
4344
class AVR final : public TargetInfo {
@@ -70,7 +71,10 @@ void AVR::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {
7071
}
7172
}
7273

73-
TargetInfo *elf::getAVRTargetInfo() {
74+
TargetInfo *getAVRTargetInfo() {
7475
static AVR target;
7576
return &target;
7677
}
78+
79+
} // namespace elf
80+
} // namespace lld

lld/ELF/Arch/Hexagon.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ using namespace llvm;
1919
using namespace llvm::object;
2020
using namespace llvm::support::endian;
2121
using namespace llvm::ELF;
22-
using namespace lld;
23-
using namespace lld::elf;
22+
23+
namespace lld {
24+
namespace elf {
2425

2526
namespace {
2627
class Hexagon final : public TargetInfo {
@@ -318,7 +319,10 @@ RelType Hexagon::getDynRel(RelType type) const {
318319
return R_HEX_NONE;
319320
}
320321

321-
TargetInfo *elf::getHexagonTargetInfo() {
322+
TargetInfo *getHexagonTargetInfo() {
322323
static Hexagon target;
323324
return &target;
324325
}
326+
327+
} // namespace elf
328+
} // namespace lld

lld/ELF/Arch/MSP430.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ using namespace llvm;
2626
using namespace llvm::object;
2727
using namespace llvm::support::endian;
2828
using namespace llvm::ELF;
29-
using namespace lld;
30-
using namespace lld::elf;
29+
30+
namespace lld {
31+
namespace elf {
3132

3233
namespace {
3334
class MSP430 final : public TargetInfo {
@@ -87,7 +88,10 @@ void MSP430::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {
8788
}
8889
}
8990

90-
TargetInfo *elf::getMSP430TargetInfo() {
91+
TargetInfo *getMSP430TargetInfo() {
9192
static MSP430 target;
9293
return &target;
9394
}
95+
96+
} // namespace elf
97+
} // namespace lld

lld/ELF/Arch/Mips.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
using namespace llvm;
1919
using namespace llvm::object;
2020
using namespace llvm::ELF;
21-
using namespace lld;
22-
using namespace lld::elf;
2321

22+
namespace lld {
23+
namespace elf {
2424
namespace {
2525
template <class ELFT> class MIPS final : public TargetInfo {
2626
public:
@@ -721,7 +721,7 @@ template <class ELFT> bool MIPS<ELFT>::usesOnlyLowPageBits(RelType type) const {
721721
}
722722

723723
// Return true if the symbol is a PIC function.
724-
template <class ELFT> bool elf::isMipsPIC(const Defined *sym) {
724+
template <class ELFT> bool isMipsPIC(const Defined *sym) {
725725
if (!sym->isFunc())
726726
return false;
727727

@@ -739,17 +739,20 @@ template <class ELFT> bool elf::isMipsPIC(const Defined *sym) {
739739
return file->getObj().getHeader()->e_flags & EF_MIPS_PIC;
740740
}
741741

742-
template <class ELFT> TargetInfo *elf::getMipsTargetInfo() {
742+
template <class ELFT> TargetInfo *getMipsTargetInfo() {
743743
static MIPS<ELFT> target;
744744
return &target;
745745
}
746746

747-
template TargetInfo *elf::getMipsTargetInfo<ELF32LE>();
748-
template TargetInfo *elf::getMipsTargetInfo<ELF32BE>();
749-
template TargetInfo *elf::getMipsTargetInfo<ELF64LE>();
750-
template TargetInfo *elf::getMipsTargetInfo<ELF64BE>();
747+
template TargetInfo *getMipsTargetInfo<ELF32LE>();
748+
template TargetInfo *getMipsTargetInfo<ELF32BE>();
749+
template TargetInfo *getMipsTargetInfo<ELF64LE>();
750+
template TargetInfo *getMipsTargetInfo<ELF64BE>();
751751

752-
template bool elf::isMipsPIC<ELF32LE>(const Defined *);
753-
template bool elf::isMipsPIC<ELF32BE>(const Defined *);
754-
template bool elf::isMipsPIC<ELF64LE>(const Defined *);
755-
template bool elf::isMipsPIC<ELF64BE>(const Defined *);
752+
template bool isMipsPIC<ELF32LE>(const Defined *);
753+
template bool isMipsPIC<ELF32BE>(const Defined *);
754+
template bool isMipsPIC<ELF64LE>(const Defined *);
755+
template bool isMipsPIC<ELF64BE>(const Defined *);
756+
757+
} // namespace elf
758+
} // namespace lld

lld/ELF/Arch/MipsArchTree.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ using namespace llvm;
2323
using namespace llvm::object;
2424
using namespace llvm::ELF;
2525

26-
using namespace lld;
27-
using namespace lld::elf;
26+
namespace lld {
27+
namespace elf {
2828

2929
namespace {
3030
struct ArchTreeEdge {
@@ -294,7 +294,7 @@ static uint32_t getArchFlags(ArrayRef<FileFlags> files) {
294294
return ret;
295295
}
296296

297-
template <class ELFT> uint32_t elf::calcMipsEFlags() {
297+
template <class ELFT> uint32_t calcMipsEFlags() {
298298
std::vector<FileFlags> v;
299299
for (InputFile *f : objectFiles)
300300
v.push_back({f, cast<ObjFile<ELFT>>(f)->getObj().getHeader()->e_flags});
@@ -350,8 +350,7 @@ static StringRef getMipsFpAbiName(uint8_t fpAbi) {
350350
}
351351
}
352352

353-
uint8_t elf::getMipsFpAbiFlag(uint8_t oldFlag, uint8_t newFlag,
354-
StringRef fileName) {
353+
uint8_t getMipsFpAbiFlag(uint8_t oldFlag, uint8_t newFlag, StringRef fileName) {
355354
if (compareMipsFpAbi(newFlag, oldFlag) >= 0)
356355
return newFlag;
357356
if (compareMipsFpAbi(oldFlag, newFlag) < 0)
@@ -367,7 +366,7 @@ template <class ELFT> static bool isN32Abi(const InputFile *f) {
367366
return false;
368367
}
369368

370-
bool elf::isMipsN32Abi(const InputFile *f) {
369+
bool isMipsN32Abi(const InputFile *f) {
371370
switch (config->ekind) {
372371
case ELF32LEKind:
373372
return isN32Abi<ELF32LE>(f);
@@ -382,14 +381,17 @@ bool elf::isMipsN32Abi(const InputFile *f) {
382381
}
383382
}
384383

385-
bool elf::isMicroMips() { return config->eflags & EF_MIPS_MICROMIPS; }
384+
bool isMicroMips() { return config->eflags & EF_MIPS_MICROMIPS; }
386385

387-
bool elf::isMipsR6() {
386+
bool isMipsR6() {
388387
uint32_t arch = config->eflags & EF_MIPS_ARCH;
389388
return arch == EF_MIPS_ARCH_32R6 || arch == EF_MIPS_ARCH_64R6;
390389
}
391390

392-
template uint32_t elf::calcMipsEFlags<ELF32LE>();
393-
template uint32_t elf::calcMipsEFlags<ELF32BE>();
394-
template uint32_t elf::calcMipsEFlags<ELF64LE>();
395-
template uint32_t elf::calcMipsEFlags<ELF64BE>();
391+
template uint32_t calcMipsEFlags<ELF32LE>();
392+
template uint32_t calcMipsEFlags<ELF32BE>();
393+
template uint32_t calcMipsEFlags<ELF64LE>();
394+
template uint32_t calcMipsEFlags<ELF64BE>();
395+
396+
} // namespace elf
397+
} // namespace lld

lld/ELF/Arch/PPC.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
using namespace llvm;
1717
using namespace llvm::support::endian;
1818
using namespace llvm::ELF;
19-
using namespace lld;
20-
using namespace lld::elf;
19+
20+
namespace lld {
21+
namespace elf {
2122

2223
namespace {
2324
class PPC final : public TargetInfo {
@@ -61,7 +62,7 @@ static void writeFromHalf16(uint8_t *loc, uint32_t insn) {
6162
write32(config->isLE ? loc : loc - 2, insn);
6263
}
6364

64-
void elf::writePPC32GlinkSection(uint8_t *buf, size_t numEntries) {
65+
void writePPC32GlinkSection(uint8_t *buf, size_t numEntries) {
6566
// On PPC Secure PLT ABI, bl foo@plt jumps to a call stub, which loads an
6667
// absolute address from a specific .plt slot (usually called .got.plt on
6768
// other targets) and jumps there.
@@ -435,7 +436,10 @@ void PPC::relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const {
435436
}
436437
}
437438

438-
TargetInfo *elf::getPPCTargetInfo() {
439+
TargetInfo *getPPCTargetInfo() {
439440
static PPC target;
440441
return &target;
441442
}
443+
444+
} // namespace elf
445+
} // namespace lld

lld/ELF/Arch/PPC64.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ using namespace llvm;
1616
using namespace llvm::object;
1717
using namespace llvm::support::endian;
1818
using namespace llvm::ELF;
19-
using namespace lld;
20-
using namespace lld::elf;
19+
20+
namespace lld {
21+
namespace elf {
2122

2223
static uint64_t ppc64TocOffset = 0x8000;
2324
static uint64_t dynamicThreadPointerOffset = 0x8000;
@@ -59,7 +60,7 @@ enum DFormOpcd {
5960
ADDI = 14
6061
};
6162

62-
uint64_t elf::getPPC64TocBase() {
63+
uint64_t getPPC64TocBase() {
6364
// The TOC consists of sections .got, .toc, .tocbss, .plt in that order. The
6465
// TOC starts where the first of these sections starts. We always create a
6566
// .got when we see a relocation that uses it, so for us the start is always
@@ -73,7 +74,7 @@ uint64_t elf::getPPC64TocBase() {
7374
return tocVA + ppc64TocOffset;
7475
}
7576

76-
unsigned elf::getPPC64GlobalEntryToLocalEntryOffset(uint8_t stOther) {
77+
unsigned getPPC64GlobalEntryToLocalEntryOffset(uint8_t stOther) {
7778
// The offset is encoded into the 3 most significant bits of the st_other
7879
// field, with some special values described in section 3.4.1 of the ABI:
7980
// 0 --> Zero offset between the GEP and LEP, and the function does NOT use
@@ -98,7 +99,7 @@ unsigned elf::getPPC64GlobalEntryToLocalEntryOffset(uint8_t stOther) {
9899
return 0;
99100
}
100101

101-
bool elf::isPPC64SmallCodeModelTocReloc(RelType type) {
102+
bool isPPC64SmallCodeModelTocReloc(RelType type) {
102103
// The only small code model relocations that access the .toc section.
103104
return type == R_PPC64_TOC16 || type == R_PPC64_TOC16_DS;
104105
}
@@ -153,8 +154,8 @@ getRelaTocSymAndAddend(InputSectionBase *tocSec, uint64_t offset) {
153154
// ld/lwa 3, 0(3) # load the value from the address
154155
//
155156
// Returns true if the relaxation is performed.
156-
bool elf::tryRelaxPPC64TocIndirection(RelType type, const Relocation &rel,
157-
uint8_t *bufLoc) {
157+
bool tryRelaxPPC64TocIndirection(RelType type, const Relocation &rel,
158+
uint8_t *bufLoc) {
158159
assert(config->tocOptimize);
159160
if (rel.addend < 0)
160161
return false;
@@ -458,7 +459,7 @@ void PPC64::relaxTlsLdToLe(uint8_t *loc, RelType type, uint64_t val) const {
458459
}
459460
}
460461

461-
unsigned elf::getPPCDFormOp(unsigned secondaryOp) {
462+
unsigned getPPCDFormOp(unsigned secondaryOp) {
462463
switch (secondaryOp) {
463464
case LBZX:
464465
return LBZ;
@@ -1093,7 +1094,10 @@ bool PPC64::adjustPrologueForCrossSplitStack(uint8_t *loc, uint8_t *end,
10931094
return true;
10941095
}
10951096

1096-
TargetInfo *elf::getPPC64TargetInfo() {
1097+
TargetInfo *getPPC64TargetInfo() {
10971098
static PPC64 target;
10981099
return &target;
10991100
}
1101+
1102+
} // namespace elf
1103+
} // namespace lld

0 commit comments

Comments
 (0)