@@ -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
@@ -1773,6 +1775,7 @@ void jl_dump_native_impl(void *native_code,
17731775 if (jl_small_typeof_copy) {
17741776 jl_small_typeof_copy->setVisibility (GlobalValue::HiddenVisibility);
17751777 jl_small_typeof_copy->setDSOLocal (true );
1778+ jl_small_typeof_copy->setDLLStorageClass (GlobalValue::DLLStorageClassTypes::DefaultStorageClass);
17761779 }
17771780 }
17781781
@@ -1804,16 +1807,18 @@ void jl_dump_native_impl(void *native_code,
18041807 // reflect the address of the jl_RTLD_DEFAULT_handle variable
18051808 // back to the caller, so that we can check for consistency issues
18061809 GlobalValue *jlRTLD_DEFAULT_var = jl_emit_RTLD_DEFAULT_var (&metadataM);
1807- addComdat (new GlobalVariable (metadataM,
1808- jlRTLD_DEFAULT_var->getType (),
1809- true ,
1810- GlobalVariable::ExternalLinkage,
1811- jlRTLD_DEFAULT_var,
1812- " jl_RTLD_DEFAULT_handle_pointer" ), TheTriple);
18131810
18141811 Type *T_size = DL.getIntPtrType (Context);
18151812 Type *T_psize = T_size->getPointerTo ();
18161813
1814+ auto FT = FunctionType::get (Type::getInt8Ty (Context)->getPointerTo ()->getPointerTo (), {}, false );
1815+ auto F = Function::Create (FT, Function::ExternalLinkage, " get_jl_RTLD_DEFAULT_handle_addr" , metadataM);
1816+ llvm::IRBuilder<> builder (BasicBlock::Create (Context, " top" , F));
1817+ builder.CreateRet (jlRTLD_DEFAULT_var);
1818+ F->setLinkage (GlobalValue::ExternalLinkage);
1819+ if (TheTriple.isOSBinFormatCOFF ())
1820+ F->setDLLStorageClass (GlobalValue::DLLStorageClassTypes::DLLExportStorageClass);
1821+
18171822 if (TheTriple.isOSWindows ()) {
18181823 // Windows expect that the function `_DllMainStartup` is present in an dll.
18191824 // Normal compilers use something like Zig's crtdll.c instead we provide a
0 commit comments