[Python-checkins] gh-95973: Add a new --with-dsymutil option to link debug information in macOS (GH-95974)

miss-islington webhook-mailer at python.org
Fri Aug 26 20:49:59 EDT 2022


https://github.com/python/cpython/commit/5b070c0d40b0c7dd83b8c4eaa44812e9d2af14f9
commit: 5b070c0d40b0c7dd83b8c4eaa44812e9d2af14f9
branch: main
author: Pablo Galindo Salgado <Pablogsal at gmail.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-08-26T17:49:41-07:00
summary:

gh-95973: Add a new --with-dsymutil option to link debug information in macOS (GH-95974)



Automerge-Triggered-By: GH:pablogsal

files:
A Misc/NEWS.d/next/Build/2022-08-15-10-56-07.gh-issue-95973.Bsswsc.rst
M .gitignore
M Makefile.pre.in
M configure
M configure.ac

diff --git a/.gitignore b/.gitignore
index 0ddfd717d737..924c136ba9aa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,10 +5,12 @@
 *.cover
 *.iml
 *.o
+*.lto
 *.a
 *.so
 *.so.*
 *.dylib
+*.dSYM
 *.dll
 *.wasm
 *.orig
diff --git a/Makefile.pre.in b/Makefile.pre.in
index af203705d38e..94ddfa4b1bed 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -54,6 +54,8 @@ DTRACE=         @DTRACE@
 DFLAGS=         @DFLAGS@
 DTRACE_HEADERS= @DTRACE_HEADERS@
 DTRACE_OBJS=    @DTRACE_OBJS@
+DSYMUTIL=       @DSYMUTIL@
+DSYMUTIL_PATH=  @DSYMUTIL_PATH@
 
 GNULD=		@GNULD@
 
@@ -576,7 +578,7 @@ LIBEXPAT_HEADERS= \
 # Default target
 all:		@DEF_MAKE_ALL_RULE@
 build_all:	check-clean-src $(BUILDPYTHON) platform sharedmods \
-		gdbhooks Programs/_testembed scripts checksharedmods
+		gdbhooks Programs/_testembed scripts checksharedmods rundsymutil
 build_wasm: check-clean-src $(BUILDPYTHON) platform sharedmods \
 		python-config checksharedmods
 
