From 1683917d99e0e7c1b922e961b5cd0f20fd55d00f Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Thu, 26 Sep 2019 17:03:20 +0000 Subject: [lld][mach-o] Avoid segfaulting when handling an empty section list. Summary: The following patch avoids segfaulting if the section list is empty when writing a mach-o MH_OBJECT. I ran into this case from a more complicated example trying to dead_strip while using '-r' in lld. I'm not sure if having empty sections is a legal mach-o, but it does seem that other llvm-binutils tools can ingest such a boring object with out issue. Would it be better to emit an error, emit a warning, or do nothing? It seems that adding a warning diagnostic might be helpful to users, as I did not expect to have a section-less object when the linker was done. Reviewers: kledzik, ruiu Subscribers: llvm-commits, jrm Tags: #lld, #llvm Differential Revision: https://reviews.llvm.org/D67735 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@372995 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/mach-o/empty-sections.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/mach-o/empty-sections.yaml (limited to 'test') diff --git a/test/mach-o/empty-sections.yaml b/test/mach-o/empty-sections.yaml new file mode 100644 index 000000000..ca6b150b1 --- /dev/null +++ b/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 +... -- cgit v1.2.3