[lld-macho] Ensure .tbss sections are also considered as ZeroFilled
authorJez Ng <jezng@fb.com>
Fri, 7 Aug 2020 18:04:41 +0000 (11:04 -0700)
committerJez Ng <jezng@fb.com>
Fri, 7 Aug 2020 18:04:41 +0000 (11:04 -0700)
This diff makes the behavior in {D80859} and {D81888} apply to
thread-local ZeroFill sections too. I realized this was necessary whie
trying to implement thread-local variables.

Reviewed By: #lld-macho, compnerd, MaskRay

Differential Revision: https://reviews.llvm.org/D85079

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

index 96ae0cb..ab2ac63 100644 (file)
@@ -36,7 +36,8 @@ struct Reloc {
 };
 
 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 {
index b56f02d..e41a7e2 100644 (file)
@@ -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
 # 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 @@ _main:
 .bss
 .zero 4
 
+.tbss _foo, 4
+.zero 4
+
 .data
 .quad 0x1234