forked from OSchip/llvm-project
Make anonymous namespace as small as possible.
Use of static is recommended by the style guide. llvm-svn: 196877
This commit is contained in:
parent
7f10a8cd45
commit
2f47acfd6a
|
@ -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 <algorithm>
|
||||
|
|
|
@ -13,12 +13,10 @@
|
|||
|
||||
using namespace lld;
|
||||
|
||||
namespace {
|
||||
bool sortInputElements(const std::unique_ptr<InputElement> &a,
|
||||
const std::unique_ptr<InputElement> &b) {
|
||||
static bool sortInputElements(const std::unique_ptr<InputElement> &a,
|
||||
const std::unique_ptr<InputElement> &b) {
|
||||
return a->getOrdinal() < b->getOrdinal();
|
||||
}
|
||||
}
|
||||
|
||||
bool InputGraph::addInputElement(std::unique_ptr<InputElement> ie) {
|
||||
_inputArgs.push_back(std::move(ie));
|
||||
|
|
|
@ -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<const Atom *, const DefinedAtom *> &targetToGOT) {
|
||||
auto pos = targetToGOT.find(target);
|
||||
return (pos == targetToGOT.end()) ? nullptr : pos->second;
|
||||
}
|
||||
} // end anonymous namespace
|
||||
|
||||
void GOTPass::perform(std::unique_ptr<MutableFile> &mergedFile) {
|
||||
// Use map so all pointers to same symbol use same GOT entry.
|
||||
|
|
|
@ -18,15 +18,13 @@ using namespace elf;
|
|||
|
||||
using namespace llvm::ELF;
|
||||
|
||||
namespace {
|
||||
|
||||
#define APPLY_RELOC(result) \
|
||||
*reinterpret_cast<llvm::support::ulittle32_t *>(location) = \
|
||||
result | \
|
||||
(uint32_t) * reinterpret_cast<llvm::support::ulittle32_t *>(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<int32_t>(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<int32_t>(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<int32_t>(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<int32_t>(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<uint32_t>(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<int32_t>(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<int32_t>(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<int32_t>(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<uint32_t>(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<int32_t>(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<uint32_t>(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<int32_t>(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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -31,13 +31,12 @@
|
|||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/FileOutputBuffer.h"
|
||||
|
||||
namespace {
|
||||
LLVM_ATTRIBUTE_UNUSED std::string kindOrUnknown(llvm::ErrorOr<std::string> k) {
|
||||
static LLVM_ATTRIBUTE_UNUSED std::string
|
||||
kindOrUnknown(llvm::ErrorOr<std::string> k) {
|
||||
if (k)
|
||||
return *k;
|
||||
return "<unknown>";
|
||||
}
|
||||
}
|
||||
|
||||
namespace lld {
|
||||
namespace elf {
|
||||
|
|
|
@ -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<llvm::support::ulittle32_t *>(location) = result |
|
||||
(uint32_t)*reinterpret_cast<llvm::support::ulittle32_t *>(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<llvm::support::ulittle32_t *>(location) = result +
|
||||
(uint32_t)*reinterpret_cast<llvm::support::ulittle32_t *>(location);
|
||||
return 0;
|
||||
}
|
||||
} // end anon namespace
|
||||
|
||||
error_code X86TargetRelocationHandler::applyRelocation(
|
||||
ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom,
|
||||
|
|
|
@ -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<llvm::support::ulittle64_t *>(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<llvm::support::ulittle32_t *>(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<llvm::support::ulittle32_t *>(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<llvm::support::little32_t *>(location) =
|
||||
result |
|
||||
(int32_t) * reinterpret_cast<llvm::support::little32_t *>(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()) {
|
||||
|
|
Loading…
Reference in New Issue