Skip to content

Commit

Permalink
Merge pull request #34997 from janvorli/implement-native-getmoduleindex
Browse files Browse the repository at this point in the history
Implement native GetModuleIndex
  • Loading branch information
janvorli authored Apr 21, 2020
2 parents 8ed18e6 + 42ad5e5 commit 85aee4d
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 170 deletions.
7 changes: 1 addition & 6 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</PropertyGroup>

<PropertyGroup>
<DefaultCoreClrSubsets>clr.runtime+linuxdac+clr.corelib+clr.nativecorelib+clr.tools+clr.buildtools+clr.packages</DefaultCoreClrSubsets>
<DefaultCoreClrSubsets>clr.runtime+linuxdac+clr.corelib+clr.nativecorelib+clr.tools+clr.packages</DefaultCoreClrSubsets>

<DefaultMonoSubsets Condition="'$(MonoEnableLLVM)' == 'true' and '$(MonoLLVMDir)' == ''">mono.llvm+</DefaultMonoSubsets>
<DefaultMonoSubsets>$(DefaultMonoSubsets)mono.runtime+mono.corelib</DefaultMonoSubsets>
Expand Down Expand Up @@ -85,7 +85,6 @@
<SubsetName Include="Clr.CoreLib" Description="The managed System.Private.CoreLib library for CoreCLR." />
<SubsetName Include="Clr.NativeCoreLib" Description="Run crossgen on System.Private.CoreLib library for CoreCLR." />
<SubsetName Include="Clr.Tools" Description="Managed tools that support CoreCLR development and testing." />
<SubsetName Include="Clr.BuildTools" Description="Tools needed for the native CoreCLR build." />
<SubsetName Include="Clr.Packages" Description="The projects that produce NuGet packages for the CoreCLR runtime, crossgen, and IL tools." />

<!-- Mono -->
Expand Down Expand Up @@ -146,10 +145,6 @@
</ItemDefinitionGroup>

<!-- CoreClr sets -->
<ItemGroup Condition="$(_subset.Contains('+clr.buildtools+'))">
<CoreClrProject Include="$(CoreClrProjectRoot)src\tools\GetModuleIndex\GetModuleIndex.csproj" />
</ItemGroup>

<ItemGroup Condition="$(_subset.Contains('+clr.corelib+'))">
<CoreClrProject Include="$(CoreClrProjectRoot)src\System.Private.CoreLib\System.Private.CoreLib.csproj" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
<!-- CoreClr dependencies -->
<MicrosoftNETCoreILAsmVersion>5.0.0-preview.4.20202.18</MicrosoftNETCoreILAsmVersion>
<MicrosoftNETSdkILVersion>5.0.0-preview.4.20202.18</MicrosoftNETSdkILVersion>
<MicrosoftFileFormatsVersion>1.0.120601</MicrosoftFileFormatsVersion>
<!-- Libraries dependencies -->
<SystemTextJsonVersion>5.0.0-preview.4.20202.18</SystemTextJsonVersion>
<runtimenativeSystemIOPortsVersion>5.0.0-alpha.1.19563.3</runtimenativeSystemIOPortsVersion>
Expand Down
25 changes: 25 additions & 0 deletions eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,28 @@ endfunction()
function(add_executable_clr)
_add_executable(${ARGV})
endfunction()

function(generate_module_index Target ModuleIndexFile)
if(CLR_CMAKE_HOST_WIN32)
set(scriptExt ".cmd")
else()
set(scriptExt ".sh")
endif()

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

set_source_files_properties(
${ModuleIndexFile}
PROPERTIES GENERATED TRUE
)

add_custom_target(
${Target}_module_index_header
DEPENDS ${ModuleIndexFile}
)
endfunction(generate_module_index)
25 changes: 25 additions & 0 deletions eng/native/genmoduleindex.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@echo off
REM Generate module index header

if [%1]==[] goto :Usage
if [%2]==[] goto :Usage

setlocal
for /f "tokens=1" %%i in ('dumpbin /HEADERS %1 ^| findstr /c:"size of image"') do set imagesize=%%i
REM Pad the extracted size to 8 hex digits
set imagesize=00000000%imagesize%
set imagesize=%imagesize:~-8%

