summaryrefslogtreecommitdiffstats
path: root/lld
diff options
context:
space:
mode:
Diffstat (limited to 'lld')
-rw-r--r--lld/include/lld/Core/DefinedAtom.h25
-rw-r--r--lld/include/lld/ReaderWriter/MachOLinkingContext.h4
-rw-r--r--lld/lib/Driver/DarwinLdDriver.cpp2
-rw-r--r--lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp4
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp9
5 files changed, 30 insertions, 14 deletions
diff --git a/lld/include/lld/Core/DefinedAtom.h b/lld/include/lld/Core/DefinedAtom.h
index 86d880c659b..45f47ca9103 100644
--- a/lld/include/lld/Core/DefinedAtom.h
+++ b/lld/include/lld/Core/DefinedAtom.h
@@ -17,6 +17,25 @@ namespace lld {
class File;
class Reference;
+// This class represents exponents of power-of-two numbers.
+// Used to represent alignments.
+//
+// Currently we represent alignments both in log2 of a value or a
+// value itself. That is confusing. We aim to use only real values
+// only. Conversion is not easy, since both types are just arithmetic
+// types, and thus the compiler doesn't help us find places we mix
+// them. This class is to make all places where exponents are used
+// explicit.
+//
+// Once the conversion is done, this class will be removed.
+class PowerOf2 {
+public:
+ PowerOf2(uint16_t v) : _v(v) {}
+ operator uint16_t() const { return _v; }
+private:
+ uint16_t _v;
+};
+
/// \brief The fundamental unit of linking.
///
/// A C function or global variable is an atom. An atom has content and
@@ -198,11 +217,9 @@ public:
};
struct Alignment {
- Alignment(int p2, int m = 0)
- : powerOf2(p2)
- , modulus(m) {}
+ Alignment(int p2, int m = 0) : powerOf2(p2), modulus(m) {}
- uint16_t powerOf2;
+ PowerOf2 powerOf2;
uint16_t modulus;
bool operator==(const Alignment &rhs) const {
diff --git a/lld/include/lld/ReaderWriter/MachOLinkingContext.h b/lld/include/lld/ReaderWriter/MachOLinkingContext.h
index 8e253a1235f..06bd2d5edac 100644
--- a/lld/include/lld/ReaderWriter/MachOLinkingContext.h
+++ b/lld/include/lld/ReaderWriter/MachOLinkingContext.h
@@ -228,10 +228,10 @@ public:
const StringRefVector &rpaths() const { return _rpaths; }
/// Add section alignment constraint on final layout.
- void addSectionAlignment(StringRef seg, StringRef sect, uint8_t align2);
+ void addSectionAlignment(StringRef seg, StringRef sect, PowerOf2 align2);
/// Returns true if specified section had alignment constraints.
- bool sectionAligned(StringRef seg, StringRef sect, uint8_t &align2) const;
+ bool sectionAligned(StringRef seg, StringRef sect, PowerOf2 &align2) const;
StringRef dyldPath() const { return "/usr/lib/dyld"; }
diff --git a/lld/lib/Driver/DarwinLdDriver.cpp b/lld/lib/Driver/DarwinLdDriver.cpp
index 68dc3946d9c..fc7e675686d 100644
--- a/lld/lib/Driver/DarwinLdDriver.cpp
+++ b/lld/lib/Driver/DarwinLdDriver.cpp
@@ -479,7 +479,7 @@ bool DarwinLdDriver::parse(int argc, const char *argv[],
<< alignStr << "' not a valid number\n";
return false;
}
- uint8_t align2 = llvm::countTrailingZeros(alignValue);
+ PowerOf2 align2 = llvm::countTrailingZeros(alignValue);
if (!llvm::isPowerOf2_64(alignValue)) {
diagnostics << "warning: alignment for '-sectalign "
<< segName << " " << sectName
diff --git a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
index 92385cf3e82..1ae5be41fc4 100644
--- a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
@@ -731,7 +731,7 @@ ArchHandler &MachOLinkingContext::archHandler() const {
void MachOLinkingContext::addSectionAlignment(StringRef seg, StringRef sect,
- uint8_t align2) {
+ PowerOf2 align2) {
SectionAlign entry;
entry.segmentName = seg;
entry.sectionName = sect;
@@ -740,7 +740,7 @@ void MachOLinkingContext::addSectionAlignment(StringRef seg, StringRef sect,
}
bool MachOLinkingContext::sectionAligned(StringRef seg, StringRef sect,
- uint8_t &align2) const {
+ PowerOf2 &align2) const {
for (const SectionAlign &entry : _sectAligns) {
if (seg.equals(entry.segmentName) && sect.equals(entry.sectionName)) {
align2 = entry.align2;
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
index 4d6183f71df..eda11726cc7 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
@@ -58,7 +58,7 @@ struct SectionInfo {
uint32_t attributes;
uint64_t address;
uint64_t size;
- uint32_t alignment;
+ PowerOf2 alignment;
std::vector<AtomInfo> atomsAndOffsets;
uint32_t normalizedSectionIndex;
uint32_t finalSectionIndex;
@@ -69,7 +69,7 @@ SectionInfo::SectionInfo(StringRef sg, StringRef sct, SectionType t,
: segmentName(sg), sectionName(sct), type(t), attributes(attrs),
address(0), size(0), alignment(0),
normalizedSectionIndex(0), finalSectionIndex(0) {
- uint8_t align;
+ PowerOf2 align(0);
if (ctxt.sectionAligned(segmentName, sectionName, align)) {
alignment = align;
}
@@ -142,7 +142,7 @@ private:
void appendSection(SectionInfo *si, NormalizedFile &file);
uint32_t sectionIndexForAtom(const Atom *atom);
- static uint64_t alignTo(uint64_t value, uint8_t align2);
+ static uint64_t alignTo(uint64_t value, PowerOf2 align2);
typedef llvm::DenseMap<const Atom*, uint32_t> AtomToIndex;
struct AtomAndIndex { const Atom *atom; uint32_t index; SymbolScope scope; };
struct AtomSorter {
@@ -453,7 +453,7 @@ void Util::organizeSections() {
}
-uint64_t Util::alignTo(uint64_t value, uint8_t align2) {
+uint64_t Util::alignTo(uint64_t value, PowerOf2 align2) {
return llvm::RoundUpToAlignment(value, 1 << align2);
}
@@ -1235,4 +1235,3 @@ normalizedFromAtoms(const lld::File &atomFile,
} // namespace normalized
} // namespace mach_o
} // namespace lld
-
OpenPOWER on IntegriCloud