[lld] r233242 - Remove implicit constructor and operator int from PowerOf2.
Rui Ueyama
ruiu at google.com
Wed Mar 25 18:12:33 PDT 2015
Author: ruiu
Date: Wed Mar 25 20:12:32 2015
New Revision: 233242
URL: http://llvm.org/viewvc/llvm-project?rev=233242&view=rev
Log:
Remove implicit constructor and operator int from PowerOf2.
This patch is to make instantiation and conversion to an integer explicit,
so that we can mechanically replace all occurrences of the class with
integer in the next step.
Now get() returns an alignment value rather than its log2 value.
Modified:
lld/trunk/include/lld/Core/DefinedAtom.h
lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
lld/trunk/lib/Driver/DarwinLdDriver.cpp
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.h
lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
lld/trunk/lib/ReaderWriter/MachO/File.h
lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp
lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp
lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp
lld/trunk/unittests/MachOTests/MachONormalizedFileYAMLTests.cpp
Modified: lld/trunk/include/lld/Core/DefinedAtom.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/DefinedAtom.h?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/DefinedAtom.h (original)
+++ lld/trunk/include/lld/Core/DefinedAtom.h Wed Mar 25 20:12:32 2015
@@ -30,8 +30,9 @@ class Reference;
// 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; }
+ explicit PowerOf2(uint16_t v) : _v(v) {}
+ bool operator==(const PowerOf2 &other) const { return _v == other._v; }
+ uint16_t get() const { return 1 << _v; }
private:
uint16_t _v;
};
@@ -218,12 +219,13 @@ public:
struct Alignment {
Alignment(int p2, int m = 0) : powerOf2(p2), modulus(m) {}
+ Alignment(PowerOf2 p2, int m = 0) : powerOf2(p2), modulus(m) {}
PowerOf2 powerOf2;
uint16_t modulus;
bool operator==(const Alignment &rhs) const {
- return (powerOf2 == rhs.powerOf2) && (modulus == rhs.modulus);
+ return (powerOf2.get() == rhs.powerOf2.get()) && (modulus == rhs.modulus);
}
};
Modified: lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h Wed Mar 25 20:12:32 2015
@@ -312,7 +312,7 @@ private:
struct SectionAlign {
StringRef segmentName;
StringRef sectionName;
- uint8_t align2;
+ PowerOf2 align2;
};
struct OrderFileNode {
Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Wed Mar 25 20:12:32 2015
@@ -479,13 +479,13 @@ bool DarwinLdDriver::parse(int argc, con
<< alignStr << "' not a valid number\n";
return false;
}
- PowerOf2 align2 = llvm::countTrailingZeros(alignValue);
+ PowerOf2 align2(llvm::countTrailingZeros(alignValue));
if (!llvm::isPowerOf2_64(alignValue)) {
diagnostics << "warning: alignment for '-sectalign "
<< segName << " " << sectName
<< llvm::format(" 0x%llX", alignValue)
<< "' is not a power of two, using "
- << llvm::format("0x%08X", (1 << align2)) << "\n";
+ << llvm::format("0x%08X", align2.get()) << "\n";
}
ctx.addSectionAlignment(segName, sectName, align2);
}
Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.h?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.h Wed Mar 25 20:12:32 2015
@@ -38,7 +38,7 @@ public:
const lld::AtomLayout *appendAtom(const Atom *atom) {
const DefinedAtom *definedAtom = cast<DefinedAtom>(atom);
DefinedAtom::Alignment atomAlign = definedAtom->alignment();
- uint64_t alignment = 1u << atomAlign.powerOf2;
+ uint64_t alignment = atomAlign.powerOf2.get();
this->_atoms.push_back(new (this->_alloc) lld::AtomLayout(atom, 0, 0));
// Set the section alignment to the largest alignment
// std::max doesn't support uint64_t
@@ -57,8 +57,8 @@ void SDataSection<HexagonELFType>::doPre
const lld::AtomLayout * B) {
const DefinedAtom *definedAtomA = cast<DefinedAtom>(A->_atom);
const DefinedAtom *definedAtomB = cast<DefinedAtom>(B->_atom);
- int64_t alignmentA = 1 << definedAtomA->alignment().powerOf2;
- int64_t alignmentB = 1 << definedAtomB->alignment().powerOf2;
+ int64_t alignmentA = definedAtomA->alignment().powerOf2.get();
+ int64_t alignmentB = definedAtomB->alignment().powerOf2.get();
if (alignmentA == alignmentB) {
if (definedAtomA->merge() == DefinedAtom::mergeAsTentative)
return false;
Modified: lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h Wed Mar 25 20:12:32 2015
@@ -310,7 +310,7 @@ template <class ELFT>
uint64_t AtomSection<ELFT>::alignOffset(uint64_t offset,
DefinedAtom::Alignment &atomAlign) {
uint64_t requiredModulus = atomAlign.modulus;
- uint64_t alignment = 1u << atomAlign.powerOf2;
+ uint64_t alignment = atomAlign.powerOf2.get();
uint64_t currentModulus = (offset % alignment);
uint64_t retOffset = offset;
if (currentModulus != requiredModulus) {
@@ -330,7 +330,7 @@ const lld::AtomLayout *AtomSection<ELFT>
const DefinedAtom *definedAtom = cast<DefinedAtom>(atom);
DefinedAtom::Alignment atomAlign = definedAtom->alignment();
- uint64_t alignment = 1u << atomAlign.powerOf2;
+ uint64_t alignment = atomAlign.powerOf2.get();
// Align the atom to the required modulus/ align the file offset and the
// memory offset separately this is required so that BSS symbols are handled
// properly as the BSS symbols only occupy memory size and not file size
Modified: lld/trunk/lib/ReaderWriter/MachO/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/File.h?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/File.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/File.h Wed Mar 25 20:12:32 2015
@@ -44,7 +44,7 @@ public:
}
DefinedAtom::Alignment align(
inSection->alignment,
- sectionOffset % ((uint64_t)1 << inSection->alignment));
+ sectionOffset % inSection->alignment.get());
MachODefinedAtom *atom =
new (allocator()) MachODefinedAtom(*this, name, scope, type, merge,
thumb, noDeadStrip, content, align);
@@ -67,7 +67,7 @@ public:
}
DefinedAtom::Alignment align(
inSection->alignment,
- sectionOffset % ((uint64_t)1 << inSection->alignment));
+ sectionOffset % inSection->alignment.get());
MachODefinedCustomSectionAtom *atom =
new (allocator()) MachODefinedCustomSectionAtom(*this, name, scope, type,
merge, thumb,
@@ -86,7 +86,7 @@ public:
}
DefinedAtom::Alignment align(
inSection->alignment,
- sectionOffset % ((uint64_t)1 << inSection->alignment));
+ sectionOffset % inSection->alignment.get());
MachODefinedAtom *atom =
new (allocator()) MachODefinedAtom(*this, name, scope, size, noDeadStrip,
align);
Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Wed Mar 25 20:12:32 2015
@@ -732,10 +732,7 @@ ArchHandler &MachOLinkingContext::archHa
void MachOLinkingContext::addSectionAlignment(StringRef seg, StringRef sect,
PowerOf2 align2) {
- SectionAlign entry;
- entry.segmentName = seg;
- entry.sectionName = sect;
- entry.align2 = align2;
+ SectionAlign entry = { seg, sect, align2 };
_sectAligns.push_back(entry);
}
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h Wed Mar 25 20:12:32 2015
@@ -114,7 +114,7 @@ struct Section {
StringRef sectionName;
SectionType type;
SectionAttr attributes;
- uint32_t alignment;
+ PowerOf2 alignment;
Hex64 address;
ArrayRef<uint8_t> content;
Relocations relocations;
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp Wed Mar 25 20:12:32 2015
@@ -297,7 +297,7 @@ readBinary(std::unique_ptr<MemoryBuffer>
section.type = (SectionType)(read32(§->flags, isBig) &
SECTION_TYPE);
section.attributes = read32(§->flags, isBig) & SECTION_ATTRIBUTES;
- section.alignment = read32(§->align, isBig);
+ section.alignment = PowerOf2(read32(§->align, isBig));
section.address = read64(§->addr, isBig);
const uint8_t *content =
(const uint8_t *)start + read32(§->offset, isBig);
@@ -341,7 +341,7 @@ readBinary(std::unique_ptr<MemoryBuffer>
SECTION_TYPE);
section.attributes =
read32((const uint8_t *)§->flags, isBig) & SECTION_ATTRIBUTES;
- section.alignment = read32(§->align, isBig);
+ section.alignment = PowerOf2(read32(§->align, isBig));
section.address = read32(§->addr, isBig);
const uint8_t *content =
(const uint8_t *)start + read32(§->offset, isBig);
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp Wed Mar 25 20:12:32 2015
@@ -291,7 +291,7 @@ MachOFileLayout::MachOFileLayout(const N
uint64_t offset = _startOfSectionsContent;
for (const Section § : file.sections) {
if (sect.type != llvm::MachO::S_ZEROFILL) {
- offset = llvm::RoundUpToAlignment(offset, 1 << sect.alignment);
+ offset = llvm::RoundUpToAlignment(offset, sect.alignment.get());
_sectInfo[§].fileOffset = offset;
offset += sect.content.size();
} else {
@@ -613,7 +613,7 @@ std::error_code MachOFileLayout::writeSi
sout->addr = sin.address;
sout->size = sin.content.size();
sout->offset = _sectInfo[&sin].fileOffset;
- sout->align = sin.alignment;
+ sout->align = llvm::Log2_32(sin.alignment.get());
sout->reloff = sin.relocations.empty() ? 0 : relOffset;
sout->nreloc = sin.relocations.size();
sout->flags = sin.type | sin.attributes;
@@ -661,7 +661,7 @@ std::error_code MachOFileLayout::writeSe
sect->offset = 0;
else
sect->offset = section->address - seg.address + segInfo.fileOffset;
- sect->align = section->alignment;
+ sect->align = llvm::Log2_32(section->alignment.get());
sect->reloff = 0;
sect->nreloc = 0;
sect->flags = section->type | section->attributes;
@@ -1343,4 +1343,3 @@ std::error_code writeBinary(const Normal
} // namespace normalized
} // namespace mach_o
} // namespace lld
-
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Wed Mar 25 20:12:32 2015
@@ -328,7 +328,7 @@ void Util::appendAtom(SectionInfo *sect,
// Figure out offset for atom in this section given alignment constraints.
uint64_t offset = sect->size;
DefinedAtom::Alignment atomAlign = atom->alignment();
- uint64_t align2 = 1 << atomAlign.powerOf2;
+ uint64_t align2 = atomAlign.powerOf2.get();
uint64_t requiredModulus = atomAlign.modulus;
uint64_t currentModulus = (offset % align2);
if ( currentModulus != requiredModulus ) {
@@ -338,7 +338,7 @@ void Util::appendAtom(SectionInfo *sect,
offset += align2+requiredModulus-currentModulus;
}
// Record max alignment of any atom in this section.
- if ( atomAlign.powerOf2 > sect->alignment )
+ if (align2 > sect->alignment.get())
sect->alignment = atomAlign.powerOf2;
// Assign atom to this section with this offset.
AtomInfo ai = {atom, offset};
@@ -454,7 +454,7 @@ void Util::organizeSections() {
}
uint64_t Util::alignTo(uint64_t value, PowerOf2 align2) {
- return llvm::RoundUpToAlignment(value, 1 << align2);
+ return llvm::RoundUpToAlignment(value, align2.get());
}
@@ -477,7 +477,7 @@ void Util::layoutSectionsInTextSegment(s
for (auto it = seg->sections.rbegin(); it != seg->sections.rend(); ++it) {
SectionInfo *sect = *it;
taddr -= sect->size;
- taddr = taddr & (0 - (1 << sect->alignment));
+ taddr = taddr & (0 - sect->alignment.get());
}
int64_t padding = taddr - hlcSize;
while (padding < 0)
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp Wed Mar 25 20:12:32 2015
@@ -53,6 +53,20 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(DataInCode)
namespace llvm {
namespace yaml {
+template <>
+struct ScalarTraits<lld::PowerOf2> {
+ static void output(const lld::PowerOf2 &value, void*, raw_ostream &out) {
+ out << llvm::format("%d", value);
+ }
+ static StringRef input(StringRef scalar, void*, lld::PowerOf2 &result) {
+ uint32_t value;
+ scalar.getAsInteger(10, value);
+ result = lld::PowerOf2(value);
+ return StringRef();
+ }
+ static bool mustQuote(StringRef) { return false; }
+};
+
// A vector of Sections is a sequence.
template<>
struct SequenceTraits< std::vector<Section> > {
@@ -276,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, 0U);
+ io.mapOptional("alignment", sect.alignment, lld::PowerOf2(0));
io.mapRequired("address", sect.address);
if (sect.type == llvm::MachO::S_ZEROFILL) {
// S_ZEROFILL sections use "size:" instead of "content:"
@@ -799,4 +813,3 @@ std::error_code writeYaml(const Normaliz
} // namespace normalized
} // namespace mach_o
} // namespace lld
-
Modified: lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp (original)
+++ lld/trunk/lib/ReaderWriter/Native/WriterNative.cpp Wed Mar 25 20:12:32 2015
@@ -416,7 +416,7 @@ private:
NativeAtomAttributesV1 computeAttributesV1(const DefinedAtom& atom) {
NativeAtomAttributesV1 attrs;
attrs.sectionNameOffset = sectionNameOffset(atom);
- attrs.align2 = atom.alignment().powerOf2;
+ attrs.align2 = llvm::Log2_32(atom.alignment().powerOf2.get());
attrs.alignModulus = atom.alignment().modulus;
attrs.scope = atom.scope();
attrs.interposable = atom.interposable();
Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Wed Mar 25 20:12:32 2015
@@ -849,10 +849,10 @@ uint64_t AtomChunk::memAlign() const {
// the section. We restore that here.
if (_atomLayouts.empty())
return _ctx.getPageSize();
- int align = _ctx.getPageSize();
+ unsigned align = _ctx.getPageSize();
for (auto atomLayout : _atomLayouts) {
auto *atom = cast<const DefinedAtom>(atomLayout->_atom);
- align = std::max(align, 1 << atom->alignment().powerOf2);
+ align = std::max(align, (unsigned)atom->alignment().powerOf2.get());
}
return align;
}
@@ -860,7 +860,7 @@ uint64_t AtomChunk::memAlign() const {
void AtomChunk::appendAtom(const DefinedAtom *atom) {
// Atom may have to be at a proper alignment boundary. If so, move the
// pointer to make a room after the last atom before adding new one.
- _size = llvm::RoundUpToAlignment(_size, 1 << atom->alignment().powerOf2);
+ _size = llvm::RoundUpToAlignment(_size, atom->alignment().powerOf2.get());
// Create an AtomLayout and move the current pointer.
auto *layout = new (_alloc) AtomLayout(atom, _size, _size);
Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Wed Mar 25 20:12:32 2015
@@ -484,9 +484,9 @@ template <> struct ScalarTraits<lld::Def
static void output(const lld::DefinedAtom::Alignment &value, void *ctxt,
raw_ostream &out) {
if (value.modulus == 0) {
- out << llvm::format("%d", 1U << value.powerOf2);
+ out << llvm::format("%d", value.powerOf2.get());
} else {
- out << llvm::format("%d mod %d", value.modulus, 1U << value.powerOf2);
+ out << llvm::format("%d mod %d", value.modulus, value.powerOf2.get());
}
}
@@ -509,7 +509,7 @@ template <> struct ScalarTraits<lld::Def
if (scalar.getAsInteger(0, power)) {
return "malformed alignment power";
}
- value.powerOf2 = llvm::Log2_64(power);
+ value.powerOf2 = PowerOf2(llvm::Log2_64(power));
if (value.modulus >= power) {
return "malformed alignment, modulus too large for power";
}
Modified: lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp (original)
+++ lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp Wed Mar 25 20:12:32 2015
@@ -273,7 +273,7 @@ TEST(BinaryReaderTest, hello_obj_x86_64)
EXPECT_EQ(text.type, S_REGULAR);
EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS));
- EXPECT_EQ(text.alignment, 4U);
+ EXPECT_EQ(text.alignment.get(), 16U);
EXPECT_EQ(text.address, Hex64(0x0));
EXPECT_EQ(text.content.size(), 45UL);
EXPECT_EQ((int)(text.content[0]), 0x55);
@@ -298,7 +298,7 @@ TEST(BinaryReaderTest, hello_obj_x86_64)
EXPECT_TRUE(cstring.sectionName.equals("__cstring"));
EXPECT_EQ(cstring.type, S_CSTRING_LITERALS);
EXPECT_EQ(cstring.attributes, SectionAttr(0));
- EXPECT_EQ(cstring.alignment, 0U);
+ EXPECT_EQ(cstring.alignment.get(), 1U);
EXPECT_EQ(cstring.address, Hex64(0x02D));
EXPECT_EQ(cstring.content.size(), 7UL);
EXPECT_EQ((int)(cstring.content[0]), 0x68);
@@ -399,7 +399,7 @@ TEST(BinaryReaderTest, hello_obj_x86) {
EXPECT_EQ(text.type, S_REGULAR);
EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS));
- EXPECT_EQ(text.alignment, 4U);
+ EXPECT_EQ(text.alignment.get(), 16U);
EXPECT_EQ(text.address, Hex64(0x0));
EXPECT_EQ(text.content.size(), 48UL);
EXPECT_EQ((int)(text.content[0]), 0x55);
@@ -434,7 +434,7 @@ TEST(BinaryReaderTest, hello_obj_x86) {
EXPECT_TRUE(cstring.sectionName.equals("__cstring"));
EXPECT_EQ(cstring.type, S_CSTRING_LITERALS);
EXPECT_EQ(cstring.attributes, SectionAttr(0));
- EXPECT_EQ(cstring.alignment, 0U);
+ EXPECT_EQ(cstring.alignment.get(), 1U);
EXPECT_EQ(cstring.address, Hex64(0x030));
EXPECT_EQ(cstring.content.size(), 7UL);
EXPECT_EQ((int)(cstring.content[0]), 0x68);
@@ -532,7 +532,7 @@ TEST(BinaryReaderTest, hello_obj_armv7)
EXPECT_EQ(text.type, S_REGULAR);
EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS));
- EXPECT_EQ(text.alignment, 2U);
+ EXPECT_EQ(text.alignment.get(), 4U);
EXPECT_EQ(text.address, Hex64(0x0));
EXPECT_EQ(text.content.size(), 42UL);
EXPECT_EQ((int)(text.content[0]), 0x80);
@@ -576,7 +576,7 @@ TEST(BinaryReaderTest, hello_obj_armv7)
EXPECT_TRUE(cstring.sectionName.equals("__cstring"));
EXPECT_EQ(cstring.type, S_CSTRING_LITERALS);
EXPECT_EQ(cstring.attributes, SectionAttr(0));
- EXPECT_EQ(cstring.alignment, 0U);
+ EXPECT_EQ(cstring.alignment.get(), 1U);
EXPECT_EQ(cstring.address, Hex64(0x02A));
EXPECT_EQ(cstring.content.size(), 7UL);
EXPECT_EQ((int)(cstring.content[0]), 0x68);
@@ -677,7 +677,7 @@ TEST(BinaryReaderTest, hello_obj_ppc) {
EXPECT_EQ(text.type, S_REGULAR);
EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS));
- EXPECT_EQ(text.alignment, 2U);
+ EXPECT_EQ(text.alignment.get(), 4U);
EXPECT_EQ(text.address, Hex64(0x0));
EXPECT_EQ(text.content.size(), 68UL);
EXPECT_EQ((int)(text.content[0]), 0x7C);
@@ -720,7 +720,7 @@ TEST(BinaryReaderTest, hello_obj_ppc) {
EXPECT_TRUE(cstring.sectionName.equals("__cstring"));
EXPECT_EQ(cstring.type, S_CSTRING_LITERALS);
EXPECT_EQ(cstring.attributes, SectionAttr(0));
- EXPECT_EQ(cstring.alignment, 2U);
+ EXPECT_EQ(cstring.alignment.get(), 4U);
EXPECT_EQ(cstring.address, Hex64(0x044));
EXPECT_EQ(cstring.content.size(), 7UL);
EXPECT_EQ((int)(cstring.content[0]), 0x68);
Modified: lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp (original)
+++ lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp Wed Mar 25 20:12:32 2015
@@ -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 = 4;
+ text.alignment = lld::PowerOf2(4);
text.address = 0;
const uint8_t textBytes[] = {
0xe8, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8b, 0x05,
@@ -179,7 +179,7 @@ TEST(BinaryWriterTest, obj_relocs_x86_64
EXPECT_EQ(S_REGULAR, text.type);
EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS));
- EXPECT_EQ(text.alignment, 4U);
+ EXPECT_EQ(text.alignment.get(), 16U);
EXPECT_EQ(text.address, Hex64(0x0));
EXPECT_EQ(48UL, text.content.size());
const Relocation& call = text.relocations[0];
@@ -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 = 4;
+ text.alignment = lld::PowerOf2(4);
text.address = 0;
const uint8_t textBytes[] = {
0xe8, 0xfb, 0xff, 0xff, 0xff, 0xa1, 0x00, 0x00,
@@ -290,7 +290,7 @@ TEST(BinaryWriterTest, obj_relocs_x86) {
EXPECT_EQ(S_REGULAR, text.type);
EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS));
- EXPECT_EQ(text.alignment, 4U);
+ EXPECT_EQ(text.alignment.get(), 16U);
EXPECT_EQ(text.address, Hex64(0x0));
EXPECT_EQ(22UL, text.content.size());
const Relocation& call = text.relocations[0];
@@ -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 = 2;
+ text.alignment = lld::PowerOf2(2);
text.address = 0;
const uint8_t textBytes[] = {
0xff, 0xf7, 0xfe, 0xef, 0x40, 0xf2, 0x05, 0x01,
@@ -415,7 +415,7 @@ TEST(BinaryWriterTest, obj_relocs_armv7)
EXPECT_EQ(S_REGULAR, text.type);
EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS));
- EXPECT_EQ(text.alignment, 2U);
+ EXPECT_EQ(text.alignment.get(), 4U);
EXPECT_EQ(text.address, Hex64(0x0));
EXPECT_EQ(18UL, text.content.size());
const Relocation& blx = text.relocations[0];
@@ -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 = 2;
+ text.alignment = lld::PowerOf2(2);
text.address = 0;
const uint8_t textBytes[] = {
0x48, 0x00, 0x00, 0x01, 0x40, 0x82, 0xff, 0xfc,
@@ -571,7 +571,7 @@ TEST(BinaryWriterTest, obj_relocs_ppc) {
EXPECT_EQ(S_REGULAR, text.type);
EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS));
- EXPECT_EQ(text.alignment, 2U);
+ EXPECT_EQ(text.alignment.get(), 4U);
EXPECT_EQ(text.address, Hex64(0x0));
EXPECT_EQ(44UL, text.content.size());
const Relocation& br24 = text.relocations[0];
@@ -690,4 +690,3 @@ TEST(BinaryWriterTest, obj_relocs_ppc) {
std::error_code ec = llvm::sys::fs::remove(Twine(tmpFl));
EXPECT_FALSE(ec);
}
-
Modified: lld/trunk/unittests/MachOTests/MachONormalizedFileYAMLTests.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/MachOTests/MachONormalizedFileYAMLTests.cpp?rev=233242&r1=233241&r2=233242&view=diff
==============================================================================
--- lld/trunk/unittests/MachOTests/MachONormalizedFileYAMLTests.cpp (original)
+++ lld/trunk/unittests/MachOTests/MachONormalizedFileYAMLTests.cpp Wed Mar 25 20:12:32 2015
@@ -213,7 +213,7 @@ TEST(ObjectFileYAML, oneSection) {
EXPECT_EQ((uint32_t)(sect.type), (uint32_t)(llvm::MachO::S_REGULAR));
EXPECT_EQ((uint32_t)(sect.attributes),
(uint32_t)(llvm::MachO::S_ATTR_PURE_INSTRUCTIONS));
- EXPECT_EQ(sect.alignment, 1U);
+ EXPECT_EQ(sect.alignment.get(), 2U);
EXPECT_EQ((uint64_t)sect.address, 0x12345678ULL);
EXPECT_EQ(sect.content.size(), 2UL);
EXPECT_EQ((int)(sect.content[0]), 0x90);
@@ -286,7 +286,7 @@ TEST(ObjectFileYAML, hello_x86_64) {
EXPECT_EQ((uint32_t)(sect1.attributes),
(uint32_t)(llvm::MachO::S_ATTR_PURE_INSTRUCTIONS
| llvm::MachO::S_ATTR_SOME_INSTRUCTIONS));
- EXPECT_EQ(sect1.alignment, 0U);
+ EXPECT_EQ(sect1.alignment.get(), 1U);
EXPECT_EQ((uint64_t)sect1.address, 0x0ULL);
EXPECT_EQ(sect1.content.size(), 22UL);
EXPECT_EQ((int)(sect1.content[0]), 0x55);
@@ -316,7 +316,7 @@ TEST(ObjectFileYAML, hello_x86_64) {
EXPECT_TRUE(sect2.sectionName.equals("__cstring"));
EXPECT_EQ((uint32_t)(sect2.type), (uint32_t)(llvm::MachO::S_CSTRING_LITERALS));
EXPECT_EQ((uint32_t)(sect2.attributes), 0U);
- EXPECT_EQ(sect2.alignment, 0U);
+ EXPECT_EQ(sect2.alignment.get(), 1U);
EXPECT_EQ((uint64_t)sect2.address, 0x016ULL);
EXPECT_EQ(sect2.content.size(), 7UL);
EXPECT_EQ((int)(sect2.content[0]), 0x68);
@@ -417,7 +417,7 @@ TEST(ObjectFileYAML, hello_x86) {
EXPECT_EQ((uint32_t)(sect1.attributes),
(uint32_t)(llvm::MachO::S_ATTR_PURE_INSTRUCTIONS
| llvm::MachO::S_ATTR_SOME_INSTRUCTIONS));
- EXPECT_EQ(sect1.alignment, 0U);
+ EXPECT_EQ(sect1.alignment.get(), 1U);
EXPECT_EQ((uint64_t)sect1.address, 0x0ULL);
EXPECT_EQ(sect1.content.size(), 33UL);
EXPECT_EQ((int)(sect1.content[0]), 0x55);
@@ -454,7 +454,7 @@ TEST(ObjectFileYAML, hello_x86) {
EXPECT_TRUE(sect2.sectionName.equals("__cstring"));
EXPECT_EQ((uint32_t)(sect2.type), (uint32_t)(llvm::MachO::S_CSTRING_LITERALS));
EXPECT_EQ((uint32_t)(sect2.attributes), 0U);
- EXPECT_EQ(sect2.alignment, 0U);
+ EXPECT_EQ(sect2.alignment.get(), 1U);
EXPECT_EQ((uint64_t)sect2.address, 0x021ULL);
EXPECT_EQ(sect2.content.size(), 7UL);
EXPECT_EQ((int)(sect2.content[0]), 0x68);
@@ -545,7 +545,7 @@ TEST(ObjectFileYAML, hello_armv6) {
EXPECT_EQ((uint32_t)(sect1.attributes),
(uint32_t)(llvm::MachO::S_ATTR_PURE_INSTRUCTIONS
| llvm::MachO::S_ATTR_SOME_INSTRUCTIONS));
- EXPECT_EQ(sect1.alignment, 2U);
+ EXPECT_EQ(sect1.alignment.get(), 4U);
EXPECT_EQ((uint64_t)sect1.address, 0x0ULL);
EXPECT_EQ(sect1.content.size(), 32UL);
EXPECT_EQ((int)(sect1.content[0]), 0x80);
@@ -582,7 +582,7 @@ TEST(ObjectFileYAML, hello_armv6) {
EXPECT_TRUE(sect2.sectionName.equals("__cstring"));
EXPECT_EQ((uint32_t)(sect2.type), (uint32_t)(llvm::MachO::S_CSTRING_LITERALS));
EXPECT_EQ((uint32_t)(sect2.attributes), 0U);
- EXPECT_EQ(sect2.alignment, 0U);
+ EXPECT_EQ(sect2.alignment.get(), 1U);
EXPECT_EQ((uint64_t)sect2.address, 0x020ULL);
EXPECT_EQ(sect2.content.size(), 7UL);
EXPECT_EQ((int)(sect2.content[0]), 0x68);
@@ -687,7 +687,7 @@ TEST(ObjectFileYAML, hello_armv7) {
EXPECT_EQ((uint32_t)(sect1.attributes),
(uint32_t)(llvm::MachO::S_ATTR_PURE_INSTRUCTIONS
| llvm::MachO::S_ATTR_SOME_INSTRUCTIONS));
- EXPECT_EQ(sect1.alignment, 1U);
+ EXPECT_EQ(sect1.alignment.get(), 2U);
EXPECT_EQ((uint64_t)sect1.address, 0x0ULL);
EXPECT_EQ(sect1.content.size(), 22UL);
EXPECT_EQ((int)(sect1.content[0]), 0x80);
@@ -740,7 +740,7 @@ TEST(ObjectFileYAML, hello_armv7) {
EXPECT_TRUE(sect2.sectionName.equals("__cstring"));
EXPECT_EQ((uint32_t)(sect2.type), (uint32_t)(llvm::MachO::S_CSTRING_LITERALS));
EXPECT_EQ((uint32_t)(sect2.attributes), 0U);
- EXPECT_EQ(sect2.alignment, 0U);
+ EXPECT_EQ(sect2.alignment.get(), 1U);
EXPECT_EQ((uint64_t)sect2.address, 0x016ULL);
EXPECT_EQ(sect2.content.size(), 7UL);
EXPECT_EQ((int)(sect2.content[0]), 0x68);
More information about the llvm-commits
mailing list