@@ -905,6 +907,22 @@ sharedmods: $(SHAREDMODS) pybuilddir.txt
 checksharedmods: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
 	@$(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/scripts/check_extension_modules.py
 
+rundsymutil: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
+	@if [ ! -z $(DSYMUTIL) ] ; then \
+		echo $(DSYMUTIL_PATH) $(BUILDPYTHON); \
+		$(DSYMUTIL_PATH) $(BUILDPYTHON); \
+		if test -f $(LDLIBRARY); then \
+			echo $(DSYMUTIL_PATH) $(LDLIBRARY); \
+			$(DSYMUTIL_PATH) $(LDLIBRARY); \
+		fi; \
+		for mod in X $(SHAREDMODS); do \
+			if test $$mod != X; then \
+				echo $(DSYMUTIL_PATH) $$mod; \
+				$(DSYMUTIL_PATH) $$mod; \
+			fi; \
+		done \
+	fi
+
 Modules/Setup.local:
 	@# Create empty Setup.local when file was deleted by user
 	echo "# Edit this file for local setup changes" > $@
@@ -1755,9 +1773,14 @@ sharedinstall: $(DESTSHARED) all
 		  if test $$i != X; then \
 		    echo $(INSTALL_SHARED) $$i $(DESTSHARED)/`basename $$i`; \
 		    $(INSTALL_SHARED) $$i $(DESTDIR)$(DESTSHARED)/`basename $$i`; \
+			if test -d "$$i.dSYM"; then \
+				echo $(DSYMUTIL_PATH) $(DESTDIR)$(DESTSHARED)/`basename $$i`; \
+				$(DSYMUTIL_PATH) $(DESTDIR)$(DESTSHARED)/`basename $$i`; \
+			fi; \
 		  fi; \
 		done
 
+
 $(DESTSHARED):
 		@for i in $(DESTDIRS); \
 		do \
@@ -1818,6 +1841,23 @@ altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@
 			-output $(DESTDIR)$(BINDIR)/python$(VERSION)-intel64$(EXE) \
 			$(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE); \
 	fi
+	# Install macOS debug information (if available)
+	if test -d "$(BUILDPYTHON).dSYM"; then \
+		echo $(DSYMUTIL_PATH) $(DESTDIR)$(BINDIR)/python$(LDVERSION)$(EXE); \
+		$(DSYMUTIL_PATH) $(DESTDIR)$(BINDIR)/python$(LDVERSION)$(EXE); \
+	fi
+	if test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \
+		if test -d "$(LDLIBRARY).dSYM"; then \
+			echo $(DSYMUTIL_PATH) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \
+			$(DSYMUTIL_PATH) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \
+		fi \
+	else \
+		if test -d "$(LDLIBRARY).dSYM"; then \
+			echo $(DSYMUTIL_PATH) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(INSTSONAME); \
+      $(DSYMUTIL_PATH) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(INSTSONAME); \
+		fi \
+	fi
+	
 
 bininstall: altbininstall
 	if test ! -d $(DESTDIR)$(LIBPC); then \
@@ -2392,6 +2432,7 @@ clean-retain-profile: pycremoval
 	find . -name '*.[oa]' -exec rm -f {} ';'
 	find . -name '*.s[ol]' -exec rm -f {} ';'
 	find . -name '*.so.[0-9]*.[0-9]*' -exec rm -f {} ';'
+	find . -name '*.lto' -exec rm -f {} ';'
 	find . -name '*.wasm' -exec rm -f {} ';'
 	find . -name '*.lst' -exec rm -f {} ';'
 	find build -name 'fficonfig.h' -exec rm -f {} ';' || true
@@ -2508,7 +2549,7 @@ Python/thread.o: @THREADHEADERS@ $(srcdir)/Python/condvar.h
 
 # Declare targets that aren't real files
 .PHONY: all build_all build_wasm check-clean-src
-.PHONY: sharedmods checksharedmods test quicktest
+.PHONY: sharedmods checksharedmods test quicktest rundsymutil
 .PHONY: install altinstall sharedinstall bininstall altbininstall
 .PHONY: maninstall libinstall inclinstall libainstall
 .PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
diff --git a/Misc/NEWS.d/next/Build/2022-08-15-10-56-07.gh-issue-95973.Bsswsc.rst b/Misc/NEWS.d/next/Build/2022-08-15-10-56-07.gh-issue-95973.Bsswsc.rst
new file mode 100644
index 000000000000..d03bc5205ead
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2022-08-15-10-56-07.gh-issue-95973.Bsswsc.rst
@@ -0,0 +1,2 @@
+Add a new ``--with-dsymutil`` configure option to to link debug information
+in macOS. Patch by Pablo Galindo.
diff --git a/configure b/configure
index 1801f806ae13..ee2eabb13c07 100755
--- a/configure
+++ b/configure
@@ -869,6 +869,8 @@ BLDSHARED
 LDCXXSHARED
 LDSHARED
 SHLIB_SUFFIX
+DSYMUTIL_PATH
+DSYMUTIL
 LIBTOOL_CRUFT
 OTHER_LIBTOOL_OPT
 UNIVERSAL_ARCH_FLAGS
@@ -1053,6 +1055,7 @@ with_assertions
 enable_optimizations
 with_lto
 enable_bolt
+with_dsymutil
 with_address_sanitizer
 with_memory_sanitizer
 with_undefined_behavior_sanitizer
@@ -1824,6 +1827,8 @@ Optional Packages:
   --with-lto=[full|thin|no|yes]
                           enable Link-Time-Optimization in any build (default
                           is no)
+  --with-dsymutil         link debug information into final executable with
+                          dsymutil in macOS (default is no)
   --with-address-sanitizer
                           enable AddressSanitizer memory error detector,
                           'asan' (default is no)
@@ -7831,10 +7836,10 @@ $as_echo "$as_me: llvm-ar found via xcrun: ${LLVM_AR}" >&6;}
           # Any changes made here should be reflected in the GCC+Darwin case below
           if test $Py_LTO_POLICY = default
           then
-            LTOFLAGS="-flto -Wl,-export_dynamic"
+            LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
             LTOCFLAGS="-flto"
           else
-            LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic"
+            LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
             LTOCFLAGS="-flto=${Py_LTO_POLICY}"
           fi
           ;;
@@ -7863,7 +7868,7 @@ $as_echo "$as_me: llvm-ar found via xcrun: ${LLVM_AR}" >&6;}
             LDFLAGS_NOLTO="-fno-lto"
       case $ac_sys_system in
         Darwin*)
