public:
MachODefinedAtom(const File &f, const StringRef name, Scope scope,
ContentType type, Merge merge, bool thumb, bool noDeadStrip,
- const ArrayRef<uint8_t> content)
+ const ArrayRef<uint8_t> content, Alignment align)
: SimpleDefinedAtom(f), _name(name), _content(content),
- _contentType(type), _scope(scope), _merge(merge), _thumb(thumb),
- _noDeadStrip(noDeadStrip) {}
+ _align(align), _contentType(type), _scope(scope), _merge(merge),
+ _thumb(thumb), _noDeadStrip(noDeadStrip) {}
// Constructor for zero-fill content
MachODefinedAtom(const File &f, const StringRef name, Scope scope,
- uint64_t size, bool noDeadStrip)
+ uint64_t size, bool noDeadStrip, Alignment align)
: SimpleDefinedAtom(f), _name(name),
- _content(ArrayRef<uint8_t>(nullptr, size)),
+ _content(ArrayRef<uint8_t>(nullptr, size)), _align(align),
_contentType(DefinedAtom::typeZeroFill),
_scope(scope), _merge(mergeNo), _thumb(false),
_noDeadStrip(noDeadStrip) {}
ContentType contentType() const override { return _contentType; }
+ Alignment alignment() const override { return _align; }
+
StringRef name() const override { return _name; }
Scope scope() const override { return _scope; }
private:
const StringRef _name;
const ArrayRef<uint8_t> _content;
+ const DefinedAtom::Alignment _align;
const ContentType _contentType;
const Scope _scope;
const Merge _merge;
Scope scope, ContentType type, Merge merge,
bool thumb, bool noDeadStrip,
const ArrayRef<uint8_t> content,
- StringRef sectionName)
+ StringRef sectionName, Alignment align)
: MachODefinedAtom(f, name, scope, type, merge, thumb, noDeadStrip,
- content),
+ content, align),
_sectionName(sectionName) {}
SectionChoice sectionChoice() const override {
_definedAtoms._atoms.push_back(new (_alloc) MachODefinedAtom(
*this, sym, DefinedAtom::scopeLinkageUnit,
DefinedAtom::typeMachHeader, DefinedAtom::mergeNo, false, false,
- ArrayRef<uint8_t>()));
+ ArrayRef<uint8_t>(), DefinedAtom::Alignment(12,0)));
return this;
}
return nullptr;
name = name.copy(_allocator);
content = content.copy(_allocator);
}
+ DefinedAtom::Alignment align(inSection->alignment,
+ sectionOffset % (1 << inSection->alignment));
MachODefinedAtom *atom =
new (_allocator) MachODefinedAtom(*this, name, scope, type, merge,
- thumb, noDeadStrip, content);
+ thumb, noDeadStrip, content, align);
addAtomForSection(inSection, atom, sectionOffset);
}
content = content.copy(_allocator);
sectionName = sectionName.copy(_allocator);
}
+ DefinedAtom::Alignment align(inSection->alignment,
+ sectionOffset % (1 << inSection->alignment));
MachODefinedCustomSectionAtom *atom =
new (_allocator) MachODefinedCustomSectionAtom(*this, name, scope, type,
merge, thumb,
noDeadStrip, content,
- sectionName);
+ sectionName, align);
addAtomForSection(inSection, atom, sectionOffset);
}
// Make a copy of the atom's name and content that is owned by this file.
name = name.copy(_allocator);
}
+ DefinedAtom::Alignment align(inSection->alignment,
+ sectionOffset % (1 << inSection->alignment));
MachODefinedAtom *atom =
- new (_allocator) MachODefinedAtom(*this, name, scope, size, noDeadStrip);
+ new (_allocator) MachODefinedAtom(*this, name, scope, size, noDeadStrip,
+ align);
addAtomForSection(inSection, atom, sectionOffset);
}
--- /dev/null
+# RUN: lld -flavor darwin -arch x86_64 -r %s -o %t -print_atoms | FileCheck %s
+# RUN: lld -flavor darwin -arch x86_64 -r %t -o %t2 -print_atoms | FileCheck %s
+#
+# Test that alignment info round trips through -r
+#
+
+--- !mach-o
+arch: x86_64
+file-type: MH_OBJECT
+flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ]
+sections:
+ - segment: __TEXT
+ section: __text
+ type: S_REGULAR
+ attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
+ alignment: 4
+ address: 0x0000000000000000
+ content: [ 0x90, 0x90, 0x90, 0xC3, 0xC3, 0xC3 ]
+local-symbols:
+ - name: _f1
+ type: N_SECT
+ sect: 1
+ value: 0x0000000000000003
+ - name: _f2
+ type: N_SECT
+ sect: 1
+ value: 0x0000000000000004
+ - name: _f3
+ type: N_SECT
+ sect: 1
+ value: 0x0000000000000005
+...
+
+# CHECK: defined-atoms:
+# CHECK: - content: [ 90, 90, 90 ]
+# CHECK: alignment: 2^4
+# CHECK: - name: _f1
+# CHECK: content: [ C3 ]
+# CHECK: alignment: 3 mod 2^4
+# CHECK: - name: _f2
+# CHECK: content: [ C3 ]
+# CHECK: alignment: 4 mod 2^4
+# CHECK: - name: _f3
+# CHECK: content: [ C3 ]
+# CHECK: alignment: 5 mod 2^4