From 2ec1aba2b69faa1de5f71832a48e25aa3b5d5314 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Fri, 17 Feb 2023 20:16:16 -0800 Subject: [PATCH] [llvm-jitlink] Discard allocation actions in -noexec mode. Allocation actions may run JIT'd code, which isn't permitted in -noexec mode. Testcases that depend on actions running should be moved to the ORC runtime. --- .../x86-64/MachO_gdb_jit_debuginfo_register.S | 28 ++++++++++++++++++++++ .../JITLink/X86/MachO_gdb_jit_debuginfo_register.s | 28 ---------------------- llvm/tools/llvm-jitlink/llvm-jitlink.cpp | 6 +++-- 3 files changed, 32 insertions(+), 30 deletions(-) create mode 100644 compiler-rt/test/orc/TestCases/Darwin/x86-64/MachO_gdb_jit_debuginfo_register.S delete mode 100644 llvm/test/ExecutionEngine/JITLink/X86/MachO_gdb_jit_debuginfo_register.s diff --git a/compiler-rt/test/orc/TestCases/Darwin/x86-64/MachO_gdb_jit_debuginfo_register.S b/compiler-rt/test/orc/TestCases/Darwin/x86-64/MachO_gdb_jit_debuginfo_register.S new file mode 100644 index 0000000..acb032f --- /dev/null +++ b/compiler-rt/test/orc/TestCases/Darwin/x86-64/MachO_gdb_jit_debuginfo_register.S @@ -0,0 +1,28 @@ +// REQUIRES: system-darwin && asserts +// RUN: %clang -c -o %t %s +// RUN: %llvm_jitlink -debug-only=orc -debugger-support %t 2>&1 \ +// RUN: | FileCheck %s +// +// Check that presence of a "__DWARF" section triggers the +// GDBJITDebugInfoRegistrationPlugin. +// +// This test requires a darwin host (despite being a noexec test) because we use +// the input object's mangling to determine the mangling of the registration +// function to use. Since the input is MachO, the mangling will only line up +// properly on Darwin. (See https://llvm.org/PR52503 for a proposed longer term +// solution). +// +// CHECK: Registering debug object with GDB JIT interface + + .section __TEXT,__text,regular,pure_instructions + .globl _main + .p2align 4, 0x90 +_main: + xorl %eax, %eax + retq + + .section __DWARF,__debug_str,regular,debug +Linfo_string: + .asciz "test dwarf string" + +.subsections_via_symbols diff --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_gdb_jit_debuginfo_register.s b/llvm/test/ExecutionEngine/JITLink/X86/MachO_gdb_jit_debuginfo_register.s deleted file mode 100644 index 1d0c813..0000000 --- a/llvm/test/ExecutionEngine/JITLink/X86/MachO_gdb_jit_debuginfo_register.s +++ /dev/null @@ -1,28 +0,0 @@ -# REQUIRES: system-darwin && asserts -# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t %s -# RUN: llvm-jitlink -debug-only=orc -debugger-support -noexec %t 2>&1 \ -# RUN: | FileCheck %s -# -# Check that presence of a "__DWARF" section triggers the -# GDBJITDebugInfoRegistrationPlugin. -# -# This test requires a darwin host (despite being a noexec test) because we use -# the input object's mangling to determine the mangling of the registration -# function to use. Since the input is MachO, the mangling will only line up -# properly on Darwin. (See https://llvm.org/PR52503 for a proposed longer term -# solution). -# -# CHECK: Registering debug object with GDB JIT interface - - .section __TEXT,__text,regular,pure_instructions - .globl _main - .p2align 4, 0x90 -_main: - xorl %eax, %eax - retq - - .section __DWARF,__debug_str,regular,debug -Linfo_string: - .asciz "test dwarf string" - -.subsections_via_symbols diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp index 4180be4..d98cd77 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -506,12 +506,14 @@ public: } void initialize(AllocInfo &AI, OnInitializedFunction OnInitialized) override { - // Slide mapping based on delta and make all segments read-writable. - auto FixedAI = AI; + // Slide mapping based on delta, make all segments read-writable, and + // discard allocation actions. + auto FixedAI = std::move(AI); FixedAI.MappingBase -= DeltaAddr; for (auto &Seg : FixedAI.Segments) Seg.AG = AllocGroup(MemProt::Read | MemProt::Write, Seg.AG.getMemDeallocPolicy()); + FixedAI.Actions.clear(); InProcessMemoryMapper::initialize( FixedAI, [this, OnInitialized = std::move(OnInitialized)]( Expected Result) mutable { -- 2.7.4