@@ -1242,6 +1242,8 @@ static void materializePreserved(Module &M, Partition &partition) {
12421242 GV.setInitializer (nullptr );
12431243 GV.setLinkage (GlobalValue::ExternalLinkage);
12441244 GV.setVisibility (GlobalValue::HiddenVisibility);
1245+ if (GV.getDLLStorageClass () != GlobalValue::DLLStorageClassTypes::DefaultStorageClass)
1246+ continue ; // Don't mess with exported or imported globals
12451247 GV.setDSOLocal (true );
12461248 }
12471249
@@ -1778,6 +1780,7 @@ void jl_dump_native_impl(void *native_code,
17781780 if (jl_small_typeof_copy) {
17791781 jl_small_typeof_copy->setVisibility (GlobalValue::HiddenVisibility);
17801782 jl_small_typeof_copy->setDSOLocal (true );
1783+ jl_small_typeof_copy->setDLLStorageClass (GlobalValue::DLLStorageClassTypes::DefaultStorageClass);
17811784 }
17821785 }
17831786
@@ -1811,19 +1814,18 @@ void jl_dump_native_impl(void *native_code,
18111814 // reflect the address of the jl_RTLD_DEFAULT_handle variable
18121815 // back to the caller, so that we can check for consistency issues
18131816 GlobalValue *jlRTLD_DEFAULT_var = jl_emit_RTLD_DEFAULT_var (&metadataM);
1814- if (TheTriple.isOSBinFormatCOFF ()) {
1815- jlRTLD_DEFAULT_var->setDLLStorageClass (GlobalValue::DLLImportStorageClass);
1816- }
1817- addComdat (new GlobalVariable (metadataM,
1818- jlRTLD_DEFAULT_var->getType (),
1819- true ,
1820- GlobalVariable::ExternalLinkage,
1821- jlRTLD_DEFAULT_var,
1822- " jl_RTLD_DEFAULT_handle_pointer" ), TheTriple);
18231817
18241818 Type *T_size = DL.getIntPtrType (Context);
18251819 Type *T_psize = T_size->getPointerTo ();
18261820
1821+ auto FT = FunctionType::get (Type::getInt8Ty (Context)->getPointerTo ()->getPointerTo (), {}, false );
1822+ auto F = Function::Create (FT, Function::ExternalLinkage, " get_jl_RTLD_DEFAULT_handle_addr" , metadataM);
1823+ llvm::IRBuilder<> builder (BasicBlock::Create (Context, " top" , F));
1824+ builder.CreateRet (jlRTLD_DEFAULT_var);
1825+ F->setLinkage (GlobalValue::ExternalLinkage);
1826+ if (TheTriple.isOSBinFormatCOFF ())
1827+ F->setDLLStorageClass (GlobalValue::DLLStorageClassTypes::DLLExportStorageClass);
1828+
18271829 if (TheTriple.isOSWindows ()) {
18281830 // Windows expect that the function `_DllMainStartup` is present in an dll.
18291831 // Normal compilers use something like Zig's crtdll.c instead we provide a
0 commit comments