Skip to content

Commit

Permalink
[netcore] Improve Jitdiff tool (#17960)
Browse files Browse the repository at this point in the history
use `objdump` arguments to reduce verbosity (no raw bytes, etc) and make the dasm more diff-friendly.
On Linux all functions have a random prefix (address) - replace it with `0xD1FFAB1E` constant). On macOS it's fine by default.

Also, allow to generate diffs for a single assembly via `dump-asm-lib` rule.
  • Loading branch information
EgorBo authored and akoeplinger committed Nov 29, 2019
1 parent 608c936 commit 9a18b6f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
24 changes: 17 additions & 7 deletions netcore/Makefile
Expand Up @@ -30,6 +30,7 @@ endif
ifeq ($(HOST_PLATFORM),macos)
PLATFORM_AOT_SUFFIX := .dylib
PLATFORM_AOT_PREFIX := lib
OBJDUMP = objdump -x86-asm-syntax=intel --no-show-raw-insn -no-leading-addr -no-leading-headers -d
NETCORESDK_EXT = tar.gz
UNZIPCMD = tar -xvf
XUNIT_INNER_ARGS = -notrait category=nonosxtests @../../../../CoreFX.issues_mac.rsp
Expand All @@ -40,6 +41,7 @@ endif
ifeq ($(HOST_PLATFORM),linux)
PLATFORM_AOT_SUFFIX := .so
PLATFORM_AOT_PREFIX := lib
OBJDUMP = objdump -M intel --no-show-raw-insn -d
NETCORESDK_EXT = tar.gz
UNZIPCMD = tar -xvf
XUNIT_INNER_ARGS = -notrait category=nonlinuxtests @../../../../CoreFX.issues_linux.rsp
Expand Down Expand Up @@ -110,7 +112,7 @@ patch-local-dotnet-aot-llvm: patch-local-dotnet
for assembly in ../.dotnet/shared/Microsoft.NETCore.App/$(BOOTSTRAP_RUNTIME)/*.dll; do \
echo "[AOT] $$assembly"; \
PATH="../llvm/usr/bin/:$(PATH)" \
MONO_ENV_OPTIONS="--aot=llvm,llvmllc=\"-mcpu=native\"" \
MONO_ENV_OPTIONS="--aot=llvm,mcpu=native" \
$(DOTNET) $$assembly ; \
done; \

Expand Down Expand Up @@ -285,17 +287,25 @@ run-tests-coreclr-%: prepare update-tests-coreclr
# dump asm for all methods in BCL using LLVM AOT, e.g.:
# make dump-asm-bcl DUMPASM_OUT=dumps/before-my-jit-fix
dump-asm-bcl: patch-local-dotnet
mkdir -p $(DUMPASM_OUT)
@if test -z "$(DUMPASM_OUT)"; then echo "DUMPASM_OUT is not set"; exit 1; fi
mkdir -p $(DUMPASM_OUT)
for assembly in ../.dotnet/shared/Microsoft.NETCore.App/$(BOOTSTRAP_RUNTIME)/*.dll; do \
printf "\n[AOT] $$(basename $$assembly):\n\n"; \
PATH="../llvm/usr/bin/:$(PATH)" \
MONO_ENV_OPTIONS="--aot=llvm,mcpu=native" \
$(DOTNET) $$assembly ; \
objdump -d "$$assembly$(PLATFORM_AOT_SUFFIX)" > "$(DUMPASM_OUT)/$$(basename $$assembly)$(PLATFORM_AOT_SUFFIX).dasm" ; \
$(MAKE) dump-asm-lib DUMPASM_LIB=$$assembly ; \
done; \
cd ../.dotnet/shared/Microsoft.NETCore.App/$(BOOTSTRAP_RUNTIME) && rm *.dll$(PLATFORM_AOT_SUFFIX)

# dump asm for a specific assembly using LLVM AOT, e.g.:
# make dump-asm-lib DUMPASM_OUT=dumps/before-my-jit-fix DUMPASM_LIB=/path/to/System.Private.CoreLib.dll
dump-asm-lib: patch-local-dotnet
@if test -z "$(DUMPASM_LIB)"; then echo "DUMPASM_LIB is not set"; exit 1; fi
@if test -z "$(DUMPASM_OUT)"; then echo "DUMPASM_OUT is not set"; exit 1; fi
mkdir -p $(DUMPASM_OUT)
PATH="../llvm/usr/bin/:$(PATH)" \
MONO_ENV_OPTIONS="--aot=llvm,mcpu=native" \
$(DOTNET) $(DUMPASM_LIB)
$(OBJDUMP) "$(DUMPASM_LIB)$(PLATFORM_AOT_SUFFIX)" > "$(DUMPASM_OUT)/$(notdir $(DUMPASM_LIB))$(PLATFORM_AOT_SUFFIX).dasm"

# Generate asm diffs, a typical workflow may look like this:
#
# make dump-asm-bcl DUMPASM_OUT=dumps/before-my-jit-fix
Expand All @@ -310,4 +320,4 @@ jitdiff:
cd tools/jitdiff && $(DOTNET) run -c Release -- "$(BEFORE)" "$(AFTER)"

distdir:
distclean:
distclean:
3 changes: 2 additions & 1 deletion netcore/tools/jitdiff/jitdiff.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -116,7 +117,7 @@ static bool TryParseFunctionName (string str, out string name)
// depends on objdump, let's use the whole line as a name if it ends with `:`
if (str.EndsWith (':'))
{
name = str;
name = Regex.Replace(str, @"(?i)\b([a-f0-9]+){8,16}\b", m => "0xD1FFAB1E");
return true;
}
name = null;
Expand Down

0 comments on commit 9a18b6f

Please sign in to comment.