for /f "tokens=1" %%i in ('dumpbin /HEADERS %1 ^| findstr /c:"time date"') do set timestamp=%%i
REM Pad the extracted time stamp to 8 hex digits
set timestamp=00000000%timestamp%
set timestamp=%timestamp:~-8%

echo 0x08, 0x%timestamp:~6,2%, 0x%timestamp:~4,2%, 0x%timestamp:~2,2%, 0x%timestamp:~0,2%, 0x%imagesize:~6,2%, 0x%imagesize:~4,2%, 0x%imagesize:~2,2%, 0x%imagesize:~0,2%, > %2

endlocal
exit /b 0

:Usage
echo Usage: genmoduleindex.cmd ModuleBinaryFile IndexHeaderFile
exit /b 1
29 changes: 29 additions & 0 deletions eng/native/genmoduleindex.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
#
# Generate module index header
#
set -euo pipefail

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

OSName=$(uname -s)

case "$OSName" in
Darwin)
# Extract the build id and prefix it with its length in bytes
dwarfdump -u $1 |
awk '/UUID:/ { gsub(/\-/,"", $2); printf("%02x", length($2)/2); print $2}' |
# Convert each byte of the id to 0x prefixed constant followed by comma
sed -E s/\(\.\.\)/0x\\1,\ /g > $2
;;
*)
# Extract the build id and prefix it with its length in bytes
readelf -n $1 |
awk '/Build ID:/ { printf("%02x", length($3)/2); print $3 }' |
# Convert each byte of the id to 0x prefixed constant followed by comma
sed -E s/\(\.\.\)/0x\\1,\ /g > $2
;;
esac
4 changes: 0 additions & 4 deletions eng/pipelines/coreclr/templates/build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ jobs:
- ${{ if and(eq(variables['System.TeamProject'], 'internal'), ne(variables['Build.Reason'], 'PullRequest')) }}:
- template: /eng/pipelines/common/restore-internal-tools.yml

# Build CoreCLR tools needed by the native runtime build
- script: $(Build.SourcesDirectory)$(dir)build$(scriptExt) -subset clr.buildtools $(crossArg) -arch $(archType) -c $(buildConfig) $(officialBuildIdArg) -ci /bl:$(Build.SourcesDirectory)/artifacts/log/clr.buildtools.binlog
displayName: Build CoreCLR Diagnostic Tools

# Build CoreCLR Runtime
- ${{ if ne(parameters.osGroup, 'Windows_NT') }}:
- script: $(coreClrRepoRootDir)build-runtime$(scriptExt) $(buildConfig) $(archType) $(crossArg) $(osArg) -ci $(compilerArg) $(officialBuildIdArg)
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ set(GENERATED_EVENTING_DIR ${CMAKE_CURRENT_BINARY_DIR}/Eventing)
set(VERSION_FILE_PATH "${CMAKE_BINARY_DIR}/version.c")
set(PAL_REDEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/dlls/mscordac/palredefines.S)

if(CLR_CMAKE_HOST_UNIX)
set(CLR_DOTNET_COMMAND ${CLR_REPO_ROOT_DIR}/dotnet.sh)
elseif(CLR_CMAKE_HOST_WIN32)
set(CLR_DOTNET_COMMAND ${CLR_REPO_ROOT_DIR}/dotnet.cmd)
endif(CLR_CMAKE_HOST_UNIX)

