[llvm] 66e9078 - [LTO] Fix a use-after-free in legacy LTO C APIs (#107896)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 9 14:12:16 PDT 2024
Author: Steven Wu
Date: 2024-09-09T14:12:12-07:00
New Revision: 66e9078f827383f77c1c239f6c09f2b07a963649
URL: https://github.com/llvm/llvm-project/commit/66e9078f827383f77c1c239f6c09f2b07a963649
DIFF: https://github.com/llvm/llvm-project/commit/66e9078f827383f77c1c239f6c09f2b07a963649.diff
LOG: [LTO] Fix a use-after-free in legacy LTO C APIs (#107896)
Fix a bug that `lto_runtime_lib_symbols_list` is returning the address
of a local variable that will be freed when getting out of scope. This
is a regression from #98512 that rewrites the runtime libcall function
lists into a SmallVector.
rdar://135559037
Added:
Modified:
llvm/tools/lto/lto.cpp
Removed:
################################################################################
diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp
index d68cff839604f6..c8fbbd1e0b24b7 100644
--- a/llvm/tools/lto/lto.cpp
+++ b/llvm/tools/lto/lto.cpp
@@ -13,6 +13,7 @@
#include "llvm-c/lto.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/CodeGen/CommandFlags.h"
@@ -88,6 +89,8 @@ struct LTOToolDiagnosticHandler : public DiagnosticHandler {
}
};
+static SmallVector<const char *> RuntimeLibcallSymbols;
+
// Initialize the configured targets if they have not been initialized.
static void lto_initialize() {
if (!initialized) {
@@ -108,6 +111,7 @@ static void lto_initialize() {
LTOContext = &Context;
LTOContext->setDiagnosticHandler(
std::make_unique<LTOToolDiagnosticHandler>(), true);
+ RuntimeLibcallSymbols = lto::LTO::getRuntimeLibcallSymbols(Triple());
initialized = true;
}
}
@@ -691,7 +695,6 @@ extern const char *lto_input_get_dependent_library(lto_input_t input,
}
extern const char *const *lto_runtime_lib_symbols_list(size_t *size) {
- auto symbols = lto::LTO::getRuntimeLibcallSymbols(Triple());
- *size = symbols.size();
- return symbols.data();
+ *size = RuntimeLibcallSymbols.size();
+ return RuntimeLibcallSymbols.data();
}
More information about the llvm-commits
mailing list