Skip to content

Commit 69a5b5a

Browse files
authored
Merge pull request rust-lang#122 from vext01/rework-globals
Inject a "global pointers array".
2 parents c15739a + 875c10a commit 69a5b5a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

llvm/lib/YkIR/YkIRWriter.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,21 @@ class YkIRWriter {
751751
serialiseGlobal(G);
752752
}
753753

754+
// Now that we've finished serialising globals, add a global (immutable, for
755+
// now) array to the LLVM module containing pointers to all the global
756+
// variables. We will use this to find the addresses of globals at runtime.
757+
// The indices of the array correspond with `GlobalDeclIdx`s in the AOT IR.
758+
vector<llvm::Constant *> GlobalsAsConsts;
759+
for (llvm::GlobalVariable *G : Globals) {
760+
GlobalsAsConsts.push_back(cast<llvm::Constant>(G));
761+
}
762+
ArrayType *GlobalsArrayTy =
763+
ArrayType::get(PointerType::get(M.getContext(), 0), Globals.size());
764+
GlobalVariable *GlobalsArray = new GlobalVariable(
765+
M, GlobalsArrayTy, true, GlobalValue::LinkageTypes::ExternalLinkage,
766+
ConstantArray::get(GlobalsArrayTy, GlobalsAsConsts));
767+
GlobalsArray->setName("__yk_globalvar_ptrs");
768+
754769
// num_types:
755770
OutStreamer.emitSizeT(Types.size());
756771
// types:

0 commit comments

Comments
 (0)