[llvm] ca4a938 - [JITLink][MachO] Detect MachO::S_THREAD_LOCAL_ZEROFILL sections as zero-fill.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 20 16:12:55 PDT 2021
Author: Lang Hames
Date: 2021-07-21T09:10:10+10:00
New Revision: ca4a9386170e656b22773b09f240d26f49a8877c
URL: https://github.com/llvm/llvm-project/commit/ca4a9386170e656b22773b09f240d26f49a8877c
DIFF: https://github.com/llvm/llvm-project/commit/ca4a9386170e656b22773b09f240d26f49a8877c.diff
LOG: [JITLink][MachO] Detect MachO::S_THREAD_LOCAL_ZEROFILL sections as zero-fill.
This will be used in upcoming MachO native TLV support patches to LLVM and
the ORC runtime.
Added:
llvm/test/ExecutionEngine/JITLink/X86/MachO_thread_bss.s
Modified:
llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
index 9ba523232d508..03a8b98dff18c 100644
--- a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
@@ -85,6 +85,17 @@ bool MachOLinkGraphBuilder::isDebugSection(const NormalizedSection &NSec) {
strcmp(NSec.SegName, "__DWARF") == 0);
}
+bool MachOLinkGraphBuilder::isZeroFillSection(const NormalizedSection &NSec) {
+ switch (NSec.Flags & MachO::SECTION_TYPE) {
+ case MachO::S_ZEROFILL:
+ case MachO::S_GB_ZEROFILL:
+ case MachO::S_THREAD_LOCAL_ZEROFILL:
+ return true;
+ default:
+ return false;
+ }
+}
+
unsigned
MachOLinkGraphBuilder::getPointerSize(const object::MachOObjectFile &Obj) {
return Obj.is64Bit() ? 8 : 4;
@@ -154,17 +165,12 @@ Error MachOLinkGraphBuilder::createNormalizedSections() {
});
// Get the section data if any.
- {
- unsigned SectionType = NSec.Flags & MachO::SECTION_TYPE;
- if (SectionType != MachO::S_ZEROFILL &&
- SectionType != MachO::S_GB_ZEROFILL) {
+ if (!isZeroFillSection(NSec)) {
+ if (DataOffset + NSec.Size > Obj.getData().size())
+ return make_error<JITLinkError>(
+ "Section data extends past end of file");
- if (DataOffset + NSec.Size > Obj.getData().size())
- return make_error<JITLinkError>(
- "Section data extends past end of file");
-
- NSec.Data = Obj.getData().data() + DataOffset;
- }
+ NSec.Data = Obj.getData().data() + DataOffset;
}
// Get prot flags.
diff --git a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h
index a6df4458c1114..90b14c44ff8a8 100644
--- a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h
+++ b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h
@@ -159,6 +159,7 @@ class MachOLinkGraphBuilder {
static bool isAltEntry(const NormalizedSymbol &NSym);
static bool isDebugSection(const NormalizedSection &NSec);
+ static bool isZeroFillSection(const NormalizedSection &NSec);
MachO::relocation_info
getRelocationInfo(const object::relocation_iterator RelItr) {
diff --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_thread_bss.s b/llvm/test/ExecutionEngine/JITLink/X86/MachO_thread_bss.s
new file mode 100644
index 0000000000000..c921e648f8a12
--- /dev/null
+++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_thread_bss.s
@@ -0,0 +1,19 @@
+# RUN: llvm-mc -triple=x86_64-apple-macos10.9 -filetype=obj -o %t %s
+# RUN: llvm-jitlink -noexec -check=%s %t
+#
+# Check that __thread_bss sections are handled as zero-fill.
+#
+# jitlink-check: *{4}X = 0
+
+ .section __TEXT,__text,regular,pure_instructions
+ .build_version macos, 10, 15 sdk_version 10, 15
+ .globl _main
+ .p2align 4, 0x90
+_main:
+ retq
+
+ .globl X
+.tbss X, 4, 2
+
+
+.subsections_via_symbols
More information about the llvm-commits
mailing list