From 22d7a01dd7282ee5e70ce57a8c1465fd335ea27d Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Fri, 19 Jun 2020 10:01:12 -0700 Subject: [PATCH] [JITLink] Allow zero-length symbols at the end of blocks. This relaxes an assertion that required symbols to start before the end of a block. Instead, symbols are now required to end on or before the end of a block. This fixes two important corner cases: Symbols at the start of empty blocks/sections, and block/section end symbols. --- llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h | 6 ++++-- .../ExecutionEngine/JITLink/X86/MachO_empty_section.s | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 llvm/test/ExecutionEngine/JITLink/X86/MachO_empty_section.s diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h index 000dd18fb37..76f9dea4160 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h @@ -352,7 +352,8 @@ private: JITTargetAddress Size, bool IsCallable, bool IsLive) { assert(SymStorage && "Storage cannot be null"); - assert(Offset < Base.getSize() && "Symbol offset is outside block"); + assert((Offset + Size) <= Base.getSize() && + "Symbol extends past end of block"); auto *Sym = reinterpret_cast(SymStorage); new (Sym) Symbol(Base, Offset, StringRef(), Size, Linkage::Strong, Scope::Local, IsLive, IsCallable); @@ -364,7 +365,8 @@ private: JITTargetAddress Size, Linkage L, Scope S, bool IsLive, bool IsCallable) { assert(SymStorage && "Storage cannot be null"); - assert(Offset < Base.getSize() && "Symbol offset is outside block"); + assert((Offset + Size) <= Base.getSize() && + "Symbol extends past end of block"); assert(!Name.empty() && "Name cannot be empty"); auto *Sym = reinterpret_cast(SymStorage); new (Sym) Symbol(Base, Offset, Name, Size, L, S, IsLive, IsCallable); diff --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_empty_section.s b/llvm/test/ExecutionEngine/JITLink/X86/MachO_empty_section.s new file mode 100644 index 00000000000..f0787ea5f51 --- /dev/null +++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_empty_section.s @@ -0,0 +1,16 @@ +# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t.o %s +# RUN: llvm-jitlink -noexec -entry hook %t.o +# +# Make sure that an empty __text section doesn't cause any problems. + + .section __TEXT,__text,regular,pure_instructions + .macosx_version_min 10, 15 +l_empty: + + .section __TEXT,__const + .globl hook + .p2align 2 +hook: + .long 42 + +.subsections_via_symbols -- 2.11.0