@@ -1166,6 +1166,8 @@ static void materializePreserved(Module &M, Partition &partition) {
11661166 GV.setInitializer (nullptr );
11671167 GV.setLinkage (GlobalValue::ExternalLinkage);
11681168 GV.setVisibility (GlobalValue::HiddenVisibility);
1169+ if (GV.getDLLStorageClass () != GlobalValue::DLLStorageClassTypes::DefaultStorageClass)
1170+ continue ; // Don't mess with exported or imported globals
11691171 GV.setDSOLocal (true );
11701172 }
11711173
@@ -1645,6 +1647,7 @@ void jl_dump_native_impl(void *native_code,
16451647 if (jl_small_typeof_copy) {
16461648 jl_small_typeof_copy->setVisibility (GlobalValue::HiddenVisibility);
16471649 jl_small_typeof_copy->setDSOLocal (true );
1650+ jl_small_typeof_copy->setDLLStorageClass (GlobalValue::DLLStorageClassTypes::DefaultStorageClass);
16481651 }
16491652 }
16501653
@@ -1673,16 +1676,17 @@ void jl_dump_native_impl(void *native_code,
16731676 // reflect the address of the jl_RTLD_DEFAULT_handle variable
16741677 // back to the caller, so that we can check for consistency issues
16751678 GlobalValue *jlRTLD_DEFAULT_var = jl_emit_RTLD_DEFAULT_var (&metadataM);
1676- addComdat (new GlobalVariable (metadataM,
1677- jlRTLD_DEFAULT_var->getType (),
1678- true ,
1679- GlobalVariable::ExternalLinkage,
1680- jlRTLD_DEFAULT_var,
1681- " jl_RTLD_DEFAULT_handle_pointer" ), TheTriple);
1682-
16831679 Type *T_size = DL.getIntPtrType (Context);
16841680 Type *T_psize = T_size->getPointerTo ();
16851681
1682+ auto FT = FunctionType::get (Type::getInt8Ty (Context)->getPointerTo ()->getPointerTo (), {}, false );
1683+ auto F = Function::Create (FT, Function::ExternalLinkage, " get_jl_RTLD_DEFAULT_handle_addr" , metadataM);
1684+ llvm::IRBuilder<> builder (BasicBlock::Create (Context, " top" , F));
1685+ builder.CreateRet (jlRTLD_DEFAULT_var);
1686+ F->setLinkage (GlobalValue::ExternalLinkage);
1687+ if (TheTriple.isOSBinFormatCOFF ())
1688+ F->setDLLStorageClass (GlobalValue::DLLStorageClassTypes::DLLExportStorageClass);
1689+
16861690 if (TheTriple.isOSWindows ()) {
16871691 // Windows expect that the function `_DllMainStartup` is present in an dll.
16881692 // Normal compilers use something like Zig's crtdll.c instead we provide a
0 commit comments