Stop encoding absolute paths in symbols

GCC & Clang encode the current working directory into the symbol files.
Even if the binaries are stripped before being installed, the build-id
hash will be different. This means that two different checkouts will
produce different installed binaries, even if the sources are identical.

To prevent this, set PWD=/proc/self/cwd, so that it replaces the
absolute path with the static path /proc/self/cwd. With GCC, use
-fdebug-prefix-map to remove that static path. Our clang does not yet
support this flag, but it was merged in r250094.

This does change the behavior when using gdb -- you now need to be in
$ANDROID_BUILD_TOP before gdb will load the sources.

Bug: 24204119
Change-Id: I792d65b042b7a3fdc78d567c5a6e93cdf0141b9b
diff --git a/core/config.mk b/core/config.mk
index 1db3d7a..2a16680 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -177,6 +177,19 @@
 FIND_LEAVES_EXCLUDES := $(addprefix --prune=, $(OUT_DIR) $(SCAN_EXCLUDE_DIRS) .repo .git)
 
 # ---------------------------------------------------------------
+# We run gcc/clang with PWD=/proc/self/cwd to remove the $TOP
+# from the debug output. That way two builds in two different
+# directories will create the same output.
+# /proc doesn't exist on Darwin.
+ifeq ($(HOST_OS),linux)
+RELATIVE_PWD := PWD=/proc/self/cwd
+# Remove this useless prefix from the debug output.
+COMMON_GLOBAL_CFLAGS += -fdebug-prefix-map=/proc/self/cwd=
+else
+RELATIVE_PWD :=
+endif
+
+# ---------------------------------------------------------------
 # Allow the C/C++ macros __DATE__ and __TIME__ to be set to the
 # build date and time, so that a build may be repeated.
 # Write the date and time to a file so that the command line