Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DBI loading problem on Linux #82461

Merged
merged 2 commits into from
Feb 22, 2023
Merged

Conversation

mikem8361
Copy link
Member

@mikem8361 mikem8361 commented Feb 22, 2023

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 (and I assume other debuggers) 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.

Before the changes:

~/diagnostics/.dotnet-test/shared/Microsoft.NETCore.App/8.0.0-preview.2.23116.1$ ldd -r libmscordbi.so
        linux-vdso.so.1 (0x00007ffe54bee000)
        libmscordaccore.so => /home/mikem/diagnostics/.dotnet-test/shared/Microsoft.NETCore.App/8.0.0-preview.2.23116.1/./libmscordaccore.so (0x00007fc29f686000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fc29f499000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc29f34a000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc29f32f000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc29f13d000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fc29faa0000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc29f118000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fc29f10e000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc29f108000)
undefined symbol: _Z22DAC_PAL_RegisterModulePKc (./libmscordbi.so)
undefined symbol: _Z24DAC_PAL_UnregisterModulePv        (./libmscordbi.so)

When I build the latest main I locally I get even more undefines before this fix:

        linux-vdso.so.1 (0x00007ffef5dfe000)
        libmscordaccore.so => /home/mikem/runtime/artifacts/bin/coreclr/linux.x64.Release/sharedFramework/./libmscordaccore.so (0x00007f4f1bb77000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f4f1b98a000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4f1b83b000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4f1b820000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4f1b62e000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f4f1bf73000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4f1b609000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f4f1b5ff000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4f1b5f9000)
undefined symbol: _ZN14UTSemReadWrite11UnlockWriteEv    (./libmscordbi.so)
undefined symbol: _ZN14UTSemReadWriteC1Ev       (./libmscordbi.so)
undefined symbol: _ZNK9PEDecoder14CheckCorHeaderEv      (./libmscordbi.so)
undefined symbol: _Z17SplitPathInteriorPKDsPS0_PmS1_S2_S1_S2_S1_S2_     (./libmscordbi.so)
undefined symbol: _ZN14UTSemReadWrite8LockReadEv        (./libmscordbi.so)
undefined symbol: _ZNK9PEDecoder11GetMetadataEPj        (./libmscordbi.so)
undefined symbol: DAC_PAL_UnregisterModule      (./libmscordbi.so)
undefined symbol: _ZN14UTSemReadWrite9LockWriteEv       (./libmscordbi.so)
undefined symbol: _ZN8MDFormat15VerifySignatureEP16STORAGESIGNATUREj    (./libmscordbi.so)
undefined symbol: DAC_PAL_RegisterModule        (./libmscordbi.so)
undefined symbol: _ZN14UTSemReadWrite4InitEv    (./libmscordbi.so)
undefined symbol: _ZNK9PEDecoder14CheckNTHeadersEv      (./libmscordbi.so)
undefined symbol: _Z19_FillMDDefaultValuehPKvjP15_MDDefaultValue        (./libmscordbi.so)
undefined symbol: _ZN8MDFormat14GetFirstStreamEP13STORAGEHEADERPKv      (./libmscordbi.so)
undefined symbol: _ZNK9PEDecoder10GetRvaDataEj8IsNullOK (./libmscordbi.so)
undefined symbol: _ZNK9PEDecoder12HasNTHeadersEv        (./libmscordbi.so)
undefined symbol: _ZN14UTSemReadWrite10UnlockReadEv     (./libmscordbi.so)
undefined symbol: _ZN14UTSemReadWriteD1Ev       (./libmscordbi.so)
undefined symbol: _ZNK9PEDecoder20FindReadyToRunHeaderEv        (./libmscordbi.so)

Part of PR dotnet#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.
@mikem8361 mikem8361 requested review from am11 and hoyosjs February 22, 2023 02:11
@mikem8361 mikem8361 self-assigned this Feb 22, 2023
@am11
Copy link
Member

am11 commented Feb 22, 2023

@mikem8361, unfortunately it breaks clang 16 build. It's currently in rc3 stage (scheduled to be released on March 7):

# host environment: bash on ubuntu 20.04 amd64
$ docker build - -t dotnet-prereq-clang16 <<EOF
FROM amd64/ubuntu

RUN apt update; apt install -y cmake curl wget software-properties-common gnupg liblttng-ust-dev libkrb5-dev libicu-dev libssl-dev libz-dev; \
    curl -sSL https://apt.llvm.org/llvm.sh | bash -s - 16 all
EOF

$ docker run --rm -v$(pwd):/runtime dotnet-prereq-clang16 /runtime/src/coreclr/build-runtime.sh

# snip
[ 85%] Linking CXX shared library libclrjit.so
[ 85%] Building CXX object jit/CMakeFiles/clrjit_win_x86_x64.dir/lir.cpp.o
ld.lld: error: version script assignment of 'V1.0' to symbol 'PAL_RegisterModule' failed: symbol not defined
ld.lld: error: version script assignment of 'V1.0' to symbol 'PAL_UnregisterModule' failed: symbol not defined
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [dlls/mscordbi/CMakeFiles/mscordbi.dir/build.make:187: dlls/mscordbi/libmscordbi.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:4537: dlls/mscordbi/CMakeFiles/mscordbi.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 85%] Building CXX object jit/CMakeFiles/clrjit_unix_x64_x64.dir/lsra.cpp.o
[ 85%] Building CXX object jit/CMakeFiles/clrjit_win_x64_x64.dir/emitxarch.cpp.o
...
make: *** [Makefile:136: all] Error 2
/
Failed to build "CoreCLR component".

Do you see another way to satisfy both lld-16 and SOS?

@am11
Copy link
Member

am11 commented Feb 22, 2023

With main the build succeeds and ldd resolves all symbols:

$ docker run --rm -v$(pwd):/runtime dotnet-prereq-clang16 \
    ldd /runtime/artifacts/bin/coreclr/linux.x64.Debug/libmscordbi.so
 
        linux-vdso.so.1 (0x00007ffda470a000)
        libmscordaccore.so => /runtime/artifacts/bin/coreclr/linux.x64.Debug/libmscordaccore.so (0x00007fdd66eec000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fdd66cbb000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fdd66bd4000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fdd66bb4000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fdd6698c000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fdd677db000)

@mikem8361
Copy link
Member Author

I think you need the -r to show the undefined symbols.

@hoyosjs
Copy link
Member

hoyosjs commented Feb 22, 2023

We might have to merge this while we figure out next steps. It would block upstack repos from debugging.

@mikem8361
Copy link
Member Author

I have no idea why this is happening with clang 16 and not older versions.

Like Juan said it is breaking SOS, VS debugging and our debugger testing. We should merge this and figure out the clang 16 issue.

Copy link
Member

@am11 am11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured out a way to make both worlds happy.

@@ -100,7 +100,10 @@ elseif(CLR_CMAKE_HOST_UNIX)
mscordaccore
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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)

Fixes the compilation error and ldd -r libmscordbi.so reports no missing symbols.

Copy link
Member

@am11 am11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks! :)

@mikem8361 mikem8361 merged commit 71034dd into dotnet:main Feb 22, 2023
@mikem8361 mikem8361 deleted the fixdbiimport branch February 22, 2023 07:28
@ghost ghost locked as resolved and limited conversation to collaborators Mar 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants