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 debug symbol generation #34154

Merged
merged 3 commits into from
Mar 30, 2020
Merged

Conversation

janvorli
Copy link
Member

The debug symbol generation got recently broken. For most of the
shared libraries, the debug symbols were stripped twice due to
the fact that install_clr for them was invoked twice - once for
the default install location and once for the sharedFramework
location and the stripping was executed in both of them. First
stripping stripped the symbols off the target binary and set
so called debuglink in the binary to point to the symbol file.
This debuglink includes a crc32 of the dbg symbols file.
The second stripping tried to strip symbols from the already
stripped binary. That resulted in a small dbg symbols file
that didn't actually contain any useful symbols. Moreover,
it is not possible to set a debuglink in a binary if it is
already set there. So the second attempt failed and the crc
was left set to the crc of the previous debug. Thus when
debugger loads such a binary, it cannot find the debug symbols
file, as the crc doesn't match. And even if it matched, the
data would have no value.

The fix is to modify install_clr so that it has an extra
optional argument to specify the secondary install location and
use just one install_clr per target. The function then does the
stripping just once and the actual installation once or twice
depending on the secondary location argumenbt presence.

Close #34108

The debug symbol generation got recently broken. For most of the
shared libraries, the debug symbols were stripped twice due to
the fact that install_clr for them was invoked twice - once for
the default install location and once for the sharedFramework
location and the stripping was executed in both of them. First
stripping stripped the symbols off the target binary and set
so called debuglink in the binary to point to the symbol file.
This debuglink includes a crc32 of the dbg symbols file.
The second stripping tried to strip symbols from the already
stripped binary. That resulted in a small dbg symbols file
that didn't actually contain any useful symbols. Moreover,
it is not possible to set a debuglink in a binary if it is
already set there. So the second attempt failed and the crc
was left set to the crc of the previous debug. Thus when
debugger loads such a binary, it cannot find the debug symbols
file, as the crc doesn't match. And even if it matched, the
data would have no value.

The fix is to modify install_clr so that it has an extra
optional argument to specify the secondary install location and
use just one install_clr per target. The function then does the
stripping just once and the actual installation once or twice
depending on the secondary location argumenbt presence.
@janvorli janvorli added this to the 5.0 milestone Mar 26, 2020
@janvorli janvorli requested a review from jkoritzinsky March 26, 2020 20:44
@janvorli janvorli self-assigned this Mar 26, 2020
@janvorli
Copy link
Member Author

cc: @am11

if(CLR_CMAKE_TARGET_WIN32)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pdb DESTINATION ${destination_path}/PDB)
install(FILES ${symbol_file} DESTINATION ${destination_path}/PDB)
Copy link
Member

Choose a reason for hiding this comment

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

I think it is better, if we do not modify this (Windows) part at this stage, as it is working out fine. Otherwise we would need to update libraries and installer as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll rather look into fixing the libraries and installer. I have forgotten that they use these now too.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, I remember doing similar cleanup in libraries, it was something like touching one file (src/libraries/Native/Unix/CMakeLists.txt) vs. multiple other CMakeLists.txt under libraries, therefore, ended up favoring the common pattern so to touch fewer files. :)

@am11
Copy link
Member

am11 commented Mar 26, 2020

Thanks @janvorli! 👍

Failure is due to libraries symbols, which I think can be fixed by reverting the changes in the common, kitchen sink strip function.

install_symbols(${targetName} .)
set(install_source_file $<TARGET_FILE:${targetName}>)
install(PROGRAMS ${install_source_file} DESTINATION .)
install_with_stripped_symbols(${targetName} .)
endfunction()
Copy link
Member

Choose a reason for hiding this comment

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

A nit: since there is not much left in this function, would it make sense to inline this at call sites by introducing a variable in this file:

set(CLR_LIBRARIES_UNIX_ROOT ${CMAKE_CURRENT_LIST_DIR})

and at call sites: install_with_stripped_symbols(System.Native.XYZ ${CLR_LIBRARIES_UNIX_ROOT})?

Copy link
Member Author

Choose a reason for hiding this comment

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

The . doesn't represent the CMAKE_CURRENT_LIST_DIR, but rather the installer output root (CMAKE_INSTALL_PREFIX), as the destination argument of the install is relative to that.
But it seems to make sense to replace this function with call to install_with_stripped_symbols(System.Native.XYZ .) to make it more consistent with the other installation commands that strip symbols (except for the coreclr one that's special).

Copy link
Member

Choose a reason for hiding this comment

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

replace this function with call to install_with_stripped_symbols(System.Native.XYZ .)

Makes sense, I think that will be a bit more work to get packaging pick it up. I tried that previous but the packaging step was failing, IIRC.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure why should there be a difference. It should generate exactly the same files at the same places as before my change.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can see the problem - the install_with_stripped_symbols uses install(PROGRAMS ...) while the installer was using install(TARGETS ...) and I've missed that difference. That causes the .lib for .dll files to not to be installed.

@janvorli janvorli closed this Mar 30, 2020
@janvorli janvorli reopened this Mar 30, 2020
@janvorli
Copy link
Member Author

@dotnet/dnceng some of the test legs are failing due to the inability to download .NET Core SDK. For example:
https://dev.azure.com/dnceng/public/_build/results?buildId=579375&view=logs&j=0ae671a0-c5c0-596d-9a9c-5c8cba56c6c8&t=d6ec3c78-037b-5ec7-c41b-a4cbf9e8f94f&l=37

https://dev.azure.com/dnceng/public/_build/results?buildId=579375&view=logs&j=a85e5b1a-b4c5-52b5-5d3e-4765a28b1fec&t=9fb38f79-da06-5ce3-5637-ee9671c28894

It uses the following URL and when I open it in a web browser, I get the response below.
https://dotnetcli.azureedge.net/dotnet/Sdk/5.0.100-preview.3.20170.6/dotnet-dev-ubuntu.16.04-x64.5.0.100-preview.3.20170.6.tar.gz

<Error>
<Code>BlobNotFound</Code>
<Message>The specified blob does not exist. RequestId:42313bc6-201e-0034-2088-060763000000 Time:2020-03-30T11:45:30.1460059Z</Message>
</Error>

@dagood
Copy link
Member

dagood commented Mar 30, 2020

You hit #34015. The 404 isn't the right URL to check, curl: (56) GnuTLS recv error (-9): A TLS packet with unexpected length was received. is the error. I filed https://github.com/dotnet/sdk/issues/10975 to track fixing this red herring.

@janvorli
Copy link
Member Author

The failures in the CI are due to #28553

@janvorli
Copy link
Member Author

@jkoritzinsky can you please take a look at this PR?

@janvorli janvorli merged commit b186c97 into dotnet:master Mar 30, 2020
@janvorli janvorli deleted the fix-debug-symbols branch March 30, 2020 18:32
@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
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.

Native debugging with symbols is broken on Linux/arm64
4 participants