[llvm] [Exegesis] Do not assume the size and layout of the assembled snippet (PR #79636)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 26 12:23:15 PST 2024


================
@@ -365,11 +365,18 @@ Expected<ExecutableFunction> ExecutableFunction::create(
 
   auto SymbolSizes = object::computeSymbolSizes(*ObjectFileHolder.getBinary());
   // Get the size of the function that we want to call into (with the name of
-  // FunctionID). This should always be the third symbol returned by
-  // calculateSymbolSizes.
-  assert(SymbolSizes.size() == 3);
-  assert(cantFail(std::get<0>(SymbolSizes[2]).getName()) == FunctionID);
-  uintptr_t CodeSize = std::get<1>(SymbolSizes[2]);
+  // FunctionID).
+  auto SymbolIt = llvm::find_if(SymbolSizes, [&](const auto &Pair) {
+    auto SymbolName = Pair.first.getName();
+    if (SymbolName)
+      return *SymbolName == FunctionID;
+    // Suppress the error.
----------------
boomanaiden154 wrote:

Can we add a note here that we should always succeed here if there aren't bugs in other parts of the code, hence the `consumeError` + assert rather than propagating the error back up through the `Expected<>` that this function returns?

https://github.com/llvm/llvm-project/pull/79636


More information about the llvm-commits mailing list