[lld] r212031 - MachO: align segment virtual addresses to page size.
Tim Northover
tnorthover at apple.com
Mon Jun 30 02:49:34 PDT 2014
Author: tnorthover
Date: Mon Jun 30 04:49:33 2014
New Revision: 212031
URL: http://llvm.org/viewvc/llvm-project?rev=212031&view=rev
Log:
MachO: align segment virtual addresses to page size.
Segments must occupy a multiple of the page size in memory (4096 currently). We
check for this when emitting files, but the placement algorithm broke down for
the second non-__TEXT segment encountered: the offset wasn't aligned up to 4096
before starting its layout.
Added:
lld/trunk/test/mach-o/exe-segment-overlap.yaml
Modified:
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=212031&r1=212030&r2=212031&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Mon Jun 30 04:49:33 2014
@@ -278,11 +278,12 @@ SectionInfo *Util::sectionForAtom(const
// Not found, so need to create a new custom section.
size_t seperatorIndex = customName.find('/');
assert(seperatorIndex != StringRef::npos);
- StringRef segName = customName.slice(0, seperatorIndex-1);
- StringRef sectName = customName.drop_front(seperatorIndex);
+ StringRef segName = customName.slice(0, seperatorIndex);
+ StringRef sectName = customName.drop_front(seperatorIndex + 1);
SectionInfo *sect = new (_allocator) SectionInfo(segName, sectName,
S_REGULAR);
_customSections.push_back(sect);
+ _sectionInfos.push_back(sect);
return sect;
}
}
@@ -452,6 +453,8 @@ void Util::assignAddressesToSections() {
layoutSectionsInTextSegment(seg, address);
else
layoutSectionsInSegment(seg, address);
+
+ address = llvm::RoundUpToAlignment(address, _context.pageSize());
}
DEBUG_WITH_TYPE("WriterMachO-norm",
llvm::dbgs() << "assignAddressesToSections()\n";
Added: lld/trunk/test/mach-o/exe-segment-overlap.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/exe-segment-overlap.yaml?rev=212031&view=auto
==============================================================================
--- lld/trunk/test/mach-o/exe-segment-overlap.yaml (added)
+++ lld/trunk/test/mach-o/exe-segment-overlap.yaml Mon Jun 30 04:49:33 2014
@@ -0,0 +1,44 @@
+# RUN: lld -flavor darwin -arch x86_64 %s -o %t
+# RUN: llvm-readobj -sections -section-data %t | FileCheck %s
+
+--- !native
+defined-atoms:
+ - name: start
+ scope: global
+ content: [ 90 ]
+
+ - name: _s2
+ type: data
+ content: [ 31, 32, 33, 34 ]
+
+ - name: _kustom
+ scope: global
+ type: unknown
+ content: [ 01, 02, 03, 04, 05, 06, 07, 08 ]
+ section-choice: custom-required
+ section-name: __CUST/__custom
+
+
+# CHECK-LABEL: Section {
+# CHECK: Name: __text
+# CHECK: Segment: __TEXT
+# CHECK: Size: 0x1
+# CHECK: Offset: 4095
+
+# CHECK-LABEL: Section {
+# CHECK: Name: __data
+# CHECK: Segment: __DATA
+# CHECK: Size: 0x4
+# CHECK: Offset: 4096
+# CHECK: SectionData (
+# CHECK-NEXT: 0000: 31323334
+# CHECK-NEXT: )
+
+# CHECK-LABEL: Section {
+# CHECK: Name: __custom{{ }}
+# CHECK: Segment: __CUST{{ }}
+# CHECK: Size: 0x8
+# CHECK: Offset: 8192
+# CHECK: SectionData (
+# CHECK-NEXT: 0000: 01020304 05060708
+# CHECK-NEXT: )
More information about the llvm-commits
mailing list