summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2015-03-26 01:44:01 +0000
committerRui Ueyama <ruiu@google.com>2015-03-26 01:44:01 +0000
commitf006f4d62c9375288f25870f2b020609d67f6b11 (patch)
tree6753fb979cf61e0d4f2951925de3e686a1652482
parent48865ca64d823eb5a76514deeffe235b54c86da7 (diff)
downloadbcm5719-llvm-f006f4d62c9375288f25870f2b020609d67f6b11.tar.gz
bcm5719-llvm-f006f4d62c9375288f25870f2b020609d67f6b11.zip
Define an implicit constructor which takes actual alignment value to PowerOf2.
The new constructor's type is the same, but this one takes not a log2 value but an alignment value itself, so the meaning is totally differnet. llvm-svn: 233244
-rw-r--r--lld/include/lld/Core/DefinedAtom.h7
-rw-r--r--lld/lib/Driver/DarwinLdDriver.cpp2
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFile.h2
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp4
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp4
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp4
-rw-r--r--lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp2
-rw-r--r--lld/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp8
8 files changed, 16 insertions, 17 deletions
diff --git a/lld/include/lld/Core/DefinedAtom.h b/lld/include/lld/Core/DefinedAtom.h
index 246a6717356..69e851a3a03 100644
--- a/lld/include/lld/Core/DefinedAtom.h
+++ b/lld/include/lld/Core/DefinedAtom.h
@@ -30,11 +30,10 @@ class Reference;
// Once the conversion is done, this class will be removed.
class PowerOf2 {
public:
- static PowerOf2 create(uint16_t v) { return PowerOf2(v); }
+ PowerOf2(uint16_t v) : _v(v) {}
bool operator==(const PowerOf2 &other) const { return _v == other._v; }
- uint16_t get() const { return 1 << _v; }
+ uint16_t get() const { return _v; }
private:
- explicit PowerOf2(uint16_t v) : _v(v) {}
uint16_t _v;
};
@@ -219,7 +218,7 @@ public:
};
struct Alignment {
- Alignment(int p2, int m = 0) : powerOf2(PowerOf2::create(p2)), modulus(m) {}
+ Alignment(int p2, int m = 0) : powerOf2(1 << p2), modulus(m) {}
Alignment(PowerOf2 p2, int m = 0) : powerOf2(p2), modulus(m) {}
PowerOf2 powerOf2;
diff --git a/lld/lib/Driver/DarwinLdDriver.cpp b/lld/lib/Driver/DarwinLdDriver.cpp
index 679c9b2d17c..2f110fee049 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;
}
- PowerOf2 align2 = PowerOf2::create(llvm::countTrailingZeros(alignValue));
+ PowerOf2 align2 = 1 << llvm::countTrailingZeros(alignValue);
if (!llvm::isPowerOf2_64(alignValue)) {
diagnostics << "warning: alignment for '-sectalign "
<< segName << " " << sectName
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h b/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h
index 940ea639923..449d61960de 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h
@@ -108,7 +108,7 @@ LLVM_YAML_STRONG_TYPEDEF(uint32_t, SectionAttr)
/// can support either kind.
struct Section {
Section() : type(llvm::MachO::S_REGULAR),
- attributes(0), alignment(PowerOf2::create(0)), address(0) { }
+ attributes(0), alignment(1), address(0) { }
StringRef segmentName;
StringRef sectionName;
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp
index 028c3638132..ad2d9186846 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp
@@ -297,7 +297,7 @@ readBinary(std::unique_ptr<MemoryBuffer> &mb,
section.type = (SectionType)(read32(&sect->flags, isBig) &
SECTION_TYPE);
section.attributes = read32(&sect->flags, isBig) & SECTION_ATTRIBUTES;
- section.alignment = PowerOf2::create(read32(&sect->align, isBig));
+ section.alignment = 1 << read32(&sect->align, isBig);
section.address = read64(&sect->addr, isBig);
const uint8_t *content =
(const uint8_t *)start + read32(&sect->offset, isBig);
@@ -341,7 +341,7 @@ readBinary(std::unique_ptr<MemoryBuffer> &mb,
SECTION_TYPE);
section.attributes =
read32((const uint8_t *)&sect->flags, isBig) & SECTION_ATTRIBUTES;
- section.alignment = PowerOf2::create(read32(&sect->align, isBig));
+ section.alignment = 1 << read32(&sect->align, isBig);
section.address = read32(&sect->addr, isBig);
const uint8_t *content =
(const uint8_t *)start + read32(&sect->offset, isBig);
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
index 15bdb0aa077..7c3e338bca1 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
@@ -67,9 +67,9 @@ struct SectionInfo {
SectionInfo::SectionInfo(StringRef sg, StringRef sct, SectionType t,
const MachOLinkingContext &ctxt, uint32_t attrs)
: segmentName(sg), sectionName(sct), type(t), attributes(attrs),
- address(0), size(0), alignment(PowerOf2::create(0)),
+ address(0), size(0), alignment(1),
normalizedSectionIndex(0), finalSectionIndex(0) {
- PowerOf2 align = PowerOf2::create(0);
+ PowerOf2 align = 1;
if (ctxt.sectionAligned(segmentName, sectionName, align)) {
alignment = align;
}
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp
index 79eefd32573..5d71c75ef43 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp
@@ -61,7 +61,7 @@ struct ScalarTraits<lld::PowerOf2> {
static StringRef input(StringRef scalar, void*, lld::PowerOf2 &result) {
uint32_t value;
scalar.getAsInteger(10, value);
- result = lld::PowerOf2::create(value);
+ result = 1 << value;
return StringRef();
}
static bool mustQuote(StringRef) { return false; }
@@ -290,7 +290,7 @@ struct MappingTraits<Section> {
io.mapRequired("section", sect.sectionName);
io.mapRequired("type", sect.type);
io.mapOptional("attributes", sect.attributes);
- io.mapOptional("alignment", sect.alignment, lld::PowerOf2::create(0));
+ io.mapOptional("alignment", sect.alignment, lld::PowerOf2(1));
io.mapRequired("address", sect.address);
if (sect.type == llvm::MachO::S_ZEROFILL) {
// S_ZEROFILL sections use "size:" instead of "content:"
diff --git a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
index e2766ced90c..5e1c069f5a6 100644
--- a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
+++ b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
@@ -509,7 +509,7 @@ template <> struct ScalarTraits<lld::DefinedAtom::Alignment> {
if (scalar.getAsInteger(0, power)) {
return "malformed alignment power";
}
- value.powerOf2 = PowerOf2::create(llvm::Log2_64(power));
+ value.powerOf2 = power;
if (value.modulus >= power) {
return "malformed alignment, modulus too large for power";
}
diff --git a/lld/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp b/lld/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp
index d7a032775f5..c705ca6f1be 100644
--- a/lld/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp
+++ b/lld/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp
@@ -123,7 +123,7 @@ TEST(BinaryWriterTest, obj_relocs_x86_64) {
text.type = S_REGULAR;
text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS);
- text.alignment = lld::PowerOf2::create(4);
+ text.alignment = 16;
text.address = 0;
const uint8_t textBytes[] = {
0xe8, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8b, 0x05,
@@ -240,7 +240,7 @@ TEST(BinaryWriterTest, obj_relocs_x86) {
text.type = S_REGULAR;
text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS);
- text.alignment = lld::PowerOf2::create(4);
+ text.alignment = 16;
text.address = 0;
const uint8_t textBytes[] = {
0xe8, 0xfb, 0xff, 0xff, 0xff, 0xa1, 0x00, 0x00,
@@ -350,7 +350,7 @@ TEST(BinaryWriterTest, obj_relocs_armv7) {
text.type = S_REGULAR;
text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS);
- text.alignment = lld::PowerOf2::create(2);
+ text.alignment = 4;
text.address = 0;
const uint8_t textBytes[] = {
0xff, 0xf7, 0xfe, 0xef, 0x40, 0xf2, 0x05, 0x01,
@@ -479,7 +479,7 @@ TEST(BinaryWriterTest, obj_relocs_ppc) {
text.type = S_REGULAR;
text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS);
- text.alignment = lld::PowerOf2::create(2);
+ text.alignment = 4;
text.address = 0;
const uint8_t textBytes[] = {
0x48, 0x00, 0x00, 0x01, 0x40, 0x82, 0xff, 0xfc,
OpenPOWER on IntegriCloud