-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Improve objcopy detection #71742
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
Improve objcopy detection #71742
Conversation
|
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
|
Tagging subscribers to this area: @hoyosjs Issue DetailsSee #71270 (comment) Up until recently (#71446), we were using binutils' objcopy on Linux. We should fallback to that if llvm-objcopy provided by selected (older) toolchain does not meet the requirement.
|
| OUTPUT_VARIABLE OBJCOPY_HELP_OUTPUT | ||
| ) | ||
|
|
||
| if(CLR_CMAKE_TARGET_ANDROID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block was unused.
|
@jkotas, I have not changed anything for NativeAOT, since there we anyway require recent versions of llvm / clang (and only use objcopy when user explicitly sets -p:StripSymbols=true). |
| endif() | ||
| # if llvm-objcopy does not support --only-keep-debug argument, try to locate binutils' objcopy | ||
| if (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT "${OBJCOPY_HELP_OUTPUT}" MATCHES "--only-keep-debug") | ||
| set(TOOLSET_PREFIX "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
llvm also has a only-keep-debug flag, only with one dash though. Any reason to favor binutils over llvm's and just adjusting the flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My test was:
$ docker run -it ubuntu:18.04
# inside the container, install different versions
$ apt update; apt install -y llvm-6 llvm-7 llvm-8 llvm-9 llvm-10
# test for only-keep-debug
# v6 - desired argument is unsupported
$ llvm-objcopy-6.0 --help | grep only-keep-debug
# nothing found
# v7 - supported with single hyphen but is a no-op
$ llvm-objcopy-7 --help | grep only-keep-debug
-only-keep-debug Currently ignored. Only for compaitability with GNU objcopy.
# v8 - same as v7
$ llvm-objcopy-8 --help | grep only-keep-debug
-only-keep-debug Currently ignored. Only for compatibility with GNU objcopy.
# v9 - supported with double hyphen
$ llvm-objcopy-9 --help | grep only-keep-debug
--only-keep-debug Clear sections that would not be stripped by --strip-debug. Currently only implemented for COFF.
# v10 - same as v9
$ llvm-objcopy-10 --help | grep only-keep-debug
--only-keep-debug Produce a debug file as the output that only preserves contents of sections useful for debugging purposesWe want only-keep-debug for consistent output; avoid binary size bloat and avoid repeating issues like #49081. Therefore, we fallback to binutils' objcopy when llvm-objcopy is incapable of stripping the symbols. As you can see above, versions of llvm-objcopy which support double hyphened argument provide non-nop functionality.
hoyosjs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then this is the right fix. Thanks!
|
Failure is #70450 |
Unblocks #71725. Followup: #71742 Prior to #71742, we were calling `locate_toolchain_exec` once per tool. Calling it twice with different prefix gives us the old result, which is something we don't want (we only call this local function a few times in this file, and each time for intention to "lookup" the executable).
See #71270 (comment)
Up until recently (#71446), we were using binutils' objcopy on Linux. We should fallback to that if llvm-objcopy provided by selected (older) toolchain does not meet the requirement.