[ORC] Android: libLLVMOrcJIT build breakage due to use of deprecated shm_open/shm_unlink
SElinux explicitly disallows the use of shm_open/shm_unlink, all AOSP versions in development are impacted
https://android.googlesource.com/platform/bionic/+/refs/heads/master/docs/status.md
Android build is not the only reason to fix this problem, because using shm_open/shm_unlink is obviously a security risk.
Please fix the issue by mean of SElinux compatble implementation.
If someone provides me with a patch, I am available to perform build tests with Android.bp build rules ported from https://android.googlesource.com/platform/external/llvm (llvm 3.9) to currrent release/15.x branch
and I will report on the test results.
FAILED: out/soong/.intermediates/external/llvm-project/llvm/lib/ExecutionEngine/Orc/libLLVMOrcJIT/android_x86_64_static/obj/ext
ernal/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.o
...
external/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp:213:32: error: use of undeclared identifier 'shm_open'
int SharedMemoryFile = shm_open(SharedMemoryName.c_str(), O_RDWR, 0700);
^
external/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp:220:9: error: use of undeclared identifier 'shm_unlink'
shm_unlink(SharedMemoryName.c_str());
^
2 errors generated.
Could you please add this issue to LLVM 15.0.0 Release Milestone ?
@llvm/issue-subscribers-orcjit
@argentite — can you take a look? For now I think you can just disable the shared mapper (e.g. have Create return an error and conditionally compile out the rest of the implementation) on unsupported platforms.
@maurossi I have temporarily disabled the use of shared memory on Android until we have a better solution on this patch. Can you check if it builds properly?
Hi @argentite I have tested the patch D130814
There are still two building errors due to commit 1b1f1c77
Build error n.1
In file included from external/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp:9:
In file included from external/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/MemoryMapper.h:16:
In file included from external/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Core.h:17:
In file included from external/llvm-project/llvm/include/llvm/ADT/DenseSet.h:17:
In file included from external/llvm-project/llvm/include/llvm/ADT/DenseMap.h:25:
In file included from external/libcxx/include/algorithm:644:
external/libcxx/include/memory:3132:32: error: no matching constructor for initialization of 'llvm::StringError'
return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/llvm-project/llvm/include/llvm/Support/Error.h:334:21: note: in instantiation of function template specialization 'std::__1
::make_unique<llvm::StringError, char const (&)[57]>' requested here
return Error(std::make_unique<ErrT>(std::forward<ArgTs>(Args)...));
^
external/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp:191:10: note: in instantiation of function template specializati
on 'llvm::make_error<llvm::StringError, char const (&)[57]>' requested here
return make_error<StringError>(
^
external/llvm-project/llvm/include/llvm/Support/Error.h:1216:7: note: candidate constructor (the implicit copy constructor) not viab
le: no known conversion from 'char const[57]' to 'const llvm::StringError' for 1st argument
class StringError : public ErrorInfo<StringError> {
^
external/llvm-project/llvm/include/llvm/Support/Error.h:1216:7: note: candidate constructor (the implicit move constructor) not viab
le: no known conversion from 'char const[57]' to 'llvm::StringError' for 1st argument
external/llvm-project/llvm/include/llvm/Support/Error.h:1221:3: note: candidate constructor not viable: no known conversion from 'ch
ar const[57]' to 'std::error_code' for 1st argument
StringError(std::error_code EC, const Twine &S = Twine());
^
external/llvm-project/llvm/include/llvm/Support/Error.h:1224:3: note: candidate constructor not viable: requires 2 arguments, but 1
was provided
StringError(const Twine &S, std::error_code EC);
^
1 error generated.
This error can be avoided by defining the second argument inconvertibleErrorCode() in make_error invokation,
as it is done in the other two invokations of make_error
https://github.com/llvm/llvm-project/blob/main/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp#L262 https://github.com/llvm/llvm-project/blob/main/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp#L380
index fe3fd3ab660f..fdfdffca0124 100644
--- a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
@@ -189,7 +189,8 @@ SharedMemoryMapper::Create(ExecutorProcessControl &EPC, SymbolAddrs SAs) {
return std::make_unique<SharedMemoryMapper>(EPC, SAs, *PageSize);
#else
return make_error<StringError>(
- "SharedMemoryMapper is not supported on this platform yet");
+ "SharedMemoryMapper is not supported on this platform yet",
+ inconvertibleErrorCode());
#endif
}
Build error n.2
In file included from external/llvm-project/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp:9:
external/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.h:69:20: error: private
field 'SharedMemoryCount' is not used [-Werror,-Wunused-private-field]
std::atomic<int> SharedMemoryCount{0};
^
1 error generated.
In order to fix the build error, the declaration SharedMemoryCount in ExecutorSharedMemoryMapperService.h needs to become conditional:
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.h
index 37fe5a98b093..86f1d5debbc5 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.h
@@ -66,7 +66,9 @@ private:
static llvm::orc::shared::CWrapperFunctionResult
releaseWrapper(const char *ArgData, size_t ArgSize);
+#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
std::atomic<int> SharedMemoryCount{0};
+#endif
std::mutex Mutex;
ReservationMap Reservations;
AllocationMap Allocations;
@maurossi Thanks for your report and your help with the errors. @argentite Thanks for bringing the basic fix up so quickly!
I added myself as reviewer on Pharicator, because I am not sure about Lang's current availability. Let's get the fix right and land it in mainline soon. Once it's done we should think about getting it cherry-picked to the release/15.x branch as well.
I will check in again tomorrow morning (CEST)
I have updated the patch. Hopefully it should build now. In the long term we should probably consider supporting ashmem.
@maurossi Can you confirm that @argentite's commit fixed your builds?
Hi Stefan,
commit ac3cb4e fixes the builing error mentioned in this issue https://github.com/llvm/llvm-project/issues/56812
and can be cherry-picked to the release/15.x branch
Thank you
/cherry-pick ac3cb4ecd0c6ed03c135945d27bbe197d80cba4e
/branch llvm/llvm-project-release-prs/issue56812
/pull-request llvm/llvm-project-release-prs#56