12.6 Build Reproducibility

The EDK II build system is designed to provide functional reproducibility, not necessarily binary reproducibility. For example, when building the DEBUG targets, the absolute path and file name for a PDB file is inserted into PE32 file. Building from different directory trees will result in different directory paths, and the PE32 files will not be identical bit for bit, but they will be identical in functionality.

Using the RELEASE build target will only result in identical files if there are no changes whatsoever to the source files. The EDK II debug libraries insert DebugAssert statements into binaries. These statements record line numbers from the source files. This means that inserting a blank line or a comment anywhere in a module can yield multiple different line numbers from the DebugAssert statements.

Fortunately, a special compiler macro, MDEPKG_NDEBUG, has been in the EDK II code base debug libraries. When this macro is defined, the DebugAssert statements are stripped completely removed from the resultant binary. So using a RELEASE and adding

the MDEPKG_NDEBUG macro will allow generating binaries that are identical, regardless of the directories or changes to comments in the source files.

The best method for adding this macro is again, using the [BuildOptions] section of the DSC file. The following is an example that is valid for all tool chains with a family set to MSFT in the tools_def.txt file.

Example

[BuildOptions]
MSFT:RELEASE_*_*_CC_FLAGS = -D MDEPKG_NDEBUG

Using this flag is also the only way to turn off DebugAssert statements when disabling all optimizations using the /0d flag for Microsoft* compilers.