Skip to content

Commit 22d7a01

Browse files
committed
[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.
1 parent bf783a6 commit 22d7a01

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ class Symbol {
352352
JITTargetAddress Size, bool IsCallable,
353353
bool IsLive) {
354354
assert(SymStorage && "Storage cannot be null");
355-
assert(Offset < Base.getSize() && "Symbol offset is outside block");
355+
assert((Offset + Size) <= Base.getSize() &&
356+
"Symbol extends past end of block");
356357
auto *Sym = reinterpret_cast<Symbol *>(SymStorage);
357358
new (Sym) Symbol(Base, Offset, StringRef(), Size, Linkage::Strong,
358359
Scope::Local, IsLive, IsCallable);
@@ -364,7 +365,8 @@ class Symbol {
364365
JITTargetAddress Size, Linkage L, Scope S,
365366
bool IsLive, bool IsCallable) {
366367
assert(SymStorage && "Storage cannot be null");
367-
assert(Offset < Base.getSize() && "Symbol offset is outside block");
368+
assert((Offset + Size) <= Base.getSize() &&
369+
"Symbol extends past end of block");
368370
assert(!Name.empty() && "Name cannot be empty");
369371
auto *Sym = reinterpret_cast<Symbol *>(SymStorage);
370372
new (Sym) Symbol(Base, Offset, Name, Size, L, S, IsLive, IsCallable);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t.o %s
2+
# RUN: llvm-jitlink -noexec -entry hook %t.o
3+
#
4+
# Make sure that an empty __text section doesn't cause any problems.
5+
6+
.section __TEXT,__text,regular,pure_instructions
7+
.macosx_version_min 10, 15
8+
l_empty:
9+
10+
.section __TEXT,__const
11+
.globl hook
12+
.p2align 2
13+
hook:
14+
.long 42
15+
16+
.subsections_via_symbols

0 commit comments

Comments
 (0)