Deterministic builds with clang and lld describes several degrees of build determinism. Here is the description of local determinism:
Like incremental basic determinism, but builds are also independent of the name of the build directory. Builds of the same source code on the same machine produce exactly the same output every time, independent of the location of the source checkout directory or the build directory.
This is often a stretch goal for a build system. For example, many autotools builds use absolute paths. CMake's Ninja generator uses absolute paths (https://gitlab.kitware.com/cmake/cmake/-/issues/13894).
Options discouraged by the post
useful for such build systems.
This option overrides the compilation directory in DWARF.
-fdebug-compilation-dir=. is commonly used to set the
compilation directory to the special directory
input files are specified as relative paths,
% clang -c -g -fdebug-compilation-dir=. ../src/a.c
The environment variable
PWD, if exists and is an
absolute path, is used by GCC and Clang as a fallback when
-fdebug-compilation-dir= is unspecified. Therefore, we can
PWD=/proc/self/cwd clang ....
See Debug info path remapping for the original GCC patch. See https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html for the documentation.
Generated debug information for assembly source
When an assembler source file has no debug
.file directive, GNU assembler synthesizes a
DW_TAG_compile_unit entry. This entry is generated when an
assembler source file has at least one
.debug_info section. The entry is mainly used to
provide address ranges for the file.
% cat a.s
LLVM integrated assembler has a similar behavior. See https://github.com/llvm/llvm-project/issues/37398 for the original feature request.
-fdebug-prefix-map did not work for generated
DWARF v5 debug information. There were two issues.