Build path variation and __FILE__
satta at debian.org
Tue Sep 6 21:09:31 UTC 2016
I’d like to contribute to the build path discussion as well with a few observations I made when trying to fix reproducibility problems related to that in my packages. In addition to the problem already raised by Ximin concerning upstream storing CFLAGS in artifacts, most of the issues I noticed were related to build path capture via __FILE__.
__FILE__ is typically set to the exact source file path passed to the compiler, and in quite common cases where it is used in debugging statements etc. it is included as a string in the final binaries’ rodata section. So if upstream’s build system passes absolute source paths and __FILE__ is used, the binaries will be different even with -fdebug-prefix-map set :(
This problem particularly shows in build systems that run builds outside the source tree like CMake, which makes use of absolute paths a lot. There is apparently an option CMAKE_USE_RELATIVE_PATHS but it is apparently unreliable  and did not help in a single case for me.
I’ll take a look at the list of reproducible packages build-depending on CMake  later and try to learn something.
Any ideas what to do about that in general? I can imagine that patch complexity would be increased a lot by trying to address this solely at the build system level, which also probably isn't always possible. One might think of a solution closer to the compiler, such as:
a) Introducing something like -ffile-prefix-map similarly to -fdebug-prefix-map to address this issue. There is already an unreviewed patch for gcc submitted by an unrelated party  and I could try and raise awareness for this bug with the GCC devs. However, this option would be incompatible with old compilers and hence probably not easily enabled in the default dpkg-buildflags. IMHO it would be a good thing to have though.
b) Using something like libelf or bin_replace_string  to remove or replace the build path in the resulting binary, e.g. as part of strip-nondeterminism. Not a permanent solution but would do the job.
c) Any other ideas?
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 455 bytes
Desc: Message signed with OpenPGP using GPGMail
More information about the Reproducible-builds