From 6a66a887baadc9eb3d0d60e26f748b8453e27a02 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Wed, 14 Oct 2015 16:44:53 -0700 Subject: [PATCH] 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 --- core/clang/config.mk | 3 ++- core/config.mk | 13 +++++++++++++ core/definitions.mk | 8 ++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/core/clang/config.mk b/core/clang/config.mk index 68875222c..cd91c6c82 100644 --- a/core/clang/config.mk +++ b/core/clang/config.mk @@ -78,7 +78,8 @@ CLANG_CONFIG_UNKNOWN_CFLAGS := \ -Wno-unused-local-typedefs \ -Wunused-but-set-parameter \ -Wunused-but-set-variable \ - -fdiagnostics-color + -fdiagnostics-color \ + -fdebug-prefix-map=/proc/self/cwd= # Clang flags for all host rules CLANG_CONFIG_HOST_EXTRA_ASFLAGS := diff --git a/core/config.mk b/core/config.mk index 1db3d7ae4..2a16680e5 100644 --- a/core/config.mk +++ b/core/config.mk @@ -176,6 +176,19 @@ include $(BUILD_SYSTEM)/envsetup.mk # See envsetup.mk for a description of SCAN_EXCLUDE_DIRS 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. diff --git a/core/definitions.mk b/core/definitions.mk index c179706bc..3d9b30120 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -1049,7 +1049,7 @@ endef define transform-cpp-to-o @echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<" @mkdir -p $(dir $@) -$(hide) $(PRIVATE_CXX) \ +$(hide) $(RELATIVE_PWD) $(PRIVATE_CXX) \ $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \ $(addprefix -isystem ,\ @@ -1081,7 +1081,7 @@ endef # $(1): extra flags define transform-c-or-s-to-o-no-deps @mkdir -p $(dir $@) -$(hide) $(PRIVATE_CC) \ +$(hide) $(RELATIVE_PWD) $(PRIVATE_CC) \ $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \ $(addprefix -isystem ,\ @@ -1156,7 +1156,7 @@ endef define transform-host-cpp-to-o @echo "$($(PRIVATE_PREFIX)DISPLAY) C++: $(PRIVATE_MODULE) <= $<" @mkdir -p $(dir $@) -$(hide) $(PRIVATE_CXX) \ +$(hide) $(RELATIVE_PWD) $(PRIVATE_CXX) \ $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \ $(addprefix -isystem ,\ @@ -1186,7 +1186,7 @@ endef # $(1): extra flags define transform-host-c-or-s-to-o-no-deps @mkdir -p $(dir $@) -$(hide) $(PRIVATE_CC) \ +$(hide) $(RELATIVE_PWD) $(PRIVATE_CC) \ $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \ $(addprefix -isystem ,\