[llvm] 8ba9a52 - LTO: always parse modules in opaque pointer mode.

Tim Northover via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 14 06:13:14 PST 2022


Author: Tim Northover
Date: 2022-12-14T14:13:08Z
New Revision: 8ba9a5218782fa4f94b5c516d513a4259992c254

URL: https://github.com/llvm/llvm-project/commit/8ba9a5218782fa4f94b5c516d513a4259992c254
DIFF: https://github.com/llvm/llvm-project/commit/8ba9a5218782fa4f94b5c516d513a4259992c254.diff

LOG: 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.

Added: 
    

Modified: 
    llvm/tools/lto/lto.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp
index f50b6ac5ae3dc..a2d051257ea4c 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<LTOToolDiagnosticHandler>(), 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<MemoryBuffer> NativeObjectFile;
   std::unique_ptr<LLVMContext> 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<LLVMContext> Context = std::make_unique<LLVMContext>();
+  Context->setOpaquePointers(true);
   Context->setDiagnosticHandler(std::make_unique<LTOToolDiagnosticHandler>(),
                                 true);
 


        


More information about the llvm-commits mailing list