Skip to content

Commit

Permalink
Merge pull request #122 from vext01/rework-globals
Browse files Browse the repository at this point in the history
Inject a "global pointers array".
  • Loading branch information
ltratt authored Mar 21, 2024
2 parents c15739a + 875c10a commit 69a5b5a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions llvm/lib/YkIR/YkIRWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,21 @@ class YkIRWriter {
serialiseGlobal(G);
}

// Now that we've finished serialising globals, add a global (immutable, for
// now) array to the LLVM module containing pointers to all the global
// variables. We will use this to find the addresses of globals at runtime.
// The indices of the array correspond with `GlobalDeclIdx`s in the AOT IR.
vector<llvm::Constant *> GlobalsAsConsts;
for (llvm::GlobalVariable *G : Globals) {
GlobalsAsConsts.push_back(cast<llvm::Constant>(G));
}
ArrayType *GlobalsArrayTy =
ArrayType::get(PointerType::get(M.getContext(), 0), Globals.size());
GlobalVariable *GlobalsArray = new GlobalVariable(
M, GlobalsArrayTy, true, GlobalValue::LinkageTypes::ExternalLinkage,
ConstantArray::get(GlobalsArrayTy, GlobalsAsConsts));
GlobalsArray->setName("__yk_globalvar_ptrs");

// num_types:
OutStreamer.emitSizeT(Types.size());
// types:
Expand Down

0 comments on commit 69a5b5a

Please sign in to comment.