Help rewriting the __FILE__ macro

Hi folks,

I'm trying to get the FreeBSD source tree to produce two identical binaries for two builds with the same source revision. Currently, this is not the case, and one of the reasons is that the value of __FILE__ is sometimes stored in the binary. This is a problem if the source location or location of temporary object files is not the same between the two builds.

Ideally, what I want is for __FILE__ to expand to a path relative to the location of the root of my source tree instead of an absolute path on the file system, i.e. src/foo/bar.c instead of /home/erik/freebsd/head/src/foo/bar.c

This has been implemented as an "-iremap=src:dst" option for GCC (47047 – Support for path translation in __FILE__) and applied to GCC in NetBSD (CVS commit: src/gnu) by Joerg Sonnenberger. 'src' is meant to be the prefix and 'dst' the replacement.

I've made an attempt to add a similar flag for Clang, but I'm a C++ and Clang novice and got lost somewhere between the driver accepting the option and the preprocessor rewriting the __FILE__ macro. I'm wondering if someone could lend me a hand completing the attached patch. Thanks!

Thanks,
Erik Cederstrand

Index: llvm/tools/clang/include/clang/Frontend/PreprocessorOptions.h

One important note here. The GCC patch is kind of the 80% solution,
because I couldn't easily figure out how to get the rest of the desired
behavior. It works well for non-debug builds, but for clang, it would be
much nicer to consistently apply the transformations to other path
consumers.

Joerg