-          LTOFLAGS="-flto -Wl,-export_dynamic"
+          LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
           LTOCFLAGS="-flto"
           ;;
         *)
@@ -10974,6 +10979,81 @@ else
 $as_echo "no" >&6; }
 fi
 
+# Check for --with-dsymutil
+
+
+DSYMUTIL=
+DSYMUTIL_PATH=
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-dsymutil" >&5
+$as_echo_n "checking for --with-dsymutil... " >&6; }
+
+# Check whether --with-dsymutil was given.
+if test "${with_dsymutil+set}" = set; then :
+  withval=$with_dsymutil;
+if test "$withval" != no
+then
+  if test "$MACHDEP" != "darwin"; then
+    as_fn_error $? "dsymutil debug linking is only available in macOS." "$LINENO" 5
+  fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; };
+  DSYMUTIL='true'
+else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }; DSYMUTIL=
+fi
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+if test "$DSYMUTIL"; then
+  # Extract the first word of "dsymutil", so it can be a program name with args.
+set dummy dsymutil; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_DSYMUTIL_PATH+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $DSYMUTIL_PATH in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DSYMUTIL_PATH="$DSYMUTIL_PATH" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_DSYMUTIL_PATH="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_path_DSYMUTIL_PATH" && ac_cv_path_DSYMUTIL_PATH="not found"
+  ;;
+esac
+fi
+DSYMUTIL_PATH=$ac_cv_path_DSYMUTIL_PATH
+if test -n "$DSYMUTIL_PATH"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL_PATH" >&5
+$as_echo "$DSYMUTIL_PATH" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  if test "$DSYMUTIL_PATH" = "not found"; then
+      as_fn_error $? "dsymutil command not found on \$PATH" "$LINENO" 5
+  fi
+fi
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dyld" >&5
 $as_echo_n "checking for dyld... " >&6; }
 case $ac_sys_system/$ac_sys_release in
diff --git a/configure.ac b/configure.ac
index bb9fec07242f..02e5d6745712 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1863,10 +1863,10 @@ if test "$Py_LTO" = 'true' ; then
           # Any changes made here should be reflected in the GCC+Darwin case below
           if test $Py_LTO_POLICY = default
           then
-            LTOFLAGS="-flto -Wl,-export_dynamic"
+            LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
             LTOCFLAGS="-flto"
           else
-            LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic"
+            LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
             LTOCFLAGS="-flto=${Py_LTO_POLICY}"
           fi
           ;;
@@ -1896,7 +1896,7 @@ if test "$Py_LTO" = 'true' ; then
       LDFLAGS_NOLTO="-fno-lto"
       case $ac_sys_system in
         Darwin*)
-          LTOFLAGS="-flto -Wl,-export_dynamic"
+          LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
           LTOCFLAGS="-flto"
           ;;
         *)
@@ -3053,6 +3053,33 @@ else
 	AC_MSG_RESULT(no)
 fi
 
+# Check for --with-dsymutil
+AC_SUBST(DSYMUTIL)
+AC_SUBST(DSYMUTIL_PATH)
+DSYMUTIL=
+DSYMUTIL_PATH=
+AC_MSG_CHECKING(for --with-dsymutil)
+AC_ARG_WITH(dsymutil,
+            AS_HELP_STRING([--with-dsymutil], [link debug information into final executable with dsymutil in macOS  (default is no)]),
+[
+if test "$withval" != no
+then
+  if test "$MACHDEP" != "darwin"; then
+    AC_MSG_ERROR([dsymutil debug linking is only available in macOS.])
+  fi
+ AC_MSG_RESULT(yes);
+  DSYMUTIL='true'
+else AC_MSG_RESULT(no); DSYMUTIL=
+fi],
+[AC_MSG_RESULT(no)])
+
+if test "$DSYMUTIL"; then
+  AC_PATH_PROG(DSYMUTIL_PATH, [dsymutil], [not found])
+  if test "$DSYMUTIL_PATH" = "not found"; then
+      AC_MSG_ERROR([dsymutil command not found on \$PATH])
+  fi
+fi
+
 AC_MSG_CHECKING(for dyld)
 case $ac_sys_system/$ac_sys_release in
   Darwin/*)



More information about the Python-checkins mailing list