[PATCH] D85079: [lld-macho] Ensure .tbss sections are also considered as ZeroFilled

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 1 15:21:59 PDT 2020


int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
int3 requested review of this revision.

This diff makes the behavior in D80859: [lld-macho] Ensure __bss sections we output have file offset of zero <https://reviews.llvm.org/D80859> and D81888: [lld-macho] Make sure ZeroFill sections are at the end of their segments <https://reviews.llvm.org/D81888> apply to
thread-local ZeroFill sections too. I realized this was necessary whie
trying to implement thread-local variables.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85079

Files:
  lld/MachO/InputSection.h
  lld/test/MachO/bss.s


Index: lld/test/MachO/bss.s
===================================================================
--- lld/test/MachO/bss.s
+++ lld/test/MachO/bss.s
@@ -26,7 +26,7 @@
 # CHECK-NEXT:   Name: __bss
 # CHECK-NEXT:   Segment: __DATA
 # CHECK-NEXT:   Address:
-# CHECK-NEXT:   Size: 0x4
+# CHECK-NEXT:   Size: 0x8
 # CHECK-NEXT:   Offset: 0
 # CHECK-NEXT:   Alignment: 0
 # CHECK-NEXT:   RelocationOffset: 0x0
@@ -38,10 +38,26 @@
 # CHECK-NEXT:   Reserved2: 0x0
 # CHECK-NEXT:   Reserved3: 0x0
 
+# CHECK:        Index: 3
+# CHECK-NEXT:   Name: __thread_bss
+# CHECK-NEXT:   Segment: __DATA
+# CHECK-NEXT:   Address: 0x100001010
+# CHECK-NEXT:   Size: 0x4
+# CHECK-NEXT:   Offset: 0
+# CHECK-NEXT:   Alignment: 0
+# CHECK-NEXT:   RelocationOffset: 0x0
+# CHECK-NEXT:   RelocationCount: 0
+# CHECK-NEXT:   Type: ThreadLocalZerofill (0x12)
+# CHECK-NEXT:   Attributes [ (0x0)
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Reserved1: 0x0
+# CHECK-NEXT:   Reserved2: 0x0
+# CHECK-NEXT:   Reserved3: 0x0
+
 # CHECK:      Name: __DATA
 # CHECK-NEXT: Size:
 # CHECK-NEXT: vmaddr:
-# CHECK-NEXT: vmsize: 0xC
+# CHECK-NEXT: vmsize: 0x14
 # CHECK-NEXT: fileoff:
 # CHECK-NEXT: filesize: 8
 
@@ -55,5 +71,8 @@
 .bss
 .zero 4
 
+.tbss _foo, 4
+.zero 4
+
 .data
 .quad 0x1234
Index: lld/MachO/InputSection.h
===================================================================
--- lld/MachO/InputSection.h
+++ lld/MachO/InputSection.h
@@ -36,7 +36,8 @@
 };
 
 inline bool isZeroFill(uint8_t flags) {
-  return (flags & llvm::MachO::SECTION_TYPE) == llvm::MachO::S_ZEROFILL;
+  return llvm::MachO::isVirtualSection(flags & llvm::MachO::SECTION_TYPE);
+}
 }
 
 class InputSection {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85079.282417.patch
Type: text/x-patch
Size: 1648 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200801/de0b0017/attachment.bin>


More information about the llvm-commits mailing list