From: Lang Hames Date: Wed, 10 Aug 2016 22:15:09 +0000 (+0000) Subject: [lld][MachO] Fix LC_SEGEMENT[_64] filesize computation in -r mode. X-Git-Tag: llvmorg-4.0.0-rc1~12797 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8c2406b1fc10051d9c8d00cbb84d394b66e7d52c;p=platform%2Fupstream%2Fllvm.git [lld][MachO] Fix LC_SEGEMENT[_64] filesize computation in -r mode. Using vmsize to populate this file works when outputing MachO images, but fails when outputting relocatable objects. This patch fixes the computation to use file offsets, which works for both output types. Fixes llvm-svn: 278297 --- diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp index 89b0f6f..8cca2a2 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp @@ -643,7 +643,9 @@ llvm::Error MachOFileLayout::writeSingleSegmentLoadCommand(uint8_t *&lc) { seg->vmsize = _file.sections.back().address + _file.sections.back().content.size(); seg->fileoff = _endOfLoadCommands; - seg->filesize = seg->vmsize; + seg->filesize = _sectInfo[&_file.sections.back()].fileOffset + + _file.sections.back().content.size() - + _sectInfo[&_file.sections.front()].fileOffset; seg->maxprot = VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE; seg->initprot = VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE; seg->nsects = _file.sections.size(); diff --git a/lld/test/mach-o/lc_segment_filesize.yaml b/lld/test/mach-o/lc_segment_filesize.yaml new file mode 100644 index 0000000..4413c76 --- /dev/null +++ b/lld/test/mach-o/lc_segment_filesize.yaml @@ -0,0 +1,31 @@ +# RUN: lld -flavor darwin -arch x86_64 -r -o %t %s && llvm-objdump -private-headers %t | FileCheck %s + +# CHECK: filesize 19 + +--- !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 ] + alignment: 16 + address: 0x0000000000000000 + content: [ 0x00, 0x00, 0x00 ] + - segment: __TEXT + section: __alt + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS ] + alignment: 16 + address: 0x0000000000000010 + content: [ 0x00, 0x00, 0x00 ] +global-symbols: + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +page-size: 0x00000000 +...