summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
diff options
context:
space:
mode:
authorNick Kledzik <kledzik@apple.com>2014-09-09 23:52:59 +0000
committerNick Kledzik <kledzik@apple.com>2014-09-09 23:52:59 +0000
commit1bebb2832ee312d3b0316dacff457a7a29435edb (patch)
tree8e60f41a6649fd60850d101306b98b039857f97f /lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
parentd0f103775a66232fae4a54fc29fdc031f3436d38 (diff)
downloadbcm5719-llvm-1bebb2832ee312d3b0316dacff457a7a29435edb.tar.gz
bcm5719-llvm-1bebb2832ee312d3b0316dacff457a7a29435edb.zip
[mach-o] Add support for arm64 (AAarch64)
Most of the changes are in the new file ArchHandler_arm64.cpp. But a few things had to be fixed to support 16KB pages (instead of 4KB) which iOS arm64 requires. In addition the StubInfo struct had to be expanded because arm64 uses two instruction (ADRP/LDR) to load a global which requires two relocations. The other mach-o arches just needed one relocation. llvm-svn: 217469
Diffstat (limited to 'lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp')
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
index 3f1ed9ac2bf..e41d9189640 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
@@ -470,16 +470,21 @@ void MachOFileLayout::buildFileOffsets() {
// Assign sections to segments.
for (const Section &s : _file.sections) {
_sectInfo[&s] = t2;
+ bool foundSegment = false;
for (const Segment &sg : _file.segments) {
- if ((s.address >= sg.address)
+ if (sg.name.equals(s.segmentName)) {
+ if ((s.address >= sg.address)
&& (s.address+s.content.size() <= sg.address+sg.size)) {
- if (!sg.name.equals(s.segmentName)) {
- _ec = make_error_code(llvm::errc::executable_format_error);
- return;
+ _segInfo[&sg].sections.push_back(&s);
+ foundSegment = true;
+ break;
}
- _segInfo[&sg].sections.push_back(&s);
}
}
+ if (!foundSegment) {
+ _ec = make_error_code(llvm::errc::executable_format_error);
+ return;
+ }
}
// Assign file offsets.
@@ -507,9 +512,10 @@ void MachOFileLayout::buildFileOffsets() {
<< ", fileOffset=" << fileOffset << "\n");
}
- // FIXME: 4096 should be inferred from segments in normalized file.
- _segInfo[&sg].fileSize = llvm::RoundUpToAlignment(segFileSize, 4096);
- fileOffset = llvm::RoundUpToAlignment(fileOffset + segFileSize, 4096);
+ _segInfo[&sg].fileSize = llvm::RoundUpToAlignment(segFileSize,
+ _file.pageSize);
+ fileOffset = llvm::RoundUpToAlignment(fileOffset + segFileSize,
+ _file.pageSize);
_addressOfLinkEdit = sg.address + sg.size;
}
_startOfLinkEdit = fileOffset;
@@ -638,15 +644,16 @@ std::error_code MachOFileLayout::writeSegmentLoadCommands(uint8_t *&lc) {
lc = reinterpret_cast<uint8_t*>(next);
}
// Add implicit __LINKEDIT segment
+ size_t linkeditSize = _endOfLinkEdit - _startOfLinkEdit;
typename T::command* cmd = reinterpret_cast<typename T::command*>(lc);
cmd->cmd = T::LC;
cmd->cmdsize = sizeof(typename T::command);
uint8_t *next = lc + cmd->cmdsize;
setString16("__LINKEDIT", cmd->segname);
cmd->vmaddr = _addressOfLinkEdit;
- cmd->vmsize = _endOfLinkEdit - _startOfLinkEdit;
+ cmd->vmsize = llvm::RoundUpToAlignment(linkeditSize, _file.pageSize);
cmd->fileoff = _startOfLinkEdit;
- cmd->filesize = _endOfLinkEdit - _startOfLinkEdit;
+ cmd->filesize = linkeditSize;
cmd->maxprot = VM_PROT_READ;
cmd->initprot = VM_PROT_READ;
cmd->nsects = 0;
@@ -823,6 +830,8 @@ void MachOFileLayout::writeSectionContent() {
// Copy all section content to output buffer.
if (s.type == llvm::MachO::S_ZEROFILL)
continue;
+ if (s.content.empty())
+ continue;
uint32_t offset = _sectInfo[&s].fileOffset;
uint8_t *p = &_buffer[offset];
memcpy(p, &s.content[0], s.content.size());
@@ -1262,7 +1271,6 @@ std::error_code MachOFileLayout::writeBinary(StringRef path) {
}
-
/// Takes in-memory normalized view and writes a mach-o object file.
std::error_code writeBinary(const NormalizedFile &file, StringRef path) {
MachOFileLayout layout(file);
OpenPOWER on IntegriCloud