This is an archive of the discontinued LLVM Phabricator instance.

[Orc][JITLink] Add a shared memory based implementation of MemoryMapper
ClosedPublic

Authored by argentite on Jun 24 2022, 11:34 AM.

Details

Summary

This is an implementation of orc::MemoryMapper that maps shared memory
pages in both executor and controller process and writes directly to
them avoiding transferring content over EPC.
All allocations are properly deinitialized automatically on the
executor side at shutdown by the ExecutorSharedMemoryMapperService.

Diff Detail

Event Timeline

argentite created this revision.Jun 24 2022, 11:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2022, 11:34 AM

Windows support and some other fixes

argentite published this revision for review.Jun 26 2022, 7:58 PM
argentite added reviewers: lhames, sgraenitz.
argentite added inline comments.
llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp
26–49

This function is copied from lib/Support/Windows/Memory.inc. We probably should expose it from there instead.

Herald added a project: Restricted Project. · View Herald TranscriptJun 26 2022, 7:58 PM

Thanks for posting your patch! I will continue reviewing, but here is a first detail I found..

llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
229

I had to cast this to uint64_t explicitly in order to fix a SPS encoding error. It appears the issue is that on my system size_t is unsigned long and not unsigned long long.

argentite updated this revision to Diff 441752.Jul 1 2022, 11:23 AM

Added explicit cast from size_t to uint64_t

lhames accepted this revision.Jul 4 2022, 4:30 PM

This looks great. Thanks @argentite!

llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
362

The call to release could fail -- we'll want to figure out the right error plumbing for this in the long run. Could you add a // FIXME for now?

llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp
157

Are there any other guards to prevent ExecutorSharedMemoryMapperService from being instantiated / used on unsupported platforms? If not, I think this should return an llvm::Error for now.

llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp
59–64

Looks like these could be moved into the scope below.

60–61

There's no explicit test that the lambdas are executed, but I think the use of this promise/future pair in the innermost lambda is sufficient -- the test will block unless all lambdas are run. That's probably worth a comment to point out though.

This revision is now accepted and ready to land.Jul 4 2022, 4:30 PM
argentite updated this revision to Diff 442450.Jul 5 2022, 11:58 PM
argentite marked 5 inline comments as done.

Replaced some llvm_unreachable() with llvm::Error

argentite updated this revision to Diff 444243.Jul 13 2022, 6:25 AM

Skip the test on unimplemented operating systems

This revision was landed with ongoing or failed builds.Jul 13 2022, 3:24 PM
This revision was automatically updated to reflect the committed changes.
amyk added a subscriber: amyk.Jul 13 2022, 9:04 PM

Hi there!

I just wanted to give a heads up that it looks like this patch is causing failures on some of the PPC bots that build with shared libraries:
https://lab.llvm.org/buildbot/#/builders/57
https://lab.llvm.org/buildbot/#/builders/121

The error looks like this in https://lab.llvm.org/buildbot/#/builders/121/builds/21343/steps/4/logs/stdio:

[124/1619] Linking CXX shared library lib/libLLVMOrcTargetProcess.so.15git
FAILED: lib/libLLVMOrcTargetProcess.so.15git 
: && /usr/lib64/ccache/c++ -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG  -Wl,-z,defs -Wl,-z,nodelete   -Wl,-rpath-link,/home/buildbots/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/./lib  -Wl,--gc-sections -shared -Wl,-soname,libLLVMOrcTargetProcess.so.15git -o lib/libLLVMOrcTargetProcess.so.15git lib/ExecutionEngine/Orc/TargetProcess/CMakeFiles/LLVMOrcTargetProcess.dir/ExecutorSharedMemoryMapperService.cpp.o lib/ExecutionEngine/Orc/TargetProcess/CMakeFiles/LLVMOrcTargetProcess.dir/JITLoaderGDB.cpp.o lib/ExecutionEngine/Orc/TargetProcess/CMakeFiles/LLVMOrcTargetProcess.dir/OrcRTBootstrap.cpp.o lib/ExecutionEngine/Orc/TargetProcess/CMakeFiles/LLVMOrcTargetProcess.dir/RegisterEHFrames.cpp.o lib/ExecutionEngine/Orc/TargetProcess/CMakeFiles/LLVMOrcTargetProcess.dir/SimpleExecutorDylibManager.cpp.o lib/ExecutionEngine/Orc/TargetProcess/CMakeFiles/LLVMOrcTargetProcess.dir/SimpleExecutorMemoryManager.cpp.o lib/ExecutionEngine/Orc/TargetProcess/CMakeFiles/LLVMOrcTargetProcess.dir/SimpleRemoteEPCServer.cpp.o lib/ExecutionEngine/Orc/TargetProcess/CMakeFiles/LLVMOrcTargetProcess.dir/TargetExecutionUtils.cpp.o  -Wl,-rpath,"\$ORIGIN/../lib"  -lpthread  lib/libLLVMOrcShared.so.15git  lib/libLLVMSupport.so.15git  -Wl,-rpath-link,/home/buildbots/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/lib && :
lib/ExecutionEngine/Orc/TargetProcess/CMakeFiles/LLVMOrcTargetProcess.dir/ExecutorSharedMemoryMapperService.cpp.o: In function `llvm::orc::rt_bootstrap::ExecutorSharedMemoryMapperService::reserve[abi:cxx11](unsigned long)':
ExecutorSharedMemoryMapperService.cpp:(.text._ZN4llvm3orc12rt_bootstrap33ExecutorSharedMemoryMapperService7reserveB5cxx11Em+0x398): undefined reference to `shm_open'
collect2: error: ld returned 1 exit status

