Last active
January 31, 2020 20:55
-
-
Save mikedld/9edcc7f0377c43e79bb81e353f3ddd1c to your computer and use it in GitHub Desktop.
Compare object files from two revisions (MSVC)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(Mandatory=$True)] [String] $SourceDir, | |
[Parameter(Mandatory=$True)] [String] $OldRevision, | |
[Parameter(Mandatory=$True)] [String] $NewRevision | |
) | |
$SourceDir = (Get-Item $SourceDir).FullName | |
$BuildDir = (Get-Item .).FullName | |
$BuildConfig = 'RelWithDebInfo' | |
function DoBuild($Revision, $ObjectFilesDir) { | |
Set-Location $BuildDir | |
cmake --build . --config $BuildConfig --target clean | |
Set-Location $SourceDir | |
git checkout . | |
git checkout $Revision | |
git apply "$PSScriptRoot\line_to_zero.patch" # change `__LINE__` to `0` to avoid extra changes | |
Set-Location $BuildDir | |
cmake --build . --config $BuildConfig | |
Remove-Item $ObjectFilesDir -Recurse -Force > $null | |
Get-ChildItem . -Recurse -Exclude *CompilerId* -Include *.obj -File | ForEach-Object { | |
$ObjectFile = Resolve-Path $_.FullName -Relative | |
$ObjectFileDir = Resolve-Path (Get-Item "$ObjectFile\..").FullName -Relative | |
New-Item "$ObjectFilesDir\$ObjectFileDir" -ItemType Directory -Force > $null | |
Copy-Item $ObjectFile "$ObjectFilesDir\$ObjectFile" -Force > $null | |
} | |
} | |
function GetFileList($Dir) { | |
Set-Location $Dir && Get-ChildItem . -Recurse | ForEach-Object { Resolve-Path $_.FullName -Relative } | |
} | |
$OldObjectFilesDir = "${BuildDir}.OldObjectFiles" | |
DoBuild $OldRevision $OldObjectFilesDir | |
$NewObjectFilesDir = "${BuildDir}.NewObjectFiles" | |
DoBuild $NewRevision $NewObjectFilesDir | |
Compare-Object (GetFileList $OldObjectFilesDir) (GetFileList $NewObjectFilesDir) | |
Set-Location $OldObjectFilesDir | |
Get-ChildItem . -Recurse -Include *.obj -File | ForEach-Object -Parallel { | |
function DumpObject($ObjectFilePath) { | |
llvm-objdump --disassemble $ObjectFilePath | ` | |
Select-Object -Skip 4 | ` | |
Out-File "$ObjectFilePath.asm" | |
return "$ObjectFilePath.asm" | |
} | |
$ObjectFile = Resolve-Path $_.FullName -Relative | |
$OldObjectFileDump = DumpObject "$using:OldObjectFilesDir\$ObjectFile" | |
$NewObjectFileDump = DumpObject "$using:NewObjectFilesDir\$ObjectFile" | |
git diff --no-index $OldObjectFileDump $NewObjectFileDump | |
} | |
Set-Location $BuildDir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment