diff --git a/lld/lib/Driver/GnuLdDriver.cpp b/lld/lib/Driver/GnuLdDriver.cpp index 6933b3e4d2fb..14f6cb5061f2 100644 --- a/lld/lib/Driver/GnuLdDriver.cpp +++ b/lld/lib/Driver/GnuLdDriver.cpp @@ -68,9 +68,11 @@ public: GnuLdOptTable() : OptTable(infoTable, llvm::array_lengthof(infoTable)){} }; +} // anonymous namespace + // Get the Input file magic for creating appropriate InputGraph nodes. -error_code getFileMagic(ELFLinkingContext &ctx, StringRef path, - llvm::sys::fs::file_magic &magic) { +static error_code getFileMagic(ELFLinkingContext &ctx, StringRef path, + llvm::sys::fs::file_magic &magic) { error_code ec = llvm::sys::fs::identify_magic(path, magic); if (ec) return ec; @@ -86,8 +88,6 @@ error_code getFileMagic(ELFLinkingContext &ctx, StringRef path, return make_error_code(ReaderError::unknown_file_format); } -} // namespace - llvm::ErrorOr ELFFileNode::getPath(const LinkingContext &) const { if (!_isDashlPrefix) return _path; diff --git a/lld/lib/Driver/UniversalDriver.cpp b/lld/lib/Driver/UniversalDriver.cpp index 5caf55165253..e653ee14bd13 100644 --- a/lld/lib/Driver/UniversalDriver.cpp +++ b/lld/lib/Driver/UniversalDriver.cpp @@ -74,23 +74,25 @@ enum class Flavor { core // -flavor core OR -core }; -Flavor strToFlavor(StringRef str) { - return llvm::StringSwitch(str) - .Case("gnu", Flavor::gnu_ld) - .Case("link", Flavor::win_link) - .Case("lld-link", Flavor::win_link) - .Case("darwin", Flavor::darwin_ld) - .Case("core", Flavor::core) - .Case("ld", Flavor::gnu_ld) // deprecated - .Default(Flavor::invalid); -} - struct ProgramNameParts { StringRef _target; StringRef _flavor; }; -ProgramNameParts parseProgramName(StringRef programName) { +} // anonymous namespace + +static Flavor strToFlavor(StringRef str) { + return llvm::StringSwitch(str) + .Case("gnu", Flavor::gnu_ld) + .Case("link", Flavor::win_link) + .Case("lld-link", Flavor::win_link) + .Case("darwin", Flavor::darwin_ld) + .Case("core", Flavor::core) + .Case("ld", Flavor::gnu_ld) // deprecated + .Default(Flavor::invalid); +} + +static ProgramNameParts parseProgramName(StringRef programName) { SmallVector components; llvm::SplitString(programName, components, "-"); ProgramNameParts ret; @@ -120,9 +122,8 @@ ProgramNameParts parseProgramName(StringRef programName) { return ret; } -} // namespace - namespace lld { + bool UniversalDriver::link(int argc, const char *argv[], raw_ostream &diagnostics) { // Parse command line options using GnuLdOptions.td @@ -181,4 +182,5 @@ bool UniversalDriver::link(int argc, const char *argv[], } llvm_unreachable("Unrecognised flavor"); } + } // end namespace lld diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp index 5cccb6fa812c..0cc5630bb6f8 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp @@ -17,10 +17,7 @@ using namespace lld; using namespace elf; using namespace llvm::ELF; -namespace { - -inline -void applyReloc(uint8_t *loc, uint32_t result, uint32_t mask) { +static inline void applyReloc(uint8_t *loc, uint32_t result, uint32_t mask) { auto target = reinterpret_cast(loc); *target = (uint32_t(*target) & ~mask) | (result & mask); } @@ -33,20 +30,20 @@ template inline T signExtend(T val) { /// \brief R_MIPS_32 /// local/external: word32 S + A (truncate) -void reloc32(uint8_t *location, uint64_t P, uint64_t S, int64_t A) { +static void reloc32(uint8_t *location, uint64_t P, uint64_t S, int64_t A) { applyReloc(location, S + A, 0xffffffff); } /// \brief R_MIPS_26 /// local : ((A | ((P + 4) & 0x3F000000)) + S) >> 2 -void reloc26loc(uint8_t *location, uint64_t P, uint64_t S, int32_t A) { +static void reloc26loc(uint8_t *location, uint64_t P, uint64_t S, int32_t A) { uint32_t result = ((A << 2) | ((P + 4) & 0x3f000000)) + S; applyReloc(location, result >> 2, 0x03ffffff); } /// \brief LLD_R_MIPS_GLOBAL_26 /// external: (sign-extend(A) + S) >> 2 -void reloc26ext(uint8_t *location, uint64_t S, int32_t A) { +static void reloc26ext(uint8_t *location, uint64_t S, int32_t A) { uint32_t result = signExtend<28>(A << 2) + S; applyReloc(location, result >> 2, 0x03ffffff); } @@ -54,8 +51,8 @@ void reloc26ext(uint8_t *location, uint64_t S, int32_t A) { /// \brief R_MIPS_HI16 /// local/external: hi16 (AHL + S) - (short)(AHL + S) (truncate) /// _gp_disp : hi16 (AHL + GP - P) - (short)(AHL + GP - P) (verify) -void relocHi16(uint8_t *location, uint64_t P, uint64_t S, int64_t AHL, - uint64_t GP, bool isGPDisp) { +static void relocHi16(uint8_t *location, uint64_t P, uint64_t S, int64_t AHL, + uint64_t GP, bool isGPDisp) { int32_t result = 0; if (isGPDisp) @@ -69,8 +66,8 @@ void relocHi16(uint8_t *location, uint64_t P, uint64_t S, int64_t AHL, /// \brief R_MIPS_LO16 /// local/external: lo16 AHL + S (truncate) /// _gp_disp : lo16 AHL + GP - P + 4 (verify) -void relocLo16(uint8_t *location, uint64_t P, uint64_t S, int64_t AHL, - uint64_t GP, bool isGPDisp) { +static void relocLo16(uint8_t *location, uint64_t P, uint64_t S, int64_t AHL, + uint64_t GP, bool isGPDisp) { int32_t result = 0; if (isGPDisp) @@ -83,8 +80,8 @@ void relocLo16(uint8_t *location, uint64_t P, uint64_t S, int64_t AHL, /// \brief R_MIPS_GOT16 /// local/external: rel16 G (verify) -void relocGOT16(uint8_t *location, uint64_t P, uint64_t S, int64_t AHL, - uint64_t GP) { +static void relocGOT16(uint8_t *location, uint64_t P, uint64_t S, int64_t AHL, + uint64_t GP) { // FIXME (simon): for local sym put high 16 bit of AHL to the GOT int32_t G = (int32_t)(S - GP); applyReloc(location, G, 0xffff); @@ -92,29 +89,27 @@ void relocGOT16(uint8_t *location, uint64_t P, uint64_t S, int64_t AHL, /// \brief R_MIPS_CALL16 /// external: rel16 G (verify) -void relocCall16(uint8_t *location, uint64_t P, uint64_t S, int64_t A, - uint64_t GP) { +static void relocCall16(uint8_t *location, uint64_t P, uint64_t S, int64_t A, + uint64_t GP) { int32_t G = (int32_t)(S - GP); applyReloc(location, G, 0xffff); } /// \brief LLD_R_MIPS_32_HI16 -void reloc32hi16(uint8_t *location, uint64_t S, int64_t A) { +static void reloc32hi16(uint8_t *location, uint64_t S, int64_t A) { applyReloc(location, (S + A) & 0xffff0000, 0xffffffff); } /// \brief LLD_R_MIPS_HI16 -void relocLldHi16(uint8_t *location, uint64_t S) { +static void relocLldHi16(uint8_t *location, uint64_t S) { applyReloc(location, (S + 0x8000) >> 16, 0xffff); } /// \brief LLD_R_MIPS_LO16 -void relocLldLo16(uint8_t *location, uint64_t S) { +static void relocLldLo16(uint8_t *location, uint64_t S) { applyReloc(location, S, 0xffff); } -} // end anon namespace - error_code MipsTargetRelocationHandler::applyRelocation( ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom, const Reference &ref) const { diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp index ee2ab033ca5c..efcd00cb8749 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp @@ -13,20 +13,18 @@ #include "Atoms.h" #include "MipsELFFile.h" -namespace { - using namespace lld; using namespace lld::elf; using namespace llvm::ELF; // Lazy resolver -const uint8_t mipsGot0AtomContent[] = { 0x00, 0x00, 0x00, 0x00 }; +static const uint8_t mipsGot0AtomContent[] = { 0x00, 0x00, 0x00, 0x00 }; // Module pointer -const uint8_t mipsGotModulePointerAtomContent[] = { 0x00, 0x00, 0x00, 0x80 }; +static const uint8_t mipsGotModulePointerAtomContent[] = { 0x00, 0x00, 0x00, 0x80 }; // PLT0 entry -const uint8_t mipsPlt0AtomContent[] = { +static const uint8_t mipsPlt0AtomContent[] = { 0x00, 0x00, 0x1c, 0x3c, // lui $28, %hi(&GOTPLT[0]) 0x00, 0x00, 0x99, 0x8f, // lw $25, %lo(&GOTPLT[0])($28) 0x00, 0x00, 0x9c, 0x27, // addiu $28, $28, %lo(&GOTPLT[0]) @@ -38,7 +36,7 @@ const uint8_t mipsPlt0AtomContent[] = { }; // Regular PLT entry -const uint8_t mipsPltAAtomContent[] = { +static const uint8_t mipsPltAAtomContent[] = { 0x00, 0x00, 0x0f, 0x3c, // lui $15, %hi(.got.plt entry) 0x00, 0x00, 0xf9, 0x8d, // l[wd] $25, %lo(.got.plt entry)($15) 0x08, 0x00, 0x20, 0x03, // jr $25 @@ -46,13 +44,15 @@ const uint8_t mipsPltAAtomContent[] = { }; // LA25 stub entry -const uint8_t mipsLA25AtomContent[] = { +static const uint8_t mipsLA25AtomContent[] = { 0x00, 0x00, 0x19, 0x3c, // lui $25, %hi(func) 0x00, 0x00, 0x00, 0x08, // j func 0x00, 0x00, 0x39, 0x27, // addiu $25, $25, %lo(func) 0x00, 0x00, 0x00, 0x00 // nop }; +namespace { + /// \brief Abstract base class represent MIPS GOT entries. class MipsGOTAtom : public GOTAtom { public: diff --git a/lld/unittests/DriverTests/DarwinLdDriverTest.cpp b/lld/unittests/DriverTests/DarwinLdDriverTest.cpp index 33d936717f58..761face8a5d0 100644 --- a/lld/unittests/DriverTests/DarwinLdDriverTest.cpp +++ b/lld/unittests/DriverTests/DarwinLdDriverTest.cpp @@ -22,12 +22,12 @@ using namespace llvm; using namespace lld; namespace { - class DarwinLdParserTest : public ParserTest { protected: const LinkingContext *linkingContext() override { return &_context; } }; +} TEST_F(DarwinLdParserTest, Basic) { EXPECT_TRUE(parse("ld", "foo.o", "bar.o", nullptr)); @@ -229,6 +229,3 @@ TEST_F(DarwinLdParserTest, llvmOptions) { EXPECT_EQ(strcmp(options[0],"-debug-only"), 0); EXPECT_EQ(strcmp(options[1],"foo"), 0); } - - -} // end anonymous namespace diff --git a/lld/unittests/DriverTests/GnuLdDriverTest.cpp b/lld/unittests/DriverTests/GnuLdDriverTest.cpp index 89b7305b2c83..63b898d67aef 100644 --- a/lld/unittests/DriverTests/GnuLdDriverTest.cpp +++ b/lld/unittests/DriverTests/GnuLdDriverTest.cpp @@ -20,17 +20,15 @@ using namespace llvm; using namespace lld; namespace { - class GnuLdParserTest : public ParserTest> { protected: const LinkingContext *linkingContext() override { return _context.get(); } }; +} TEST_F(GnuLdParserTest, Empty) { EXPECT_FALSE(parse("ld", nullptr)); EXPECT_EQ(linkingContext(), nullptr); EXPECT_EQ("No input files\n", errorMessage()); } - -} // end anonymous namespace diff --git a/lld/unittests/DriverTests/InputGraphTest.cpp b/lld/unittests/DriverTests/InputGraphTest.cpp index 8ff37df69df6..862962f1c8de 100644 --- a/lld/unittests/DriverTests/InputGraphTest.cpp +++ b/lld/unittests/DriverTests/InputGraphTest.cpp @@ -141,6 +141,8 @@ protected: std::unique_ptr _inputGraph; }; +} // end anonymous namespace + TEST_F(InputGraphTest, Basic) { EXPECT_EQ(0, inputFileCount()); ErrorOr nextElement = inputGraph().getNextInputElement(); @@ -619,5 +621,3 @@ TEST_F(InputGraphTest, HiddenNodeTests) { nextElement = inputGraph().getNextInputElement(); EXPECT_EQ(InputGraphError::no_more_elements, nextElement.getError()); } - -} diff --git a/lld/unittests/DriverTests/WinLinkDriverTest.cpp b/lld/unittests/DriverTests/WinLinkDriverTest.cpp index 4de37f6e8945..1f8117dbd8dc 100644 --- a/lld/unittests/DriverTests/WinLinkDriverTest.cpp +++ b/lld/unittests/DriverTests/WinLinkDriverTest.cpp @@ -25,12 +25,12 @@ using namespace llvm; using namespace lld; namespace { - class WinLinkParserTest : public ParserTest { protected: const LinkingContext *linkingContext() override { return &_context; } }; +} TEST_F(WinLinkParserTest, Basic) { EXPECT_TRUE(parse("link.exe", "/subsystem:console", "/out:a.exe", @@ -682,5 +682,3 @@ TEST_F(WinLinkParserTest, DefEntryNameWindows) { EXPECT_TRUE(parse("link.exe", "/subsystem:windows", "a.obj", nullptr)); EXPECT_EQ("_WinMainCRTStartup", _context.entrySymbolName()); } - -} // end anonymous namespace