Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Make PDB builds reproducible #2

Open
jasonwhite opened this issue Aug 2, 2016 · 5 comments
Open

Make PDB builds reproducible #2

jasonwhite opened this issue Aug 2, 2016 · 5 comments
Assignees

Comments

@jasonwhite
Copy link
Owner

Currently, PDB files are not patched to remove non-determinism.

This presents a larger challenge than just patching the PE file alone, because:

  1. The PDB file format is not well documented.
  2. The size of the PDB file seems to change with every build. Thus, we cannot use a memory map to make modifications to the PDB file as we will need to remove data.

References:

  1. https://github.com/Microsoft/microsoft-pdb
@jasonwhite jasonwhite self-assigned this Aug 2, 2016
@jasonwhite
Copy link
Owner Author

Fixed with f4241a1.

@l0calh05t
Copy link

l0calh05t commented Sep 6, 2018

I believe this issue has to be reopened, because even the most trivial program (empty main) produces non-deterministic PDBs (with VS2015):

@setlocal
@echo off

call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64 || exit /b 1
cl
echo.
ducible --version
echo.

echo int main(int, char**) { return 0; }> main.cpp

for %%i in (1,2) do (
	cl /nologo /Zi main.cpp /link /incremental:no >NUL || exit /b 1
	ducible main.exe main.pdb >NUL || exit /b 1
	move main.exe main.%%i.exe >NUL || exit /b 1
	move main.pdb main.%%i.pdb >NUL || exit /b 1
	del vc140.pdb || exit /b 1
	del main.obj || exit /b 1
)

fc main.1.exe main.2.exe >NUL 2>&1 && echo EXE identical || ( echo EXE different && exit /b 1)
fc main.1.pdb main.2.pdb >NUL 2>&1 && echo PDB identical || ( echo PDB different && exit /b 1)

Results in the following output:

Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

ducible version v1.2.1-2535ce5

EXE identical
PDB different

@jasonwhite jasonwhite reopened this Sep 6, 2018
@jasonwhite
Copy link
Owner Author

@l0calh05t I can reproduce that problem with the test suite with VS2017 (I don't have VS2015 installed currently). I guess getting reproducible PDBs is a moving target. It looks like the /Zi flag is causing this. Using /Z7 instead appears to be fine.

I probably won't have time to dig into this in the near future, but from glancing at the hexdump it looks like there are some source file paths in the PDB that aren't in sorted order. If anyone else has the gusto to fix this, I'll happily take a PR for it. 😉

@l0calh05t
Copy link

I‘m fairly certain that I also tried /Z7 to no avail. I’ll retest tomorrow.

@l0calh05t
Copy link

l0calh05t commented Sep 7, 2018

I just re-checked. And /Z7 also results in differing PDBs with VS2015. However, if I compare the pdbdump --verbose outputs of the two builds they are identical for /Z7 even though the binaries differ. This isn't the case for /Zi where both binary and dump differ.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants