Use alignment values everywhere instead of log2.

This patch defines implicit conversion between integers and PowerOf2
instances, so uses of the classes is now implicit and look like
regular integers. Now we are ready to remove the scaffolding.

llvm-svn: 233245
This commit is contained in:
Rui Ueyama 2015-03-26 02:03:44 +00:00
parent f006f4d62c
commit f217ef0d75
32 changed files with 99 additions and 117 deletions

View File

@ -32,7 +32,7 @@ class PowerOf2 {
public:
PowerOf2(uint16_t v) : _v(v) {}
bool operator==(const PowerOf2 &other) const { return _v == other._v; }
uint16_t get() const { return _v; }
operator uint16_t() const { return _v; }
private:
uint16_t _v;
};
@ -218,14 +218,13 @@ public:
};
struct Alignment {
Alignment(int p2, int m = 0) : powerOf2(1 << p2), modulus(m) {}
Alignment(PowerOf2 p2, int m = 0) : powerOf2(p2), modulus(m) {}
Alignment(int v, int m = 0) : value(v), modulus(m) {}
PowerOf2 powerOf2;
PowerOf2 value;
uint16_t modulus;
bool operator==(const Alignment &rhs) const {
return (powerOf2.get() == rhs.powerOf2.get()) && (modulus == rhs.modulus);
return (value == rhs.value) && (modulus == rhs.modulus);
}
};

View File

@ -224,7 +224,7 @@ public:
Merge merge() const override { return DefinedAtom::mergeNo; }
Alignment alignment() const override { return Alignment(0, 0); }
Alignment alignment() const override { return 1; }
SectionChoice sectionChoice() const override {
return DefinedAtom::sectionBasedOnContent;

View File

@ -485,7 +485,7 @@ bool DarwinLdDriver::parse(int argc, const char *argv[],
<< segName << " " << sectName
<< llvm::format(" 0x%llX", alignValue)
<< "' is not a power of two, using "
<< llvm::format("0x%08X", align2.get()) << "\n";
<< llvm::format("0x%08X", align2) << "\n";
}
ctx.addSectionAlignment(segName, sectName, align2);
}

View File

