Skip to content

Commit

Permalink
Add introspection for readelf (#85298)
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 committed Apr 26, 2023
1 parent ddd591d commit e8b41db
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions eng/native/configuretools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ if(NOT WIN32 AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI)

if(NOT CLR_CMAKE_TARGET_APPLE AND (NOT CLR_CMAKE_TARGET_ANDROID OR CROSS_ROOTFS))
locate_toolchain_exec(objdump CMAKE_OBJDUMP YES)
locate_toolchain_exec(readelf CMAKE_READELF YES)

unset(CMAKE_OBJCOPY CACHE)
locate_toolchain_exec(objcopy CMAKE_OBJCOPY NO)
Expand Down
12 changes: 7 additions & 5 deletions eng/native/genmoduleindex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
set -euo pipefail

if [[ "$#" -lt 2 ]]; then
echo "Usage: genmoduleindex.sh ModuleBinaryFile IndexHeaderFile"
echo "Usage: genmoduleindex.sh ModuleBinaryFile IndexHeaderFile readelfBinaryPath"
exit 1
fi

Expand All @@ -25,16 +25,18 @@ function printIdAsBinary() {

case "$(uname -s)" in
Darwin)
cmd="dwarfdump -u $1"
cmd="dwarfdump"
arg="-u"
pattern='^UUID: ([0-9A-Fa-f\-]+)';;
*)
cmd="readelf -n $1"
cmd="$3"
arg="-n"
pattern='^[[:space:]]*Build ID: ([0-9A-Fa-f\-]+)';;
esac

while read -r line; do
"$cmd" "$arg" "$1" | while read -r line; do
if [[ "$line" =~ $pattern ]]; then
printIdAsBinary "${BASH_REMATCH[1]//-/}"
break
fi
done < <(eval "$cmd") > "$2"
done > "$2"
2 changes: 1 addition & 1 deletion src/coreclr/debug/runtimeinfo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function(generate_module_index Target ModuleIndexFile)

add_custom_command(
OUTPUT ${ModuleIndexFile}
COMMAND ${CLR_ENG_NATIVE_DIR}/genmoduleindex${scriptExt} $<TARGET_FILE:${Target}> ${ModuleIndexFile}
COMMAND ${CLR_ENG_NATIVE_DIR}/genmoduleindex${scriptExt} $<TARGET_FILE:${Target}> ${ModuleIndexFile} ${CMAKE_READELF}
DEPENDS ${Target}
COMMENT "Generating ${Target} module index file -> ${ModuleIndexFile}"
)
Expand Down

0 comments on commit e8b41db

Please sign in to comment.