# Avoid logging when skipping up-to-date copies
set(CMAKE_INSTALL_MESSAGE LAZY)

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/src/debug/runtimeinfo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ set(RUNTIMEINFO_SOURCES

add_library_clr(runtimeinfo STATIC ${RUNTIMEINFO_SOURCES})

add_dependencies(runtimeinfo runtime_module_index_header)
add_dependencies(runtimeinfo dac_module_index_header)
add_dependencies(runtimeinfo dbi_module_index_header)
add_dependencies(runtimeinfo coreclr_module_index_header)
add_dependencies(runtimeinfo mscordaccore_module_index_header)
add_dependencies(runtimeinfo mscordbi_module_index_header)
19 changes: 1 addition & 18 deletions src/coreclr/src/dlls/mscordac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,24 +190,7 @@ target_link_libraries(mscordaccore PRIVATE ${COREDAC_LIBRARIES})
# Create the DAC module index header file containing the DAC build id
# for xplat and the timestamp/size on Windows.
if(FEATURE_SINGLE_FILE_DIAGNOSTICS)
set(
DAC_MODULE_INDEX_FILE
${GENERATED_INCLUDE_DIR}/dacmoduleindex.h
)
add_custom_command(
OUTPUT ${DAC_MODULE_INDEX_FILE}
COMMAND ${CLR_DOTNET_COMMAND} ${CMAKE_INSTALL_PREFIX}/GetModuleIndex/GetModuleIndex.dll $<TARGET_FILE:mscordaccore> ${DAC_MODULE_INDEX_FILE}
DEPENDS mscordaccore
COMMENT "Generating DAC module index file -> ${DAC_MODULE_INDEX_FILE}"
)
set_source_files_properties(
${DAC_MODULE_INDEX_FILE}
PROPERTIES GENERATED TRUE
)
add_custom_target(
dac_module_index_header
DEPENDS ${DAC_MODULE_INDEX_FILE}
)
generate_module_index(mscordaccore ${GENERATED_INCLUDE_DIR}/dacmoduleindex.h)
endif(FEATURE_SINGLE_FILE_DIAGNOSTICS)

# add the install targets
Expand Down
19 changes: 1 addition & 18 deletions src/coreclr/src/dlls/mscordbi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,7 @@ endif(CLR_CMAKE_HOST_WIN32)
# Create the DBI module index header file containing the DBI build id
# for xplat and the timestamp/size on Windows.
if(FEATURE_SINGLE_FILE_DIAGNOSTICS)
set(
DBI_MODULE_INDEX_FILE
${GENERATED_INCLUDE_DIR}/dbimoduleindex.h
)
add_custom_command(
OUTPUT ${DBI_MODULE_INDEX_FILE}
COMMAND ${CLR_DOTNET_COMMAND} ${CMAKE_INSTALL_PREFIX}/GetModuleIndex/GetModuleIndex.dll $<TARGET_FILE:mscordbi> ${DBI_MODULE_INDEX_FILE}
DEPENDS mscordbi
COMMENT "Generating DBI module index file -> ${DBI_MODULE_INDEX_FILE}"
)
set_source_files_properties(
${DBI_MODULE_INDEX_FILE}
PROPERTIES GENERATED TRUE
)
add_custom_target(
dbi_module_index_header
DEPENDS ${DBI_MODULE_INDEX_FILE}
)
generate_module_index(mscordbi ${GENERATED_INCLUDE_DIR}/dbimoduleindex.h)
endif(FEATURE_SINGLE_FILE_DIAGNOSTICS)

# add the install targets
Expand Down
19 changes: 1 addition & 18 deletions src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,7 @@ target_link_libraries(coreclr ${CORECLR_LIBRARIES})
# Create the runtime module index header file containing the coreclr build id
# for xplat and the timestamp/size on Windows.
if(FEATURE_SINGLE_FILE_DIAGNOSTICS)
set(
RUNTIME_MODULE_INDEX_FILE
${GENERATED_INCLUDE_DIR}/runtimemoduleindex.h
)
add_custom_command(
OUTPUT ${RUNTIME_MODULE_INDEX_FILE}
COMMAND ${CLR_DOTNET_COMMAND} ${CMAKE_INSTALL_PREFIX}/GetModuleIndex/GetModuleIndex.dll $<TARGET_FILE:coreclr> ${RUNTIME_MODULE_INDEX_FILE}
DEPENDS coreclr
COMMENT "Generating runtime module index file -> ${RUNTIME_MODULE_INDEX_FILE}"
)
set_source_files_properties(
${RUNTIME_MODULE_INDEX_FILE}
PROPERTIES GENERATED TRUE
)
add_custom_target(
runtime_module_index_header
DEPENDS ${RUNTIME_MODULE_INDEX_FILE}
)
generate_module_index(coreclr ${GENERATED_INCLUDE_DIR}/runtimemoduleindex.h)
endif(FEATURE_SINGLE_FILE_DIAGNOSTICS)

if(CLR_CMAKE_TARGET_WIN32)
Expand Down
81 changes: 0 additions & 81 deletions src/coreclr/src/tools/GetModuleIndex/GetModuleIndex.cs

This file was deleted.

15 changes: 0 additions & 15 deletions src/coreclr/src/tools/GetModuleIndex/GetModuleIndex.csproj

This file was deleted.

0 comments on commit 85aee4d

Please sign in to comment.