Skip to content

Commit 8e5a8f6

Browse files
committed
[ORC] Don't require a null-terminator on MemoryBuffers for objects in archives.
The MemoryBuffer::getMemBuffer method's RequiresNullTerminator parameter defaults to true, but object files are not null terminated so we need to explicitly pass false here.
1 parent 53e2380 commit 8e5a8f6

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ Error StaticLibraryDefinitionGenerator::tryToGenerate(
349349
MemoryBufferRef ChildBufferRef(ChildBufferInfo.first,
350350
ChildBufferInfo.second);
351351

352-
if (auto Err =
353-
L.add(JD, MemoryBuffer::getMemBuffer(ChildBufferRef), VModuleKey()))
352+
if (auto Err = L.add(JD, MemoryBuffer::getMemBuffer(ChildBufferRef, false),
353+
VModuleKey()))
354354
return Err;
355355
}
356356

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare i32 @foo()
2+
3+
define i32 @bar() {
4+
entry:
5+
%0 = call i32 @foo()
6+
ret i32 %0
7+
}
8+

llvm/test/ExecutionEngine/OrcLazy/basic-object-file-loading.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llc -filetype=obj -o %t %p/Inputs/basic-object-source.ll
1+
; RUN: llc -filetype=obj -o %t %p/Inputs/foo-return-i32-0.ll
22
; RUN: lli -jit-kind=orc-lazy -extra-object %t %s
33
;
44
; Check that we can load an object file and call a function in it.
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
; This first line will generate the .o files for the next run line
2-
; RUN: llc -filetype=obj -o %t.o %p/Inputs/basic-object-source.ll
3-
; RUN: llvm-ar r %t.a %t.o
4-
; RUN: lli -jit-kind=orc-lazy -extra-archive %t.a %s
2+
; RUN: rm -rf %t && mkdir -p %t
3+
; RUN: llc -filetype=obj -o %t/foo.o %p/Inputs/foo-return-i32-0.ll
4+
; RUN: llc -filetype=obj -o %t/bar.o %p/Inputs/bar-return-i32-call-foo.ll
5+
; RUN: llvm-ar r %t/staticlib.a %t/foo.o %t/bar.o
6+
; RUN: lli -jit-kind=orc-lazy -extra-archive %t/staticlib.a %s
57

6-
declare i32 @foo()
8+
declare i32 @bar()
79

810
define i32 @main() {
9-
%r = call i32 @foo( ) ; <i32> [#uses=1]
11+
%r = call i32 @bar() ; <i32> [#uses=1]
1012
ret i32 %r
1113
}

0 commit comments

Comments
 (0)