diff --git a/lld/include/lld/Core/Parallel.h b/lld/include/lld/Core/Parallel.h index b77a71ec6aef..c2704485f4bf 100644 --- a/lld/include/lld/Core/Parallel.h +++ b/lld/include/lld/Core/Parallel.h @@ -18,9 +18,7 @@ #ifdef _MSC_VER // Exceptions are disabled so this isn't defined, but concrt assumes it is. -namespace { -void *__uncaught_exception() { return nullptr; } -} +static void *__uncaught_exception() { return nullptr; } #endif #include diff --git a/lld/lib/Core/InputGraph.cpp b/lld/lib/Core/InputGraph.cpp index ea95b620f3c5..ddf1d7dc1279 100644 --- a/lld/lib/Core/InputGraph.cpp +++ b/lld/lib/Core/InputGraph.cpp @@ -13,12 +13,10 @@ using namespace lld; -namespace { -bool sortInputElements(const std::unique_ptr &a, - const std::unique_ptr &b) { +static bool sortInputElements(const std::unique_ptr &a, + const std::unique_ptr &b) { return a->getOrdinal() < b->getOrdinal(); } -} bool InputGraph::addInputElement(std::unique_ptr ie) { _inputArgs.push_back(std::move(ie)); diff --git a/lld/lib/Passes/GOTPass.cpp b/lld/lib/Passes/GOTPass.cpp index b9a6f73e5b13..f29c35b0b644 100644 --- a/lld/lib/Passes/GOTPass.cpp +++ b/lld/lib/Passes/GOTPass.cpp @@ -41,8 +41,8 @@ namespace lld { -namespace { -bool shouldReplaceTargetWithGOTAtom(const Atom *target, bool canBypassGOT) { +static bool shouldReplaceTargetWithGOTAtom(const Atom *target, + bool canBypassGOT) { // Accesses to shared library symbols must go through GOT. if (target->definition() == Atom::definitionSharedLibrary) return true; @@ -59,13 +59,12 @@ bool shouldReplaceTargetWithGOTAtom(const Atom *target, bool canBypassGOT) { return !canBypassGOT; } -const DefinedAtom * +static const DefinedAtom * findGOTAtom(const Atom *target, llvm::DenseMap &targetToGOT) { auto pos = targetToGOT.find(target); return (pos == targetToGOT.end()) ? nullptr : pos->second; } -} // end anonymous namespace void GOTPass::perform(std::unique_ptr &mergedFile) { // Use map so all pointers to same symbol use same GOT entry. diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp index 3765aeba3b03..ffe58b1233d2 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp @@ -18,15 +18,13 @@ using namespace elf; using namespace llvm::ELF; -namespace { - #define APPLY_RELOC(result) \ *reinterpret_cast(location) = \ result | \ (uint32_t) * reinterpret_cast(location); -int relocBNPCREL(uint8_t *location, uint64_t P, uint64_t S, uint64_t A, - int32_t nBits) { +static int relocBNPCREL(uint8_t *location, uint64_t P, uint64_t S, uint64_t A, + int32_t nBits) { int32_t result = (uint32_t)(((S + A) - P) >> 2); int32_t range = 1 << nBits; if (result < range && result > -range) { @@ -38,7 +36,7 @@ int relocBNPCREL(uint8_t *location, uint64_t P, uint64_t S, uint64_t A, } /// \brief Word32_LO: 0x00c03fff : (S + A) : Truncate -int relocLO16(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { +static int relocLO16(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { uint32_t result = (uint32_t)(S + A); result = lld::scatterBits(result, 0x00c03fff); APPLY_RELOC(result); @@ -46,7 +44,7 @@ int relocLO16(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { } /// \brief Word32_LO: 0x00c03fff : (S + A) >> 16 : Truncate -int relocHI16(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { +static int relocHI16(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { uint32_t result = (uint32_t)((S + A) >> 16); result = lld::scatterBits(result, 0x00c03fff); APPLY_RELOC(result); @@ -54,13 +52,13 @@ int relocHI16(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { } /// \brief Word32: 0xffffffff : (S + A) : Truncate -int reloc32(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { +static int reloc32(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { uint32_t result = (uint32_t)(S + A); APPLY_RELOC(result); return 0; } -int reloc32_6_X(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { +static int reloc32_6_X(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { int64_t result = ((S + A) >> 6); int64_t range = ((int64_t)1) << 32; if (result > range) @@ -71,7 +69,8 @@ int reloc32_6_X(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { } // R_HEX_B32_PCREL_X -int relocHexB32PCRELX(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { +static int relocHexB32PCRELX(uint8_t *location, uint64_t P, uint64_t S, + uint64_t A) { int64_t result = ((S + A - P) >> 6); result = lld::scatterBits(result, 0xfff3fff); APPLY_RELOC(result); @@ -79,8 +78,8 @@ int relocHexB32PCRELX(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { } // R_HEX_BN_PCREL_X -int relocHexBNPCRELX(uint8_t *location, uint64_t P, uint64_t S, uint64_t A, - int nbits) { +static int relocHexBNPCRELX(uint8_t *location, uint64_t P, uint64_t S, + uint64_t A, int nbits) { int32_t result = ((S + A - P) & 0x3f); int32_t range = 1 << nbits; if (result < range && result > -range) { @@ -92,7 +91,8 @@ int relocHexBNPCRELX(uint8_t *location, uint64_t P, uint64_t S, uint64_t A, } // R_HEX_6_PCREL_X -int relocHex6PCRELX(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { +static int relocHex6PCRELX(uint8_t *location, uint64_t P, uint64_t S, + uint64_t A) { int32_t result = (S + A - P); result = lld::scatterBits(result, FINDV4BITMASK(location)); APPLY_RELOC(result); @@ -100,7 +100,7 @@ int relocHex6PCRELX(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { } // R_HEX_N_X : Word32_U6 : (S + A) : Unsigned Truncate -int relocHex_N_X(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { +static int relocHex_N_X(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { uint32_t result = (S + A); result = lld::scatterBits(result, FINDV4BITMASK(location)); APPLY_RELOC(result); @@ -108,8 +108,8 @@ int relocHex_N_X(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { } // GP REL relocations -int relocHexGPRELN(uint8_t *location, uint64_t P, uint64_t S, uint64_t A, - uint64_t GP, int nShiftBits) { +static int relocHexGPRELN(uint8_t *location, uint64_t P, uint64_t S, uint64_t A, + uint64_t GP, int nShiftBits) { int32_t result = (int64_t)((S + A - GP) >> nShiftBits); int32_t range = 1L << 16; if (result <= range) { @@ -121,7 +121,7 @@ int relocHexGPRELN(uint8_t *location, uint64_t P, uint64_t S, uint64_t A, } /// \brief Word32_LO: 0x00c03fff : (G) : Truncate -int relocHexGOTLO16(uint8_t *location, uint64_t A, uint64_t GOT) { +static int relocHexGOTLO16(uint8_t *location, uint64_t A, uint64_t GOT) { int32_t result = (int32_t)(A-GOT); result = lld::scatterBits(result, 0x00c03fff); APPLY_RELOC(result); @@ -129,7 +129,7 @@ int relocHexGOTLO16(uint8_t *location, uint64_t A, uint64_t GOT) { } /// \brief Word32_LO: 0x00c03fff : (G) >> 16 : Truncate -int relocHexGOTHI16(uint8_t *location, uint64_t A, uint64_t GOT) { +static int relocHexGOTHI16(uint8_t *location, uint64_t A, uint64_t GOT) { int32_t result = (int32_t)((A-GOT) >> 16); result = lld::scatterBits(result, 0x00c03fff); APPLY_RELOC(result); @@ -137,14 +137,14 @@ int relocHexGOTHI16(uint8_t *location, uint64_t A, uint64_t GOT) { } /// \brief Word32: 0xffffffff : (G) : Truncate -int relocHexGOT32(uint8_t *location, uint64_t A, uint64_t GOT) { +static int relocHexGOT32(uint8_t *location, uint64_t A, uint64_t GOT) { int32_t result = (int32_t)(GOT - A); APPLY_RELOC(result); return 0; } /// \brief Word32_U16 : (G) : Truncate -int relocHexGOT16(uint8_t *location, uint64_t A, uint64_t GOT) { +static int relocHexGOT16(uint8_t *location, uint64_t A, uint64_t GOT) { int32_t result = (int32_t)(GOT-A); int32_t range = 1L << 16; if (result <= range) { @@ -155,14 +155,14 @@ int relocHexGOT16(uint8_t *location, uint64_t A, uint64_t GOT) { return 1; } -int relocHexGOT32_6_X(uint8_t *location, uint64_t A, uint64_t GOT) { +static int relocHexGOT32_6_X(uint8_t *location, uint64_t A, uint64_t GOT) { int32_t result = (int32_t)((A-GOT) >> 6); result = lld::scatterBits(result, FINDV4BITMASK(location)); APPLY_RELOC(result); return 0; } -int relocHexGOT16_X(uint8_t *location, uint64_t A, uint64_t GOT) { +static int relocHexGOT16_X(uint8_t *location, uint64_t A, uint64_t GOT) { int32_t result = (int32_t)(A-GOT); int32_t range = 1L << 6; if (result <= range) { @@ -173,46 +173,44 @@ int relocHexGOT16_X(uint8_t *location, uint64_t A, uint64_t GOT) { return 1; } -int relocHexGOT11_X(uint8_t *location, uint64_t A, uint64_t GOT) { +static int relocHexGOT11_X(uint8_t *location, uint64_t A, uint64_t GOT) { uint32_t result = (uint32_t)(A-GOT); result = lld::scatterBits(result, FINDV4BITMASK(location)); APPLY_RELOC(result); return 0; } -int relocHexGOTRELSigned(uint8_t *location, uint64_t P, uint64_t S, uint64_t A, - uint64_t GOT, int shiftBits = 0) { +static int relocHexGOTRELSigned(uint8_t *location, uint64_t P, uint64_t S, + uint64_t A, uint64_t GOT, int shiftBits = 0) { int32_t result = (int32_t)((S + A - GOT) >> shiftBits); result = lld::scatterBits(result, FINDV4BITMASK(location)); APPLY_RELOC(result); return 0; } -int relocHexGOTRELUnsigned(uint8_t *location, uint64_t P, uint64_t S, - uint64_t A, uint64_t GOT, int shiftBits = 0) { +static int relocHexGOTRELUnsigned(uint8_t *location, uint64_t P, uint64_t S, + uint64_t A, uint64_t GOT, int shiftBits = 0) { uint32_t result = (uint32_t)((S + A - GOT) >> shiftBits); result = lld::scatterBits(result, FINDV4BITMASK(location)); APPLY_RELOC(result); return 0; } -int relocHexGOTREL_HILO16(uint8_t *location, uint64_t P, uint64_t S, uint64_t A, - uint64_t GOT, int shiftBits = 0) { +static int relocHexGOTREL_HILO16(uint8_t *location, uint64_t P, uint64_t S, + uint64_t A, uint64_t GOT, int shiftBits = 0) { int32_t result = (int32_t)((S + A - GOT) >> shiftBits); result = lld::scatterBits(result, 0x00c03fff); APPLY_RELOC(result); return 0; } -int relocHexGOTREL_32(uint8_t *location, uint64_t P, uint64_t S, uint64_t A, - uint64_t GOT) { +static int relocHexGOTREL_32(uint8_t *location, uint64_t P, uint64_t S, + uint64_t A, uint64_t GOT) { int32_t result = (int32_t)(S + A - GOT); APPLY_RELOC(result); return 0; } -} // end anon namespace - error_code HexagonTargetRelocationHandler::applyRelocation( ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom, const Reference &ref) const { diff --git a/lld/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp b/lld/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp index 30d3ae1b50e2..eb1e467c1153 100644 --- a/lld/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp @@ -21,9 +21,10 @@ using namespace llvm::ELF; /// A: Added used to compute the value, r_addend /// P: Place address of the field being relocated, r_offset /// S: Value of the symbol whose index resides in the relocation entry. -namespace { + /// \brief low24 (S + A - P) >> 2 : Verify -int relocB24PCREL(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { +static int relocB24PCREL(uint8_t *location, uint64_t P, uint64_t S, + uint64_t A) { int32_t result = (uint32_t)(((S + A) - P)); if ((result < 0x1000000) && (result > -0x1000000)) { result &= ~-(0x1000000); @@ -33,7 +34,6 @@ int relocB24PCREL(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { } return 1; } -} // end anon namespace error_code PPCTargetRelocationHandler::applyRelocation( ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom, diff --git a/lld/lib/ReaderWriter/ELF/SectionChunks.h b/lld/lib/ReaderWriter/ELF/SectionChunks.h index 86c582cd2b20..2974658ce844 100644 --- a/lld/lib/ReaderWriter/ELF/SectionChunks.h +++ b/lld/lib/ReaderWriter/ELF/SectionChunks.h @@ -31,13 +31,12 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileOutputBuffer.h" -namespace { -LLVM_ATTRIBUTE_UNUSED std::string kindOrUnknown(llvm::ErrorOr k) { +static LLVM_ATTRIBUTE_UNUSED std::string +kindOrUnknown(llvm::ErrorOr k) { if (k) return *k; return ""; } -} namespace lld { namespace elf { diff --git a/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp b/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp index 648f41dabc70..3e6599068f2f 100644 --- a/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp @@ -15,9 +15,8 @@ using namespace elf; using namespace llvm::ELF; -namespace { /// \brief R_386_32 - word32: S + A -int reloc32(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { +static int reloc32(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { int32_t result = (uint32_t)(S + A); *reinterpret_cast(location) = result | (uint32_t)*reinterpret_cast(location); @@ -25,13 +24,12 @@ int reloc32(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { } /// \brief R_386_PC32 - word32: S + A - P -int relocPC32(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { +static int relocPC32(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { uint32_t result = (uint32_t)((S + A) - P); *reinterpret_cast(location) = result + (uint32_t)*reinterpret_cast(location); return 0; } -} // end anon namespace error_code X86TargetRelocationHandler::applyRelocation( ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom, diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp b/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp index 42a5a9951610..1ddbccd5db5b 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp @@ -13,9 +13,8 @@ using namespace lld; using namespace elf; -namespace { /// \brief R_X86_64_64 - word64: S + A -void reloc64(uint8_t *location, uint64_t P, uint64_t S, int64_t A) { +static void reloc64(uint8_t *location, uint64_t P, uint64_t S, int64_t A) { uint64_t result = S + A; *reinterpret_cast(location) = result | @@ -23,7 +22,7 @@ void reloc64(uint8_t *location, uint64_t P, uint64_t S, int64_t A) { } /// \brief R_X86_64_PC32 - word32: S + A - P -void relocPC32(uint8_t *location, uint64_t P, uint64_t S, int64_t A) { +static void relocPC32(uint8_t *location, uint64_t P, uint64_t S, int64_t A) { uint32_t result = (uint32_t)((S + A) - P); *reinterpret_cast(location) = result + @@ -31,7 +30,7 @@ void relocPC32(uint8_t *location, uint64_t P, uint64_t S, int64_t A) { } /// \brief R_X86_64_32 - word32: S + A -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) { int32_t result = (uint32_t)(S + A); *reinterpret_cast(location) = result | @@ -40,14 +39,13 @@ void reloc32(uint8_t *location, uint64_t P, uint64_t S, int64_t A) { } /// \brief R_X86_64_32S - word32: S + A -void reloc32S(uint8_t *location, uint64_t P, uint64_t S, int64_t A) { +static void reloc32S(uint8_t *location, uint64_t P, uint64_t S, int64_t A) { int32_t result = (int32_t)(S + A); *reinterpret_cast(location) = result | (int32_t) * reinterpret_cast(location); // TODO: Make sure that the result sign extends to the 64bit value. } -} // end anon namespace int64_t X86_64TargetRelocationHandler::relocAddend(const Reference &ref) const { switch (ref.kind()) {