@ -43,7 +43,7 @@ public:
ContentType contentType() const override { return DefinedAtom::typeStub; }
Alignment alignment() const override { return Alignment(0, 0); }
Alignment alignment() const override { return 1; }
SectionChoice sectionChoice() const override {
return DefinedAtom::sectionBasedOnContent;
@ -104,7 +104,7 @@ public:
ContentType contentType() const override { return DefinedAtom::typeGOT; }
Alignment alignment() const override { return Alignment(3, 0); }
Alignment alignment() const override { return 8; }
SectionChoice sectionChoice() const override {
return DefinedAtom::sectionBasedOnContent;

View File

@ -73,7 +73,7 @@ public:
ContentPermissions permissions() const override { return permR_X; }
Alignment alignment() const override { return Alignment(2); }
Alignment alignment() const override { return 4; }
StringRef name() const override { return _name; }
std::string _name;
@ -116,7 +116,7 @@ public:
return llvm::makeArrayRef(ARMGotAtomContent);
}
Alignment alignment() const override { return Alignment(2); }
Alignment alignment() const override { return 4; }
};
class ELFPassFile : public SimpleFile {

View File

@ -290,7 +290,7 @@ public:
Alignment alignment() const override {
if (!_symbol)
return Alignment(0);
return 1;
// Obtain proper value of st_value field.
const auto symValue = getSymbolValue(_symbol);
@ -299,13 +299,13 @@ public:
// st_value.
if ((_symbol->getType() == llvm::ELF::STT_COMMON) ||
_symbol->st_shndx == llvm::ELF::SHN_COMMON) {
return Alignment(llvm::Log2_64(symValue));
return symValue;
}
if (_section->sh_addralign == 0) {
// sh_addralign of 0 means no alignment
return Alignment(0, symValue);
return Alignment(1, symValue);
}
return Alignment(llvm::Log2_64(_section->sh_addralign),
return Alignment(_section->sh_addralign,
symValue % _section->sh_addralign);
}
@ -485,7 +485,7 @@ public:
ContentType contentType() const override { return typeConstant; }
Alignment alignment() const override {
return Alignment(llvm::Log2_64(_section->sh_addralign));
return Alignment(_section->sh_addralign);
}
SectionChoice sectionChoice() const override { return sectionCustomRequired; }
@ -561,9 +561,7 @@ public:
ContentType contentType() const override { return typeZeroFill; }
Alignment alignment() const override {
return Alignment(llvm::Log2_64(_symbol->st_value));
}
Alignment alignment() const override { return Alignment(_symbol->st_value); }
SectionChoice sectionChoice() const override { return sectionBasedOnContent; }
@ -710,10 +708,7 @@ public:
ArrayRef<uint8_t> rawContent() const override { return ArrayRef<uint8_t>(); }
Alignment alignment() const override {
// The alignment should be 8 byte aligned
return Alignment(3);
}
Alignment alignment() const override { return 8; }
StringRef name() const override { return _name; }
@ -740,10 +735,7 @@ public:
ContentPermissions permissions() const override { return permRW_; }
Alignment alignment() const override {
// The alignment should be 8 byte aligned
return Alignment(3);
}
Alignment alignment() const override { return 8; }
#ifndef NDEBUG
StringRef name() const override { return _name; }
@ -772,9 +764,7 @@ public:
ContentPermissions permissions() const override { return permR_X; }
Alignment alignment() const override {
return Alignment(4); // 16
}
Alignment alignment() const override { return 16; }
#ifndef NDEBUG
StringRef name() const override { return _name; }
@ -811,10 +801,7 @@ public:
ContentPermissions permissions() const override { return permRW_; }
Alignment alignment() const override {
// Needs 8 byte alignment
return Alignment(3);
}
Alignment alignment() const override { return 8; }
ArrayRef<uint8_t> rawContent() const override { return ArrayRef<uint8_t>(); }
};
@ -839,7 +826,7 @@ public:
ContentPermissions permissions() const override { return permRW_; }
Alignment alignment() const override { return Alignment(0); }
Alignment alignment() const override { return 1; }
ArrayRef<uint8_t> rawContent() const override { return ArrayRef<uint8_t>(); }
};

View File