Are you able to look into this?

Thanks.

Hi! I am not very familiar with powerpc but it seems like POSIX shared memory APIs should be available.
From this page I suspect shm_ family of functions could be in librt instead of libc.

Hi! I am not very familiar with powerpc but it seems like POSIX shared memory APIs should be available.
From this page I suspect shm_ family of functions could be in librt instead of libc.

I don't think this is specific to PPC, shm_* APIs are in librt right? I can see "Link with -lrt." in the synopsis of https://man7.org/linux/man-pages/man3/shm_open.3.html. So I guess doing something like:

diff --git a/llvm/lib/ExecutionEngine/CMakeLists.txt b/llvm/lib/ExecutionEngine/CMakeLists.txt
index a5607872c706..cdb7b3e622c3 100644
--- a/llvm/lib/ExecutionEngine/CMakeLists.txt
+++ b/llvm/lib/ExecutionEngine/CMakeLists.txt
@@ -24,7 +24,7 @@ add_llvm_component_library(LLVMExecutionEngine
   )
 
 if(BUILD_SHARED_LIBS)
-  target_link_libraries(LLVMExecutionEngine PUBLIC LLVMRuntimeDyld)
+  target_link_libraries(LLVMExecutionEngine PUBLIC LLVMRuntimeDyld rt)
 endif()
 
 add_subdirectory(Interpreter)
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/CMakeLists.txt b/llvm/lib/ExecutionEngine/Orc/TargetProcess/CMakeLists.txt
index 415876abd65f..9a2709a4d6af 100644
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/CMakeLists.txt
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/CMakeLists.txt
@@ -12,7 +12,7 @@ add_llvm_component_library(LLVMOrcTargetProcess
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/ExecutionEngine/Orc
 
   LINK_LIBS
-  ${LLVM_PTHREAD_LIB}
+  ${LLVM_PTHREAD_LIB} rt
 
   LINK_COMPONENTS
   OrcShared

should get the shared-lib build fixed in Linux, but I'm not sure about other platforms.

I've reverted this in 3e9cc543f223 since I'm hitting the same error as @amyk compiling with shared libs on AArch64 Linux. I had to revert a fix (46b1a7c5f9e6) from @mstorsjo for mingw as well so you probably want to pick that up when re-landing.

thakis added a subscriber: thakis.Jul 14 2022, 4:55 AM

Hi! I am not very familiar with powerpc but it seems like POSIX shared memory APIs should be available.
From this page I suspect shm_ family of functions could be in librt instead of libc.

I don't think this is specific to PPC, shm_* APIs are in librt right? I can see "Link with -lrt." in the synopsis of https://man7.org/linux/man-pages/man3/shm_open.3.html. So I guess doing something like:

diff --git a/llvm/lib/ExecutionEngine/CMakeLists.txt b/llvm/lib/ExecutionEngine/CMakeLists.txt
index a5607872c706..cdb7b3e622c3 100644
--- a/llvm/lib/ExecutionEngine/CMakeLists.txt
+++ b/llvm/lib/ExecutionEngine/CMakeLists.txt
@@ -24,7 +24,7 @@ add_llvm_component_library(LLVMExecutionEngine
   )
 
 if(BUILD_SHARED_LIBS)
-  target_link_libraries(LLVMExecutionEngine PUBLIC LLVMRuntimeDyld)
+  target_link_libraries(LLVMExecutionEngine PUBLIC LLVMRuntimeDyld rt)
 endif()
 
 add_subdirectory(Interpreter)
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/CMakeLists.txt b/llvm/lib/ExecutionEngine/Orc/TargetProcess/CMakeLists.txt
index 415876abd65f..9a2709a4d6af 100644
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/CMakeLists.txt
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/CMakeLists.txt
@@ -12,7 +12,7 @@ add_llvm_component_library(LLVMOrcTargetProcess
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/ExecutionEngine/Orc
 
   LINK_LIBS
-  ${LLVM_PTHREAD_LIB}
+  ${LLVM_PTHREAD_LIB} rt
 
   LINK_COMPONENTS
   OrcShared

should get the shared-lib build fixed in Linux, but I'm not sure about other platforms.

This looks right to me, but it shouldn't be done on windows and apple platforms i think. (Not sure about the bsds.)

Maybe look for what we do for HAVE_LIBRT in llvm/cmake/config-ix.cmake and set a var like LLVM_RT_LIB there and use that here (similar to LLVM_PTHREAD_LIB).

argentite reopened this revision.Jul 14 2022, 5:15 AM
This revision is now accepted and ready to land.Jul 14 2022, 5:15 AM
argentite updated this revision to Diff 444608.Jul 14 2022, 5:15 AM

Link with librt if available

I think this should work everywhere.

It seems like some platforms have shm_ functions in libc and librt acts like a placeholder.

Link with librt if available

I think this should work everywhere.

It seems like some platforms have shm_ functions in libc and librt acts like a placeholder.

This compiles for me now, cheers

LGTM otherwise -- thanks for chasing up the fix @argentite.

llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
2 ↗(On Diff #444608)

As @thakis suggested I think this should be LLVM_RT_LIB (for consistency with LLVM_PTHREAD_LIB).

This revision was landed with ongoing or failed builds.Jul 15 2022, 9:45 AM
This revision was automatically updated to reflect the committed changes.

As @thakis suggested I think this should be LLVM_RT_LIB (for consistency with LLVM_PTHREAD_LIB).

Re-committed on @argentite's behalf. I ended up leaving this as-is: it looks like libSupport currently does something similar with a local CMake variable for rt. We can introduce LLVM_RT_LIB in a follow-up patch if we decide it's worth it.

hctim added a subscriber: hctim.Jul 15 2022, 12:43 PM

Looks like this broke the UBSan buildbot:

https://lab.llvm.org/buildbot/#/builders/85/builds/9186

Details on how to reproduce sanitizer buildbots can be found at https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild, but hopefully the error from the bot should be enough to identify the issue.

-- Testing: 67188 tests, 80 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90
FAIL: LLVM-Unit :: ExecutionEngine/Orc/./OrcJITTests/84/128 (61930 of 67188)
******************** TEST 'LLVM-Unit :: ExecutionEngine/Orc/./OrcJITTests/84/128' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/unittests/ExecutionEngine/Orc/./OrcJITTests-LLVM-Unit-4179923-84-128.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=128 GTEST_SHARD_INDEX=84 /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/unittests/ExecutionEngine/Orc/./OrcJITTests
--
Note: This is test shard 85 of 128.
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from SharedMemoryMapperTest
[ RUN      ] SharedMemoryMapperTest.MemReserveInitializeDeinitializeRelease
/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h:61:20: runtime error: null pointer passed as argument 2, which is declared to never be null
/usr/lib/gcc-cross/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include/string.h:44:28: note: nonnull attribute specified here
    #0 0x5567ac3b1159 in llvm::orc::shared::SPSOutputBuffer::write(char const*, unsigned long) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h:61:5
    #1 0x5567ac74da31 in serialize /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h:352:15
    #2 0x5567ac74da31 in serialize<llvm::ArrayRef<char> > /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h:141:12
    #3 0x5567ac74da31 in bool llvm::orc::shared::SPSArgList<unsigned long, llvm::orc::shared::SPSSequence<char>>::serialize<unsigned long, llvm::ArrayRef<char>>(llvm::orc::shared::SPSOutputBuffer&, unsigned long const&, llvm::ArrayRef<char> const&) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h:142:12
    #4 0x5567ac74d9a4 in bool llvm::orc::shared::SPSArgList<llvm::orc::shared::SPSExecutorAddr, unsigned long, llvm::orc::shared::SPSSequence<char>>::serialize<llvm::orc::ExecutorAddr, unsigned long, llvm::ArrayRef<char>>(llvm::orc::shared::SPSOutputBuffer&, llvm::orc::ExecutorAddr const&, unsigned long const&, llvm::ArrayRef<char> const&) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h:142:12
    #5 0x5567ac74d95d in bool llvm::orc::shared::SPSArgList<llvm::orc::shared::SPSMemoryProtectionFlags, llvm::orc::shared::SPSExecutorAddr, unsigned long, llvm::orc::shared::SPSSequence<char>>::serialize<llvm::orc::tpctypes::WireProtectionFlags, llvm::orc::ExecutorAddr, unsigned long, llvm::ArrayRef<char>>(llvm::orc::shared::SPSOutputBuffer&, llvm::orc::tpctypes::WireProtectionFlags const&, llvm::orc::ExecutorAddr const&, unsigned long const&, llvm::ArrayRef<char> const&) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h:142:12
    #6 0x5567ac74d8a8 in serialize<llvm::orc::tpctypes::SegFinalizeRequest> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h:141:12
    #7 0x5567ac74d8a8 in llvm::orc::shared::SPSSerializationTraits<llvm::orc::shared::SPSSequence<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSMemoryProtectionFlags, llvm::orc::shared::SPSExecutorAddr, unsigned long, llvm::orc::shared::SPSSequence<char>>>, std::__1::vector<llvm::orc::tpctypes::SegFinalizeRequest, std::__1::allocator<llvm::orc::tpctypes::SegFinalizeRequest>>, void>::serialize(llvm::orc::shared::SPSOutputBuffer&, std::__1::vector<llvm::orc::tpctypes::SegFinalizeRequest, std::__1::allocator<llvm::orc::tpctypes::SegFinalizeRequest>> const&) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h:385:12
    #8 0x5567ac74d65f in serialize<std::__1::vector<llvm::orc::tpctypes::SegFinalizeRequest, std::__1::allocator<llvm::orc::tpctypes::SegFinalizeRequest> >, std::__1::vector<llvm::orc::shared::AllocActionCallPair, std::__1::allocator<llvm::orc::shared::AllocActionCallPair> > > /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h:141:12
    #9 0x5567ac74d65f in serialize /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h:199:12
    #10 0x5567ac74d65f in serialize<llvm::orc::tpctypes::FinalizeRequest> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h:141:12
    #11 0x5567ac74d65f in bool llvm::orc::shared::SPSArgList<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSSequence<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSMemoryProtectionFlags, llvm::orc::shared::SPSExecutorAddr, unsigned long, llvm::orc::shared::SPSSequence<char>>>, llvm::orc::shared::SPSSequence<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSSequence<char>>, llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSSequence<char>>>>>>::serialize<llvm::orc::ExecutorAddr, llvm::orc::tpctypes::FinalizeRequest>(llvm::orc::shared::SPSOutputBuffer&, llvm::orc::ExecutorAddr const&, llvm::orc::tpctypes::FinalizeRequest const&) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h:142:12
    #12 0x5567ac76cbc4 in bool llvm::orc::shared::SPSArgList<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSSequence<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSMemoryProtectionFlags, llvm::orc::shared::SPSExecutorAddr, unsigned long, llvm::orc::shared::SPSSequence<char>>>, llvm::orc::shared::SPSSequence<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSSequence<char>>, llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSSequence<char>>>>>>::serialize<llvm::orc::ExecutorAddr, llvm::orc::ExecutorAddr, llvm::orc::tpctypes::FinalizeRequest>(llvm::orc::shared::SPSOutputBuffer&, llvm::orc::ExecutorAddr const&, llvm::orc::ExecutorAddr const&, llvm::orc::tpctypes::FinalizeRequest const&) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h:142:12
    #13 0x5567ac76c8cb in llvm::orc::shared::WrapperFunctionResult llvm::orc::shared::detail::serializeViaSPSToWrapperFunctionResult<llvm::orc::shared::SPSArgList<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSSequence<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSMemoryProtectionFlags, llvm::orc::shared::SPSExecutorAddr, unsigned long, llvm::orc::shared::SPSSequence<char>>>, llvm::orc::shared::SPSSequence<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSSequence<char>>, llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSSequence<char>>>>>>, llvm::orc::ExecutorAddr, llvm::orc::ExecutorAddr, llvm::orc::tpctypes::FinalizeRequest>(llvm::orc::ExecutorAddr const&, llvm::orc::ExecutorAddr const&, llvm::orc::tpctypes::FinalizeRequest const&) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h:176:8
    #14 0x5567ac7685c4 in callAsync<(lambda at /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/ExecutorProcessControl.h:317:9), (lambda at /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp:281:7), llvm::orc::ExecutorAddr, llvm::orc::ExecutorAddr, llvm::orc::tpctypes::FinalizeRequest> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h:484:9
    #15 0x5567ac7685c4 in callSPSWrapperAsync<llvm::orc::shared::SPSExpected<llvm::orc::shared::SPSExecutorAddr> (llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSSequence<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSMemoryProtectionFlags, llvm::orc::shared::SPSExecutorAddr, unsigned long, llvm::orc::shared::SPSSequence<char> > >, llvm::orc::shared::SPSSequence<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSSequence<char> >, llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSSequence<char> > > > >), llvm::orc::ExecutorProcessControl::RunAsTask, (lambda at /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp:281:7), llvm::orc::ExecutorAddr, llvm::orc::ExecutorAddr, llvm::orc::tpctypes::FinalizeRequest> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/ExecutorProcessControl.h:316:5
    #16 0x5567ac7685c4 in callSPSWrapperAsync<llvm::orc::shared::SPSExpected<llvm::orc::shared::SPSExecutorAddr> (llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSSequence<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSMemoryProtectionFlags, llvm::orc::shared::SPSExecutorAddr, unsigned long, llvm::orc::shared::SPSSequence<char> > >, llvm::orc::shared::SPSSequence<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSSequence<char> >, llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSSequence<char> > > > >), (lambda at /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp:281:7), llvm::orc::ExecutorAddr, llvm::orc::ExecutorAddr, llvm::orc::tpctypes::FinalizeRequest> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/ExecutorProcessControl.h:331:5
    #17 0x5567ac7685c4 in llvm::orc::SharedMemoryMapper::initialize(llvm::orc::MemoryMapper::AllocInfo&, llvm::unique_function<void (llvm::Expected<llvm::orc::ExecutorAddr>)>) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp:278:7
    #18 0x5567ac3e1c28 in operator() /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp:100:15
    #19 0x5567ac3e1c28 in void llvm::detail::UniqueFunctionBase<void, llvm::Expected<llvm::orc::ExecutorAddrRange>>::CallImpl<SharedMemoryMapperTest_MemReserveInitializeDeinitializeRelease_Test::TestBody()::$_1>(void*, llvm::Expected<llvm::orc::ExecutorAddrRange>&) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:222:12
    #20 0x5567ac76b10a in llvm::orc::SharedMemoryMapper::reserve(unsigned long, llvm::unique_function<void (llvm::Expected<llvm::orc::ExecutorAddrRange>)>)::$_2::operator()(llvm::Error, llvm::Expected<std::__1::pair<llvm::orc::ExecutorAddr, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp:231:9
    #21 0x5567ac76be35 in operator() /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
    #22 0x5567ac76be35 in operator() /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/ExecutorProcessControl.h:92:23
    #23 0x5567ac76be35 in llvm::orc::GenericNamedTaskImpl<llvm::orc::ExecutorProcessControl::IncomingWFRHandler llvm::orc::ExecutorProcessControl::RunAsTask::operator()<void llvm::orc::shared::WrapperFunction<llvm::orc::shared::SPSExpected<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSSequence<char>>> (llvm::orc::shared::SPSExecutorAddr, unsigned long)>::callAsync<void llvm::orc::ExecutorProcessControl::callSPSWrapperAsync<llvm::orc::shared::SPSExpected<llvm::orc::shared::SPSTuple<llvm::orc::shared::SPSExecutorAddr, llvm::orc::shared::SPSSequence<char>>> (llvm::orc::shared::SPSExecutorAddr, unsigned long), llvm::orc::ExecutorProcessControl::RunAsTask, llvm::orc::SharedMemoryMapper::reserve(unsigned long, llvm::unique_function<void (llvm::Expected<llvm::orc::ExecutorAddrRange>)>)::$_2, llvm::orc::ExecutorAddr, unsigned long>(llvm::orc::ExecutorProcessControl::RunAsTask&&, llvm::orc::ExecutorAddr, llvm::orc::SharedMemoryMapper::reserve(unsigned long, llvm::unique_function<void (llvm::Expected<llvm::orc::ExecutorAddrRange>)>)::$_2&&, llvm::orc::ExecutorAddr const&, unsigned long const&)::'lambda'(auto&&, char const*, unsigned long), llvm::orc::SharedMemoryMapper::reserve(unsigned long, llvm::unique_function<void (llvm::Expected<llvm::orc::ExecutorAddrRange>)>)::$_2, llvm::orc::ExecutorAddr, unsigned long>(auto&&, llvm::orc::ExecutorProcessControl::RunAsTask&&, llvm::orc::ExecutorAddr const&, unsigned long const&)::'lambda'(llvm::orc::shared::WrapperFunctionResult)>(auto&&)::'lambda'(llvm::orc::shared::WrapperFunctionResult)::operator()(llvm::orc::shared::WrapperFunctionResult)::'lambda'()>::run() /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/TaskDispatch.h:68:25
    #24 0x5567ac79f190 in operator() /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/ExecutionEngine/Orc/TaskDispatch.cpp:33:8
    #25 0x5567ac79f190 in __invoke<(lambda at /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/ExecutionEngine/Orc/TaskDispatch.cpp:32:15)> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/libcxx_build_ubsan/include/c++/v1/__functional/invoke.h:403:23
    #26 0x5567ac79f190 in __thread_execute<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, (lambda at /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/ExecutionEngine/Orc/TaskDispatch.cpp:32:15)> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/libcxx_build_ubsan/include/c++/v1/thread:284:5
    #27 0x5567ac79f190 in void* std::__1::__thread_proxy[abi:v15000]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, llvm::orc::DynamicThreadPoolTaskDispatcher::dispatch(std::__1::unique_ptr<llvm::orc::Task, std::__1::default_delete<llvm::orc::Task>>)::$_0>>(void*) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/libcxx_build_ubsan/include/c++/v1/thread:295:5
    #28 0x7fc9f385eb42  (/lib/x86_64-linux-gnu/libc.so.6+0x94b42) (BuildId: 89c3cb85f9e55046776471fed05ec441581d1969)
    #29 0x7fc9f38f09ff  (/lib/x86_64-linux-gnu/libc.so.6+0x1269ff) (BuildId: 89c3cb85f9e55046776471fed05ec441581d1969)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h:61:20 in
argentite reopened this revision.Jul 18 2022, 7:36 AM
This revision is now accepted and ready to land.Jul 18 2022, 7:36 AM
argentite updated this revision to Diff 445496.Jul 18 2022, 7:40 AM

Use new SharedMemorySegFinalizeRequest instead of SegFinalizeRequest

The problem seems to be that there is a Content: ArrayRef<char> in SegFinalizeRequest. In SharedMemoryMapper it is set to (nullptr, 0) since we do not use it but the serialization code runs memcpy anyway with source nullptr and length 0. A new type SharedMemorySegFinalizeRequest without this field will make the intent clear as well.

lhames accepted this revision.Jul 19 2022, 1:59 PM

Use new SharedMemorySegFinalizeRequest instead of SegFinalizeRequest

The problem seems to be that there is a Content: ArrayRef<char> in SegFinalizeRequest. In SharedMemoryMapper it is set to (nullptr, 0) since we do not use it but the serialization code runs memcpy anyway with source nullptr and length 0. A new type SharedMemorySegFinalizeRequest without this field will make the intent clear as well.

I fixed serialization of empty ArrayRef<char> in 67220c2ad72, but I like the idea of a custom request type for the SharedMemoryMapper too -- I'll keep that and re-re-land this.

RKSimon added a subscriber: RKSimon.Aug 9 2022, 9:07 AM
RKSimon added inline comments.
llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp
279

@argentite Static analysis is complaining that this second return is dead code - is it or should the return release() be inside the if() ?

argentite added inline comments.
llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp
279

Yup that release should be inside the if body but we also can't hold the mutex while calling release. I reordered them here: https://reviews.llvm.org/D131510 .