Skip to content

Commit

Permalink
Fix DBI loading problem on Linux (#82461)
Browse files Browse the repository at this point in the history
* Fix DBI loading problem on Linux

Part of PR #81573 needed to be undone to build libmscordbi.so without
any undefined symbols from the DAC. The DAC_PAL_RegisterModule, etc. stubs I recommended didn't work and DBI
could not be loaded by SOS because of missing exports.

The double pass at the libraries from the `target_link_libraries(mscordbi ${COREDBI_LIBRARIES} ${COREDBI_LIBRARIES})`
cmake file needed to be restored. The stubs were not needed after that.

* Fix clang16 build problems
  • Loading branch information
mikem8361 authored Feb 22, 2023
1 parent 7d3a2bb commit 71034dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
16 changes: 15 additions & 1 deletion src/coreclr/dlls/mscordbi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,21 @@ elseif(CLR_CMAKE_HOST_UNIX)
mscordaccore
)

target_link_libraries(mscordbi ${COREDBI_LIBRARIES})
# Before llvm 16, lld was setting `--undefined-version` by default. The default was
# flipped to `--no-undefined-version` in lld 16, so we will explicitly set it to
# `--undefined-version` for our use-case.
include(CheckLinkerFlag OPTIONAL)
if(COMMAND check_linker_flag)
check_linker_flag(CXX -Wl,--undefined-version LINKER_SUPPORTS_UNDEFINED_VERSION)
if (LINKER_SUPPORTS_UNDEFINED_VERSION)
add_linker_flag(-Wl,--undefined-version)
endif(LINKER_SUPPORTS_UNDEFINED_VERSION)
endif(COMMAND check_linker_flag)

# COREDBI_LIBRARIES is mentioned twice because ld is one pass linker and will not find symbols
# if they are defined after they are used. Having all libs twice makes sure that ld will actually
# find all symbols.
target_link_libraries(mscordbi ${COREDBI_LIBRARIES} ${COREDBI_LIBRARIES})

add_dependencies(mscordbi mscordaccore)

Expand Down
15 changes: 0 additions & 15 deletions src/coreclr/dlls/mscordbi/mscordbi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,3 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
// Defer to the main debugging code.
return DbgDllMain(hInstance, dwReason, lpReserved);
}

#if defined(TARGET_LINUX) && !defined(HOST_WINDOWS)
PALIMPORT HINSTANCE PALAPI DAC_PAL_RegisterModule(IN LPCSTR lpLibFileName);
PALIMPORT VOID PALAPI DAC_PAL_UnregisterModule(IN HINSTANCE hInstance);

HINSTANCE PALAPI PAL_RegisterModule(IN LPCSTR lpLibFileName)
{
return DAC_PAL_RegisterModule(lpLibFileName);
}

VOID PALAPI PAL_UnregisterModule(IN HINSTANCE hInstance)
{
DAC_PAL_UnregisterModule(hInstance);
}
#endif

0 comments on commit 71034dd

Please sign in to comment.