Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions eng/native/configuretools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ if(NOT WIN32 AND NOT CLR_CMAKE_TARGET_BROWSER)
locate_toolchain_exec(objdump CMAKE_OBJDUMP)
locate_toolchain_exec(objcopy CMAKE_OBJCOPY)

execute_process(
COMMAND ${CMAKE_OBJCOPY} --help
OUTPUT_VARIABLE OBJCOPY_HELP_OUTPUT
)

if(CLR_CMAKE_TARGET_ANDROID)
Copy link
Member Author

Choose a reason for hiding this comment

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

This block was unused.

set(TOOLSET_PREFIX ${ANDROID_TOOLCHAIN_PREFIX})
elseif(CMAKE_CROSSCOMPILING AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD AND
CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv8l|armv7l|armv6l|aarch64|arm|s390x|ppc64le)$")
set(TOOLSET_PREFIX "${TOOLCHAIN}-")
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 "")
Copy link
Member

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?

Copy link
Member Author

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 purposes

We 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.

locate_toolchain_exec(objcopy CMAKE_OBJCOPY)
endif ()

endif()
endif()
Expand Down