[lld] r222201 - [mach-o] extract atom alignment information from mach-o files
Nick Kledzik
kledzik at apple.com
Mon Nov 17 16:30:26 PST 2014
Author: kledzik
Date: Mon Nov 17 18:30:25 2014
New Revision: 222201
URL: http://llvm.org/viewvc/llvm-project?rev=222201&view=rev
Log:
[mach-o] extract atom alignment information from mach-o files
Added:
lld/trunk/test/mach-o/align_text.yaml
Modified:
lld/trunk/lib/ReaderWriter/MachO/Atoms.h
lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp
lld/trunk/lib/ReaderWriter/MachO/File.h
Modified: lld/trunk/lib/ReaderWriter/MachO/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/Atoms.h?rev=222201&r1=222200&r2=222201&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/Atoms.h Mon Nov 17 18:30:25 2014
@@ -18,16 +18,16 @@ class MachODefinedAtom : public SimpleDe
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) {}
@@ -36,6 +36,8 @@ public:
ContentType contentType() const override { return _contentType; }
+ Alignment alignment() const override { return _align; }
+
StringRef name() const override { return _name; }
Scope scope() const override { return _scope; }
@@ -71,6 +73,7 @@ public:
private:
const StringRef _name;
const ArrayRef<uint8_t> _content;
+ const DefinedAtom::Alignment _align;
const ContentType _contentType;
const Scope _scope;
const Merge _merge;
@@ -84,9 +87,9 @@ public:
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 {
Modified: lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp?rev=222201&r1=222200&r2=222201&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp Mon Nov 17 18:30:25 2014
@@ -100,7 +100,7 @@ public:
_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;
Modified: lld/trunk/lib/ReaderWriter/MachO/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/File.h?rev=222201&r1=222200&r2=222201&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/File.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/File.h Mon Nov 17 18:30:25 2014
@@ -39,9 +39,11 @@ public:
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);
}
@@ -59,11 +61,13 @@ public:
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);
}
@@ -75,8 +79,11 @@ public:
// 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);
}
Added: lld/trunk/test/mach-o/align_text.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/align_text.yaml?rev=222201&view=auto
==============================================================================
--- lld/trunk/test/mach-o/align_text.yaml (added)
+++ lld/trunk/test/mach-o/align_text.yaml Mon Nov 17 18:30:25 2014
@@ -0,0 +1,45 @@
+# 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
More information about the llvm-commits
mailing list