[Lldb-commits] [lldb] 915c84b - [lldb] Fix evaluation of expressions with static initializers (#89063)

via lldb-commits lldb-commits at lists.llvm.org
Wed Apr 17 05:33:22 PDT 2024


Author: Pavel Labath
Date: 2024-04-17T14:33:18+02:00
New Revision: 915c84b1480bb3c6d2e44ca83822d2c2304b763a

URL: https://github.com/llvm/llvm-project/commit/915c84b1480bb3c6d2e44ca83822d2c2304b763a
DIFF: https://github.com/llvm/llvm-project/commit/915c84b1480bb3c6d2e44ca83822d2c2304b763a.diff

LOG: [lldb] Fix evaluation of expressions with static initializers (#89063)

After 281d71604f418eb952e967d9dc4b26241b7f96a, llvm generates 32-bit
relocations, which overflow when we load these objects into high memory.
Interestingly, setting the code model to "large" does not help here
(perhaps it is the default?). I'm not completely sure that this is the
right thing to do, but it doesn't seem to cause any ill effects. I'll
follow up with the author of that patch about the expected behavior
here.

Added: 
    

Modified: 
    lldb/source/Expression/IRExecutionUnit.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp
index cb9bee8733e15d..7ad0e5ff22b2f6 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -13,6 +13,7 @@
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/Support/CodeGen.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -279,10 +280,13 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr,
   llvm::EngineBuilder builder(std::move(m_module_up));
   llvm::Triple triple(m_module->getTargetTriple());
 
+  // PIC needed for ELF to avoid generating 32-bit relocations (which overflow
+  // if the object is loaded into high memory).
+  bool want_pic = triple.isOSBinFormatMachO() || triple.isOSBinFormatELF();
+
   builder.setEngineKind(llvm::EngineKind::JIT)
       .setErrorStr(&error_string)
-      .setRelocationModel(triple.isOSBinFormatMachO() ? llvm::Reloc::PIC_
-                                                      : llvm::Reloc::Static)
+      .setRelocationModel(want_pic ? llvm::Reloc::PIC_ : llvm::Reloc::Static)
       .setMCJITMemoryManager(std::make_unique<MemoryManager>(*this))
       .setOptLevel(llvm::CodeGenOptLevel::Less);
 


        


More information about the lldb-commits mailing list