[PATCH] D67735: [lld][mach-o] Avoid segfaulting when handling an empty section list.
Matt Davis via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 26 10:01:33 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL372995: [lld][mach-o] Avoid segfaulting when handling an empty section list. (authored by mattd, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D67735?vs=220752&id=221974#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D67735/new/
https://reviews.llvm.org/D67735
Files:
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
lld/trunk/test/mach-o/empty-sections.yaml
Index: lld/trunk/test/mach-o/empty-sections.yaml
===================================================================
--- lld/trunk/test/mach-o/empty-sections.yaml
+++ lld/trunk/test/mach-o/empty-sections.yaml
@@ -0,0 +1,9 @@
+# RUN: ld64.lld -arch x86_64 -r %s -o %t
+#
+# Test that writing empty mach-o sections does not segfault the linker.
+#
+
+--- !mach-o
+arch: x86_64
+file-type: MH_OBJECT
+...
Index: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
===================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
@@ -626,17 +626,19 @@
+ _file.sections.size() * sizeof(typename T::section);
uint8_t *next = lc + seg->cmdsize;
memset(seg->segname, 0, 16);
+ seg->flags = 0;
seg->vmaddr = 0;
- seg->vmsize = _file.sections.back().address
- + _file.sections.back().content.size();
seg->fileoff = _endOfLoadCommands;
- 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();
- seg->flags = 0;
+ if (seg->nsects) {
+ seg->vmsize = _file.sections.back().address
+ + _file.sections.back().content.size();
+ seg->filesize = _sectInfo[&_file.sections.back()].fileOffset +
+ _file.sections.back().content.size() -
+ _sectInfo[&_file.sections.front()].fileOffset;
+ }
if (_swap)
swapStruct(*seg);
typename T::section *sout = reinterpret_cast<typename T::section*>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67735.221974.patch
Type: text/x-patch
Size: 1872 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190926/71a1801b/attachment.bin>
More information about the llvm-commits
mailing list