@ -93,8 +93,8 @@ public:
virtual DefinedAtom::Alignment alignment() const {
if (isSmallCommonSymbol())
return DefinedAtom::Alignment(llvm::Log2_64(this->_symbol->st_value));
return ELFCommonAtom<ELFT>::alignment();
return DefinedAtom::Alignment(this->_symbol->st_value);
return 1;
}
virtual DefinedAtom::ContentPermissions permissions() const {

View File

@ -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 = atomAlign.powerOf2.get();
uint64_t alignment = atomAlign.value;
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>::doPreFlight() {
const lld::AtomLayout * B) {
const DefinedAtom *definedAtomA = cast<DefinedAtom>(A->_atom);
const DefinedAtom *definedAtomB = cast<DefinedAtom>(B->_atom);
int64_t alignmentA = definedAtomA->alignment().powerOf2.get();
int64_t alignmentB = definedAtomB->alignment().powerOf2.get();
int64_t alignmentA = definedAtomA->alignment().value;
int64_t alignmentB = definedAtomB->alignment().value;
if (alignmentA == alignmentB) {
if (definedAtomA->merge() == DefinedAtom::mergeAsTentative)
return false;

View File

@ -77,7 +77,7 @@ public:
return makeArrayRef(hexagonGotAtomContent);
}
Alignment alignment() const override { return Alignment(2); }
Alignment alignment() const override { return 4; }
};
class HexagonGOTPLTAtom : public GOTAtom {
@ -88,7 +88,7 @@ public:
return makeArrayRef(hexagonGotPltAtomContent);
}
Alignment alignment() const override { return Alignment(2); }
Alignment alignment() const override { return 4; }
};
class HexagonGOTPLT0Atom : public GOTAtom {
@ -99,7 +99,7 @@ public:
return makeArrayRef(hexagonGotPlt0AtomContent);
}
Alignment alignment() const override { return Alignment(3); }
Alignment alignment() const override { return 8; }
};
class HexagonPLT0Atom : public PLT0Atom {

View File

@ -109,7 +109,7 @@ class MipsGOTAtom : public GOTAtom {
public:
MipsGOTAtom(const File &f) : GOTAtom(f, ".got") {}
Alignment alignment() const override { return Alignment(2); }
Alignment alignment() const override { return 4; }
};
/// \brief MIPS GOT entry initialized by zero.
@ -173,7 +173,7 @@ public:
addReferenceELF_Mips(R_MIPS_32, 0, plt0, 0);
}
Alignment alignment() const override { return Alignment(2); }
Alignment alignment() const override { return 4; }
ArrayRef<uint8_t> rawContent() const override {
return llvm::makeArrayRef(mipsGot0AtomContent).slice(4);
@ -238,7 +238,7 @@ public:
addReferenceELF_Mips(R_MICROMIPS_PC23_S2, 0, got, 0);
}
Alignment alignment() const override { return Alignment(1); }
Alignment alignment() const override { return 2; }
CodeModel codeModel() const override { return codeMipsMicro; }
ArrayRef<uint8_t> rawContent() const override {

View File

@ -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 = atomAlign.powerOf2.get();
uint64_t alignment = atomAlign.value;
uint64_t currentModulus = (offset % alignment);
uint64_t retOffset = offset;
if (currentModulus != requiredModulus) {
@ -330,7 +330,7 @@ const lld::AtomLayout *AtomSection<ELFT>::appendAtom(const Atom *atom) {
const DefinedAtom *definedAtom = cast<DefinedAtom>(atom);
DefinedAtom::Alignment atomAlign = definedAtom->alignment();
uint64_t alignment = atomAlign.powerOf2.get();
uint64_t alignment = atomAlign.value;
// 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

View File

@ -1433,9 +1433,7 @@ public:
return DefinedAtom::typeCode;
}
Alignment alignment() const override {
return Alignment(2);
}
Alignment alignment() const override { return 4; }
uint64_t size() const override {
return 12;
@ -1479,9 +1477,7 @@ public:
return DefinedAtom::typeCode;
}
Alignment alignment() const override {
return Alignment(2);
}
Alignment alignment() const override { return 4; }
uint64_t size() const override {
return 16;

View File

@ -92,7 +92,7 @@ public:
return DefinedAtom::typeProcessedUnwindInfo;
}
Alignment alignment() const override { return Alignment(2); }
Alignment alignment() const override { return 4; }
uint64_t size() const override { return _contents.size(); }

View File

@ -100,7 +100,7 @@ public:
_definedAtoms._atoms.push_back(new (allocator()) MachODefinedAtom(
*this, sym, DefinedAtom::scopeLinkageUnit,
DefinedAtom::typeMachHeader, DefinedAtom::mergeNo, false, false,
ArrayRef<uint8_t>(), DefinedAtom::Alignment(12,0)));
ArrayRef<uint8_t>(), DefinedAtom::Alignment(4096)));
return this;
}
return nullptr;

View File

@ -44,7 +44,7 @@ public:
}
DefinedAtom::Alignment align(
inSection->alignment,
sectionOffset % inSection->alignment.get());
sectionOffset % inSection->alignment);
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 % inSection->alignment.get());
sectionOffset % inSection->alignment);
MachODefinedCustomSectionAtom *atom =
new (allocator()) MachODefinedCustomSectionAtom(*this, name, scope, type,
merge, thumb,
@ -86,7 +86,7 @@ public:
}
DefinedAtom::Alignment align(
inSection->alignment,
sectionOffset % inSection->alignment.get());
sectionOffset % inSection->alignment);
MachODefinedAtom *atom =
new (allocator()) MachODefinedAtom(*this, name, scope, size, noDeadStrip,
align);

