Skip to content

Commit 915c84b

Browse files
authored
[lldb] Fix evaluation of expressions with static initializers (#89063)
After 281d716, 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.
1 parent 86a7828 commit 915c84b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lldb/source/Expression/IRExecutionUnit.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/IR/DiagnosticInfo.h"
1414
#include "llvm/IR/LLVMContext.h"
1515
#include "llvm/IR/Module.h"
16+
#include "llvm/Support/CodeGen.h"
1617
#include "llvm/Support/SourceMgr.h"
1718
#include "llvm/Support/raw_ostream.h"
1819

@@ -279,10 +280,13 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr,
279280
llvm::EngineBuilder builder(std::move(m_module_up));
280281
llvm::Triple triple(m_module->getTargetTriple());
281282

283+
// PIC needed for ELF to avoid generating 32-bit relocations (which overflow
284+
// if the object is loaded into high memory).
285+
bool want_pic = triple.isOSBinFormatMachO() || triple.isOSBinFormatELF();
286+
282287
builder.setEngineKind(llvm::EngineKind::JIT)
283288
.setErrorStr(&error_string)
284-
.setRelocationModel(triple.isOSBinFormatMachO() ? llvm::Reloc::PIC_
285-
: llvm::Reloc::Static)
289+
.setRelocationModel(want_pic ? llvm::Reloc::PIC_ : llvm::Reloc::Static)
286290
.setMCJITMemoryManager(std::make_unique<MemoryManager>(*this))
287291
.setOptLevel(llvm::CodeGenOptLevel::Less);
288292

0 commit comments

Comments
 (0)