From 8ba9a5218782fa4f94b5c516d513a4259992c254 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Tue, 13 Dec 2022 09:10:56 +0000 Subject: [PATCH] LTO: always parse modules in opaque pointer mode. Once an LLVMContext has been told it needs to track pointer types, it can no longer be used to parse opaque modules. However, we are likely (at least for a while) to have old LTO .o files in the SDK that need to interoperate with just-generated ones, so deciding opaqueness based on the first module read causes linker failures. This makes the llvm-c LTO interface parse any object it sees in opaque mode, even if type data is present, which guarantees compatibility. --- llvm/tools/lto/lto.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp index f50b6ac..a2d0512 100644 --- a/llvm/tools/lto/lto.cpp +++ b/llvm/tools/lto/lto.cpp @@ -106,6 +106,7 @@ static void lto_initialize() { static LLVMContext Context; LTOContext = &Context; + LTOContext->setOpaquePointers(true); LTOContext->setDiagnosticHandler( std::make_unique(), true); initialized = true; @@ -133,7 +134,10 @@ struct LibLTOCodeGenerator : LTOCodeGenerator { // Module must be destructed before its context gets destructed. ~LibLTOCodeGenerator() { resetMergedModule(); } - void init() { setDiagnosticHandler(handleLibLTODiagnostic, nullptr); } + void init() { + OwnedContext->setOpaquePointers(true); + setDiagnosticHandler(handleLibLTODiagnostic, nullptr); + } std::unique_ptr NativeObjectFile; std::unique_ptr OwnedContext; @@ -271,6 +275,7 @@ lto_module_t lto_module_create_in_local_context(const void *mem, size_t length, // Create a local context. Ownership will be transferred to LTOModule. std::unique_ptr Context = std::make_unique(); + Context->setOpaquePointers(true); Context->setDiagnosticHandler(std::make_unique(), true); -- 2.7.4