View File

@ -60,7 +60,7 @@ public:
}
Alignment alignment() const override {
return Alignment(_is64 ? 3 : 2);
return _is64 ? 8 : 4;
}
uint64_t size() const override {

View File

@ -291,7 +291,7 @@ MachOFileLayout::MachOFileLayout(const NormalizedFile &file)
uint64_t offset = _startOfSectionsContent;
for (const Section &sect : file.sections) {
if (sect.type != llvm::MachO::S_ZEROFILL) {
offset = llvm::RoundUpToAlignment(offset, sect.alignment.get());
offset = llvm::RoundUpToAlignment(offset, sect.alignment);
_sectInfo[&sect].fileOffset = offset;
offset += sect.content.size();
} else {
@ -613,7 +613,7 @@ std::error_code MachOFileLayout::writeSingleSegmentLoadCommand(uint8_t *&lc) {
sout->addr = sin.address;
sout->size = sin.content.size();
sout->offset = _sectInfo[&sin].fileOffset;
sout->align = llvm::Log2_32(sin.alignment.get());
sout->align = llvm::Log2_32(sin.alignment);
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::writeSegmentLoadCommands(uint8_t *&lc) {
sect->offset = 0;
else
sect->offset = section->address - seg.address + segInfo.fileOffset;
sect->align = llvm::Log2_32(section->alignment.get());
sect->align = llvm::Log2_32(section->alignment);
sect->reloff = 0;
sect->nreloc = 0;
sect->flags = section->type | section->attributes;

View File

@ -328,7 +328,7 @@ void Util::appendAtom(SectionInfo *sect, const DefinedAtom *atom) {
// Figure out offset for atom in this section given alignment constraints.
uint64_t offset = sect->size;
DefinedAtom::Alignment atomAlign = atom->alignment();
uint64_t align2 = atomAlign.powerOf2.get();
uint64_t align2 = atomAlign.value;
uint64_t requiredModulus = atomAlign.modulus;
uint64_t currentModulus = (offset % align2);
if ( currentModulus != requiredModulus ) {
@ -338,8 +338,8 @@ void Util::appendAtom(SectionInfo *sect, const DefinedAtom *atom) {
offset += align2+requiredModulus-currentModulus;
}
// Record max alignment of any atom in this section.
if (align2 > sect->alignment.get())
sect->alignment = atomAlign.powerOf2;
if (align2 > sect->alignment)
sect->alignment = atomAlign.value;
// Assign atom to this section with this offset.
AtomInfo ai = {atom, offset};
sect->atomsAndOffsets.push_back(ai);
@ -454,7 +454,7 @@ void Util::organizeSections() {
}
uint64_t Util::alignTo(uint64_t value, PowerOf2 align2) {
return llvm::RoundUpToAlignment(value, align2.get());
return llvm::RoundUpToAlignment(value, align2);
}
@ -477,7 +477,7 @@ void Util::layoutSectionsInTextSegment(size_t hlcSize, SegmentInfo *seg,
for (auto it = seg->sections.rbegin(); it != seg->sections.rend(); ++it) {
SectionInfo *sect = *it;
taddr -= sect->size;
taddr = taddr & (0 - sect->alignment.get());
taddr = taddr & (0 - sect->alignment);
}
int64_t padding = taddr - hlcSize;
while (padding < 0)

View File

@ -759,7 +759,8 @@ normalizedObjectToAtoms(MachOFile *file,
file->addUndefinedAtom(sym.name, copyRefs);
} else {
file->addTentativeDefAtom(sym.name, atomScope(sym.scope), sym.value,
DefinedAtom::Alignment(sym.desc >> 8), copyRefs);
DefinedAtom::Alignment(1 << (sym.desc >> 8)),
copyRefs);
}
}

View File

@ -44,7 +44,7 @@ public:
}
Alignment alignment() const override {
return Alignment(_is64 ? 3 : 2);
return _is64 ? 8 : 4;
}
uint64_t size() const override {
@ -79,7 +79,7 @@ public:
}
Alignment alignment() const override {
return Alignment(_is64 ? 3 : 2);
return _is64 ? 8 : 4;
}
uint64_t size() const override {
@ -115,7 +115,7 @@ public:
}
Alignment alignment() const override {
return Alignment(_stubInfo.codeAlignment);
return 1 << _stubInfo.codeAlignment;
}
uint64_t size() const override {
@ -148,7 +148,7 @@ public:
}
Alignment alignment() const override {
return Alignment(_stubInfo.codeAlignment);
return 1 << _stubInfo.codeAlignment;
}
uint64_t size() const override {
@ -182,7 +182,7 @@ public:
}
Alignment alignment() const override {
return Alignment(_stubInfo.codeAlignment);
return 1 << _stubInfo.codeAlignment;
}
uint64_t size() const override {

View File

@ -67,7 +67,8 @@ public:
}
DefinedAtom::Alignment alignment() const override {
return DefinedAtom::Alignment(attributes().align2, attributes().alignModulus);
return DefinedAtom::Alignment(1 << attributes().align2,
attributes().alignModulus);
}
DefinedAtom::SectionChoice sectionChoice() const override {

View File

@ -416,7 +416,7 @@ private:
NativeAtomAttributesV1 computeAttributesV1(const DefinedAtom& atom) {
NativeAtomAttributesV1 attrs;
attrs.sectionNameOffset = sectionNameOffset(atom);
attrs.align2 = llvm::Log2_32(atom.alignment().powerOf2.get());
attrs.align2 = llvm::Log2_32(atom.alignment().value);
attrs.alignModulus = atom.alignment().modulus;
attrs.scope = atom.scope();
attrs.interposable = atom.interposable();

View File

@ -52,7 +52,7 @@ public:
StringRef name() const override { return _name; }
Interposable interposable() const override { return interposeNo; }
Merge merge() const override { return mergeNo; }
Alignment alignment() const override { return Alignment(0); }
Alignment alignment() const override { return 1; }
StringRef customSectionName() const override { return ""; }
DeadStripKind deadStrip() const override { return deadStripNormal; }
@ -102,7 +102,7 @@ public:
uint64_t ordinal)
: COFFBaseDefinedAtom(file, name, Kind::File), _sectionName(sectionName),
_sectionSize(sectionSize), _scope(scope), _contentType(contentType),
_permissions(perms), _ordinal(ordinal), _alignment(0) {}
_permissions(perms), _ordinal(ordinal), _alignment(1) {}
static bool classof(const COFFBaseDefinedAtom *atom) {
return atom->getKind() == Kind::File;
@ -189,7 +189,7 @@ public:
SectionChoice sectionChoice() const override { return sectionBasedOnContent; }
uint64_t ordinal() const override { return _ordinal; }
Scope scope() const override { return scopeGlobal; }
Alignment alignment() const override { return Alignment(0); }
Alignment alignment() const override { return 1; }
uint64_t size() const override { return _data.size(); }
ArrayRef<uint8_t> rawContent() const override { return _data; }

View File

@ -163,7 +163,7 @@ class DelayImportAddressAtom : public IdataAtom {
public:
explicit DelayImportAddressAtom(IdataContext &context)
: IdataAtom(context, createContent(context.ctx)),
_align(Alignment(context.ctx.is64Bit() ? 3 : 2)) {}
_align(context.ctx.is64Bit() ? 8 : 4) {}
StringRef customSectionName() const override { return ".data"; }
ContentPermissions permissions() const override { return permRW_; }
Alignment alignment() const override { return _align; }
@ -183,7 +183,7 @@ public:
const Atom *descAtom, const Atom *delayLoadHelperAtom);
StringRef customSectionName() const override { return ".text"; }
ContentPermissions permissions() const override { return permR_X; }
Alignment alignment() const override { return Alignment(0); }
Alignment alignment() const override { return 1; }
private:
std::vector<uint8_t> createContent(MachineTypes machine) const;

View File

@ -35,7 +35,7 @@ public:
uint64_t ordinal() const override { return _ordinal; }
Scope scope() const override { return scopeGlobal; }
ContentType contentType() const override { return typeData; }
Alignment alignment() const override { return Alignment(4); }
Alignment alignment() const override { return 16; }
ContentPermissions permissions() const override { return permR__; }
private:

View File

@ -242,7 +242,7 @@ DefinedAtom::ContentPermissions getPermissions(const coff_section *section) {
/// aligned by this value in the resulting executable/DLL.
DefinedAtom::Alignment getAlignment(const coff_section *section) {
if (section->Characteristics & llvm::COFF::IMAGE_SCN_TYPE_NO_PAD)
return DefinedAtom::Alignment(0);
return 1;
// Bit [20:24] contains section alignment information. We need to decrease
// the value stored by 1 in order to get the real exponent (e.g, ALIGN_1BYTE
@ -254,10 +254,10 @@ DefinedAtom::Alignment getAlignment(const coff_section *section) {
// in characteristics[20:24], and its output is intended to be copied to .rsrc
// section with no padding, so I think doing this is the right thing.
if (characteristics == 0)
return DefinedAtom::Alignment(0);
return 1;
uint32_t powerOf2 = characteristics - 1;
return DefinedAtom::Alignment(powerOf2);
return 1 << powerOf2;
}
DefinedAtom::Merge getMerge(const coff_aux_section_definition *auxsym) {
@ -543,9 +543,7 @@ FileCOFF::createDefinedSymbols(const SymbolVectorT &symbols,
// Common symbols should be aligned on natural boundaries with the maximum
// of 32 byte. It's not documented anywhere, but it's what MSVC link.exe
// seems to be doing.
uint64_t alignment = std::min((uint64_t)32, llvm::NextPowerOf2(size));
atom->setAlignment(
DefinedAtom::Alignment(llvm::countTrailingZeros(alignment)));
atom->setAlignment(std::min((uint64_t)32, llvm::NextPowerOf2(size)));
result.push_back(atom);
continue;
}

View File

@ -216,7 +216,7 @@ public:
uint64_t ordinal() const override { return 0; }
Scope scope() const override { return scopeGlobal; }
ContentType contentType() const override { return typeCode; }
Alignment alignment() const override { return Alignment(1); }
Alignment alignment() const override { return 2; }
ContentPermissions permissions() const override { return permR_X; }
private:

View File

@ -852,7 +852,7 @@ uint64_t AtomChunk::memAlign() const {
unsigned align = _ctx.getPageSize();
for (auto atomLayout : _atomLayouts) {
auto *atom = cast<const DefinedAtom>(atomLayout->_atom);
align = std::max(align, (unsigned)atom->alignment().powerOf2.get());
align = std::max(align, (unsigned)atom->alignment().value);
}
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, atom->alignment().powerOf2.get());
_size = llvm::RoundUpToAlignment(_size, atom->alignment().value);
// Create an AtomLayout and move the current pointer.
auto *layout = new (_alloc) AtomLayout(atom, _size, _size);

View File

@ -484,9 +484,9 @@ template <> struct ScalarTraits<lld::DefinedAtom::Alignment> {
static void output(const lld::DefinedAtom::Alignment &value, void *ctxt,
raw_ostream &out) {
if (value.modulus == 0) {
out << llvm::format("%d", value.powerOf2.get());
out << llvm::format("%d", value.value);
} else {
out << llvm::format("%d mod %d", value.modulus, value.powerOf2.get());
out << llvm::format("%d mod %d", value.modulus, value.value);
}
}
@ -509,7 +509,7 @@ template <> struct ScalarTraits<lld::DefinedAtom::Alignment> {
if (scalar.getAsInteger(0, power)) {
return "malformed alignment power";
}
value.powerOf2 = power;
value.value = power;
if (value.modulus >= power) {
return "malformed alignment, modulus too large for power";
}
@ -791,7 +791,7 @@ template <> struct MappingTraits<const lld::DefinedAtom *> {
public:
NormalizedAtom(IO &io)
: _file(fileFromContext(io)), _name(), _refName(), _contentType(),
_alignment(0), _content(), _references(), _isGroupChild(false) {
_alignment(1), _content(), _references(), _isGroupChild(false) {
static uint32_t ordinalCounter = 1;
_ordinal = ordinalCounter++;
}
@ -937,7 +937,7 @@ template <> struct MappingTraits<const lld::DefinedAtom *> {
DefinedAtom::interposeNo);
io.mapOptional("merge", keys->_merge, DefinedAtom::mergeNo);
io.mapOptional("alignment", keys->_alignment,
DefinedAtom::Alignment(0));
DefinedAtom::Alignment(1));
io.mapOptional("section-choice", keys->_sectionChoice,
DefinedAtom::sectionBasedOnContent);
io.mapOptional("section-name", keys->_sectionName, StringRef());

View File

@ -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.get(), 16U);
EXPECT_EQ((uint16_t)text.alignment, 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.get(), 1U);
EXPECT_EQ((uint16_t)cstring.alignment, 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.get(), 16U);
EXPECT_EQ((uint16_t)text.alignment, 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.get(), 1U);
EXPECT_EQ((uint16_t)cstring.alignment, 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.get(), 4U);
EXPECT_EQ((uint16_t)text.alignment, 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.get(), 1U);
EXPECT_EQ((uint16_t)cstring.alignment, 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.get(), 4U);
EXPECT_EQ((uint16_t)text.alignment, 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.get(), 4U);
EXPECT_EQ((uint16_t)cstring.alignment, 4U);
EXPECT_EQ(cstring.address, Hex64(0x044));
EXPECT_EQ(cstring.content.size(), 7UL);
EXPECT_EQ((int)(cstring.content[0]), 0x68);

View File

@ -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.get(), 16U);
EXPECT_EQ((uint16_t)text.alignment, 16U);
EXPECT_EQ(text.address, Hex64(0x0));
EXPECT_EQ(48UL, text.content.size());
const Relocation& call = text.relocations[0];
@ -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.get(), 16U);
EXPECT_EQ((uint16_t)text.alignment, 16U);
EXPECT_EQ(text.address, Hex64(0x0));
EXPECT_EQ(22UL, text.content.size());
const Relocation& call = text.relocations[0];
@ -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.get(), 4U);
EXPECT_EQ((uint16_t)text.alignment, 4U);
EXPECT_EQ(text.address, Hex64(0x0));
EXPECT_EQ(18UL, text.content.size());
const Relocation& blx = text.relocations[0];
@ -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.get(), 4U);
EXPECT_EQ((uint16_t)text.alignment, 4U);
EXPECT_EQ(text.address, Hex64(0x0));
EXPECT_EQ(44UL, text.content.size());
const Relocation& br24 = text.relocations[0];

View File

@ -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.get(), 2U);
EXPECT_EQ((uint16_t)sect.alignment, 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.get(), 1U);
EXPECT_EQ((uint16_t)sect1.alignment, 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.get(), 1U);
EXPECT_EQ((uint16_t)sect2.alignment, 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.get(), 1U);
EXPECT_EQ((uint16_t)sect1.alignment, 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.get(), 1U);
EXPECT_EQ((uint16_t)sect2.alignment, 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.get(), 4U);
EXPECT_EQ((uint16_t)sect1.alignment, 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.get(), 1U);
EXPECT_EQ((uint16_t)sect2.alignment, 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.get(), 2U);
EXPECT_EQ((uint16_t)sect1.alignment, 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.get(), 1U);
EXPECT_EQ((uint16_t)sect2.alignment, 1U);
EXPECT_EQ((uint64_t)sect2.address, 0x016ULL);
EXPECT_EQ(sect2.content.size(), 7UL);
EXPECT_EQ((int)(sect2.content[0]), 0x68);