Bug 1474024 - Avoid LTO breaking debug info on macOS builds. r=froydnj draft
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 10 Jul 2018 07:09:24 +0900
changeset 818964 c72306f45940ff1aa174a0fc4d73983902cff538
parent 818682 2ed1506d1dc7db3d70a3feed95f1456bce05bbee
child 819075 a6635f206392c19ba41ba58aa3630b03a441f6af
push id116406
push userbmo:mh+mozilla@glandium.org
push dateMon, 16 Jul 2018 21:18:47 +0000
reviewersfroydnj
bugs1474024
milestone63.0a1
Bug 1474024 - Avoid LTO breaking debug info on macOS builds. r=froydnj
config/config.mk
--- a/config/config.mk
+++ b/config/config.mk
@@ -208,16 +208,36 @@ COMPILE_CMMFLAGS = $(OS_COMPILE_CMMFLAGS
 ASFLAGS = $(COMPUTED_ASFLAGS)
 SFLAGS = $(COMPUTED_SFLAGS)
 
 HOST_CFLAGS = $(COMPUTED_HOST_CFLAGS) $(_DEPEND_CFLAGS)
 HOST_CXXFLAGS = $(COMPUTED_HOST_CXXFLAGS) $(_DEPEND_CFLAGS)
 HOST_C_LDFLAGS = $(COMPUTED_HOST_C_LDFLAGS)
 HOST_CXX_LDFLAGS = $(COMPUTED_HOST_CXX_LDFLAGS)
 
+ifdef MOZ_LTO
+ifeq (Darwin,$(OS_TARGET))
+# When linking on macOS, debug info is not linked along with the final binary,
+# and the dwarf data stays in object files until they are "linked" with the
+# dsymutil tool.
+# With LTO, object files are temporary, and are not kept around, which
+# means there's no object file for dsymutil to do its job. Consequently,
+# there is no debug info for LTOed compilation units.
+# The macOS linker has however an option to explicitly keep those object
+# files, which dsymutil will then find.
+# The catch is that the linker uses sequential numbers for those object
+# files, and doesn't avoid conflicts from multiple linkers running at
+# the same time. So in directories with multiple binaries, object files
+# from the first linked binaries would be overwritten by those of the
+# last linked binary. So we use a subdirectory containing the name of the
+# linked binary.
+LDFLAGS += -Wl,-object_path_lto,$@.lto.o/
+endif
+endif
+
 # We only add color flags if neither the flag to disable color
 # (e.g. "-fno-color-diagnostics" nor a flag to control color
 # (e.g. "-fcolor-diagnostics=never") is present.
 define colorize_flags
 ifeq (,$(filter $(COLOR_CFLAGS:-f%=-fno-%),$$(1))$(findstring $(COLOR_CFLAGS),$$(1)))
 $(1) += $(COLOR_CFLAGS)
 endif
 endef