Skip to content

Commit

Permalink
[JITLink][MachO] Detect MachO::S_THREAD_LOCAL_ZEROFILL sections as ze…
Browse files Browse the repository at this point in the history
…ro-fill.

This will be used in upcoming MachO native TLV support patches to LLVM and
the ORC runtime.
  • Loading branch information
lhames committed Jul 20, 2021
1 parent a876d09 commit ca4a938
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
26 changes: 16 additions & 10 deletions llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions llvm/test/ExecutionEngine/JITLink/X86/MachO_thread_bss.s
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ca4a938

Please sign in to comment.