[lld] r204982 - Make anonymous namespace as small as possible.

Rui Ueyama ruiu at google.com
Thu Mar 27 16:34:32 PDT 2014


Author: ruiu
Date: Thu Mar 27 18:34:32 2014
New Revision: 204982

URL: http://llvm.org/viewvc/llvm-project?rev=204982&view=rev
Log:
Make anonymous namespace as small as possible.

Modified:
    lld/trunk/lib/Driver/GnuLdDriver.cpp
    lld/trunk/lib/Driver/UniversalDriver.cpp
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
    lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp
    lld/trunk/unittests/DriverTests/GnuLdDriverTest.cpp
    lld/trunk/unittests/DriverTests/InputGraphTest.cpp
    lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp

Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=204982&r1=204981&r2=204982&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Thu Mar 27 18:34:32 2014
@@ -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(ELFLinkingContex
   return make_error_code(ReaderError::unknown_file_format);
 }
 
-} // namespace
-
 llvm::ErrorOr<StringRef> ELFFileNode::getPath(const LinkingContext &) const {
   if (!_isDashlPrefix)
     return _path;

Modified: lld/trunk/lib/Driver/UniversalDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/UniversalDriver.cpp?rev=204982&r1=204981&r2=204982&view=diff
==============================================================================
--- lld/trunk/lib/Driver/UniversalDriver.cpp (original)
+++ lld/trunk/lib/Driver/UniversalDriver.cpp Thu Mar 27 18:34:32 2014
@@ -74,23 +74,25 @@ enum class Flavor {
   core          // -flavor core OR -core
 };
 
-Flavor strToFlavor(StringRef str) {
-  return llvm::StringSwitch<Flavor>(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<Flavor>(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<StringRef, 3> components;
   llvm::SplitString(programName, components, "-");
   ProgramNameParts ret;
@@ -120,9 +122,8 @@ ProgramNameParts parseProgramName(String
   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, con
   }
   llvm_unreachable("Unrecognised flavor");
 }
+
 } // end namespace lld

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp?rev=204982&r1=204981&r2=204982&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp Thu Mar 27 18:34:32 2014
@@ -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<llvm::support::ulittle32_t *>(loc);
   *target = (uint32_t(*target) & ~mask) | (result & mask);
 }
@@ -33,20 +30,20 @@ template <size_t BITS, class T> inline T
 
 /// \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, uint6
 /// \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
 /// \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
 
 /// \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, uint6
 
 /// \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 {

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp?rev=204982&r1=204981&r2=204982&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp Thu Mar 27 18:34:32 2014
@@ -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:

Modified: lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp?rev=204982&r1=204981&r2=204982&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp Thu Mar 27 18:34:32 2014
@@ -22,12 +22,12 @@ using namespace llvm;
 using namespace lld;
 
 namespace {
-
 class DarwinLdParserTest
     : public ParserTest<DarwinLdDriver, MachOLinkingContext> {
 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

Modified: lld/trunk/unittests/DriverTests/GnuLdDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/GnuLdDriverTest.cpp?rev=204982&r1=204981&r2=204982&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/GnuLdDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/GnuLdDriverTest.cpp Thu Mar 27 18:34:32 2014
@@ -20,17 +20,15 @@ using namespace llvm;
 using namespace lld;
 
 namespace {
-
 class GnuLdParserTest
     : public ParserTest<GnuLdDriver, std::unique_ptr<ELFLinkingContext>> {
 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

Modified: lld/trunk/unittests/DriverTests/InputGraphTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/InputGraphTest.cpp?rev=204982&r1=204981&r2=204982&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/InputGraphTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/InputGraphTest.cpp Thu Mar 27 18:34:32 2014
@@ -141,6 +141,8 @@ protected:
   std::unique_ptr<InputGraph> _inputGraph;
 };
 
+} // end anonymous namespace
+
 TEST_F(InputGraphTest, Basic) {
   EXPECT_EQ(0, inputFileCount());
   ErrorOr<InputElement *> nextElement = inputGraph().getNextInputElement();
@@ -619,5 +621,3 @@ TEST_F(InputGraphTest, HiddenNodeTests)
   nextElement = inputGraph().getNextInputElement();
   EXPECT_EQ(InputGraphError::no_more_elements, nextElement.getError());
 }
-
-}

Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=204982&r1=204981&r2=204982&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Thu Mar 27 18:34:32 2014
@@ -25,12 +25,12 @@ using namespace llvm;
 using namespace lld;
 
 namespace {
-
 class WinLinkParserTest
     : public ParserTest<WinLinkDriver, PECOFFLinkingContext> {
 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, DefEntryNameWi
   EXPECT_TRUE(parse("link.exe", "/subsystem:windows", "a.obj", nullptr));
   EXPECT_EQ("_WinMainCRTStartup", _context.entrySymbolName());
 }
-
-} // end anonymous namespace





More information about the llvm-commits mailing list