[PATCH] D81888: [lld-macho] Make sure ZeroFill sections are at the end of their segments

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 1 19:58:55 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG7996a1ef7020: [lld-macho] Make sure ZeroFill sections are at the end of their segments (authored by int3).

Changed prior to commit:
  https://reviews.llvm.org/D81888?vs=270882&id=274994#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81888/new/

https://reviews.llvm.org/D81888

Files:
  lld/MachO/Writer.cpp
  lld/test/MachO/bss.s


Index: lld/test/MachO/bss.s
===================================================================
--- lld/test/MachO/bss.s
+++ lld/test/MachO/bss.s
@@ -3,9 +3,27 @@
 # RUN: lld -flavor darwinnew -o %t %t.o
 # RUN: llvm-readobj --section-headers --macho-segment %t | FileCheck %s
 
-## Check that __bss takes up zero file size and is at file offset zero.
+## Check that __bss takes up zero file size, is at file offset zero, and
+## appears at the end of its segment.
 
-# CHECK:        Name: __bss
+# CHECK:        Index: 1
+# CHECK-NEXT:   Name: __data
+# CHECK-NEXT:   Segment: __DATA
+# CHECK-NEXT:   Address:
+# CHECK-NEXT:   Size: 0x8
+# CHECK-NEXT:   Offset: 4096
+# CHECK-NEXT:   Alignment: 0
+# CHECK-NEXT:   RelocationOffset: 0x0
+# CHECK-NEXT:   RelocationCount: 0
+# CHECK-NEXT:   Type: Regular (0x0)
+# CHECK-NEXT:   Attributes [ (0x0)
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Reserved1: 0x0
+# CHECK-NEXT:   Reserved2: 0x0
+# CHECK-NEXT:   Reserved3: 0x0
+
+# CHECK:        Index: 2
+# CHECK-NEXT:   Name: __bss
 # CHECK-NEXT:   Segment: __DATA
 # CHECK-NEXT:   Address:
 # CHECK-NEXT:   Size: 0x4
@@ -23,9 +41,9 @@
 # CHECK:      Name: __DATA
 # CHECK-NEXT: Size:
 # CHECK-NEXT: vmaddr:
-# CHECK-NEXT: vmsize: 0x4
+# CHECK-NEXT: vmsize: 0xC
 # CHECK-NEXT: fileoff:
-# CHECK-NEXT: filesize: 0
+# CHECK-NEXT: filesize: 8
 
 .globl _main
 
@@ -36,3 +54,6 @@
 
 .bss
 .zero 4
+
+.data
+.quad 0x1234
Index: lld/MachO/Writer.cpp
===================================================================
--- lld/MachO/Writer.cpp
+++ lld/MachO/Writer.cpp
@@ -358,6 +358,10 @@
         .Case(section_names::stringTable, -1)
         .Default(0);
   }
+  // ZeroFill sections must always be the at the end of their segments,
+  // otherwise subsequent sections may get overwritten with zeroes at runtime.
+  if (isZeroFill(osec->flags))
+    return std::numeric_limits<int>::max();
   return 0;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81888.274994.patch
Type: text/x-patch
Size: 1891 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200702/6e961381/attachment.bin>


More information about the llvm-commits mailing list