[llvm] 3b2f879 - [ORC] Use dyn_cast to check input type in StaticLibraryDefinitionGenerator.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 6 14:02:17 PST 2023


Author: Lang Hames
Date: 2023-12-06T14:01:55-08:00
New Revision: 3b2f8795093ce64209bd648231ecda85df28748a

URL: https://github.com/llvm/llvm-project/commit/3b2f8795093ce64209bd648231ecda85df28748a
DIFF: https://github.com/llvm/llvm-project/commit/3b2f8795093ce64209bd648231ecda85df28748a.diff

LOG: [ORC] Use dyn_cast to check input type in StaticLibraryDefinitionGenerator.

Replaces an llvm::cast that assumed that all Binary instances were either
Archive or MachOUniversalBinary instances with a dyn_cast. The cast was
triggering an assert in StaticLibraryDefinitionGenerator::Load if that method
was given a path or MemoryBuffer containing a relocatable object file.
Switching to dyn_cast causes the operation to error out with a bad-format
error as expected.

Fixes rdar://119262300

Added: 
    llvm/test/ExecutionEngine/JITLink/Generic/Inputs/main-ret-0.ll
    llvm/test/ExecutionEngine/JITLink/Generic/error-object-passed-as-archive.test

Modified: 
    llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
index eb8e6825fad45..7316b2dce8abb 100644
--- a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
@@ -284,7 +284,7 @@ StaticLibraryDefinitionGenerator::Load(
 
   // If this is a universal binary then search for a slice matching the given
   // Triple.
-  if (auto *UB = cast<object::MachOUniversalBinary>(B->getBinary())) {
+  if (auto *UB = dyn_cast<object::MachOUniversalBinary>(B->getBinary())) {
 
     const auto &TT = L.getExecutionSession().getTargetTriple();
 
@@ -347,7 +347,7 @@ StaticLibraryDefinitionGenerator::Create(
 
   // If this is a universal binary then search for a slice matching the given
   // Triple.
-  if (auto *UB = cast<object::MachOUniversalBinary>(B->get())) {
+  if (auto *UB = dyn_cast<object::MachOUniversalBinary>(B->get())) {
 
     const auto &TT = L.getExecutionSession().getTargetTriple();
 

diff  --git a/llvm/test/ExecutionEngine/JITLink/Generic/Inputs/main-ret-0.ll b/llvm/test/ExecutionEngine/JITLink/Generic/Inputs/main-ret-0.ll
new file mode 100644
index 0000000000000..3d03142d6ca28
--- /dev/null
+++ b/llvm/test/ExecutionEngine/JITLink/Generic/Inputs/main-ret-0.ll
@@ -0,0 +1,4 @@
+define i32 @main(i32 %argc, i8**  %argv)  {
+entry:
+  ret i32 0
+}

diff  --git a/llvm/test/ExecutionEngine/JITLink/Generic/error-object-passed-as-archive.test b/llvm/test/ExecutionEngine/JITLink/Generic/error-object-passed-as-archive.test
new file mode 100644
index 0000000000000..04e67adee7446
--- /dev/null
+++ b/llvm/test/ExecutionEngine/JITLink/Generic/error-object-passed-as-archive.test
@@ -0,0 +1,6 @@
+# RUN: llc -filetype=obj -o %t.o %S/Inputs/main-ret-0.ll
+# RUN: cp %t.o %t.a
+# RUN: not llvm-jitlink -noexec %t.o %t.a
+#
+# Try to load an object file as if it were an archive. Should result in an
+# error, rather than a crash.


        


More information about the llvm-commits mailing list