@@ -98,6 +98,8 @@ static cl::opt<bool> WriteRelBFToSummary(
9898
9999extern FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold;
100100
101+ extern bool YkAllocLLVMBCSection;
102+
101103namespace {
102104
103105// / These are manifest constants used by the bitcode writer. They do not need to
@@ -4992,11 +4994,32 @@ void llvm::embedBitcodeInModule(llvm::Module &M, llvm::MemoryBufferRef Buf,
49924994 ModuleData = ArrayRef<uint8_t >((const uint8_t *)Buf.getBufferStart (),
49934995 Buf.getBufferSize ());
49944996 }
4997+
4998+ GlobalValue::LinkageTypes SymLinkage = GlobalValue::PrivateLinkage;
4999+
5000+ // For the YK JIT we prepend a header containing the size of the bitcode.
5001+ // This is required in order to load bitcode from memory.
5002+ std::vector<uint8_t > YkModuleData;
5003+ if (YkAllocLLVMBCSection) {
5004+ // Write length field.
5005+ size_t ModuleDataSize = ModuleData.size ();
5006+ uint8_t *Bytes = reinterpret_cast <uint8_t *>(&ModuleDataSize);
5007+ for (size_t I = 0 ; I < sizeof (ModuleDataSize); I++)
5008+ YkModuleData.push_back (Bytes[I]);
5009+
5010+ // Append bitcode.
5011+ std::move (ModuleData.begin (), ModuleData.end (),
5012+ std::back_inserter (YkModuleData));
5013+ ModuleData = YkModuleData;
5014+
5015+ // Ensure the symbol is exported in the resulting binary.
5016+ SymLinkage = GlobalValue::ExternalLinkage;
5017+ }
5018+
49955019 llvm::Constant *ModuleConstant =
49965020 llvm::ConstantDataArray::get (M.getContext (), ModuleData);
49975021 llvm::GlobalVariable *GV = new llvm::GlobalVariable (
4998- M, ModuleConstant->getType (), true , llvm::GlobalValue::PrivateLinkage,
4999- ModuleConstant);
5022+ M, ModuleConstant->getType (), true , SymLinkage, ModuleConstant);
50005023 GV->setSection (getSectionNameForBitcode (T));
50015024 // Set alignment to 1 to prevent padding between two contributions from input
50025025 // sections after linking.
0 commit comments