Skip to content

Commit 5b070c0

Browse files
authored
pythongh-95973: Add a new --with-dsymutil option to link debug information in macOS (pythonGH-95974)
Automerge-Triggered-By: GH:pablogsal
1 parent 43a6dea commit 5b070c0

File tree

5 files changed

+160
-8
lines changed

5 files changed

+160
-8
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
*.cover
66
*.iml
77
*.o
8+
*.lto
89
*.a
910
*.so
1011
*.so.*
1112
*.dylib
13+
*.dSYM
1214
*.dll
1315
*.wasm
1416
*.orig

Diff for: Makefile.pre.in

+43-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ DTRACE= @DTRACE@
5454
DFLAGS= @DFLAGS@
5555
DTRACE_HEADERS= @DTRACE_HEADERS@
5656
DTRACE_OBJS= @DTRACE_OBJS@
57+
DSYMUTIL= @DSYMUTIL@
58+
DSYMUTIL_PATH= @DSYMUTIL_PATH@
5759

5860
GNULD= @GNULD@
5961

@@ -576,7 +578,7 @@ LIBEXPAT_HEADERS= \
576578
# Default target
577579
all: @DEF_MAKE_ALL_RULE@
578580
build_all: check-clean-src $(BUILDPYTHON) platform sharedmods \
579-
gdbhooks Programs/_testembed scripts checksharedmods
581+
gdbhooks Programs/_testembed scripts checksharedmods rundsymutil
580582
build_wasm: check-clean-src $(BUILDPYTHON) platform sharedmods \
581583
python-config checksharedmods
582584

@@ -905,6 +907,22 @@ sharedmods: $(SHAREDMODS) pybuilddir.txt
905907
checksharedmods: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
906908
@$(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/scripts/check_extension_modules.py
907909

910+
rundsymutil: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
911+
@if [ ! -z $(DSYMUTIL) ] ; then \
912+
echo $(DSYMUTIL_PATH) $(BUILDPYTHON); \
913+
$(DSYMUTIL_PATH) $(BUILDPYTHON); \
914+
if test -f $(LDLIBRARY); then \
915+
echo $(DSYMUTIL_PATH) $(LDLIBRARY); \
916+
$(DSYMUTIL_PATH) $(LDLIBRARY); \
917+
fi; \
918+
for mod in X $(SHAREDMODS); do \
919+
if test $$mod != X; then \
920+
echo $(DSYMUTIL_PATH) $$mod; \
921+
$(DSYMUTIL_PATH) $$mod; \
922+
fi; \
923+
done \
924+
fi
925+
908926
Modules/Setup.local:
909927
@# Create empty Setup.local when file was deleted by user
910928
echo "# Edit this file for local setup changes" > $@
@@ -1755,9 +1773,14 @@ sharedinstall: $(DESTSHARED) all
17551773
if test $$i != X; then \
17561774
echo $(INSTALL_SHARED) $$i $(DESTSHARED)/`basename $$i`; \
17571775
$(INSTALL_SHARED) $$i $(DESTDIR)$(DESTSHARED)/`basename $$i`; \
1776+
if test -d "$$i.dSYM"; then \
1777+
echo $(DSYMUTIL_PATH) $(DESTDIR)$(DESTSHARED)/`basename $$i`; \
1778+
$(DSYMUTIL_PATH) $(DESTDIR)$(DESTSHARED)/`basename $$i`; \
1779+
fi; \
17581780
fi; \
17591781
done
17601782

1783+
17611784
$(DESTSHARED):
17621785
@for i in $(DESTDIRS); \
17631786
do \
@@ -1818,6 +1841,23 @@ altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@
18181841
-output $(DESTDIR)$(BINDIR)/python$(VERSION)-intel64$(EXE) \
18191842
$(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE); \
18201843
fi
1844+
# Install macOS debug information (if available)
1845+
if test -d "$(BUILDPYTHON).dSYM"; then \
1846+
echo $(DSYMUTIL_PATH) $(DESTDIR)$(BINDIR)/python$(LDVERSION)$(EXE); \
1847+
$(DSYMUTIL_PATH) $(DESTDIR)$(BINDIR)/python$(LDVERSION)$(EXE); \
1848+
fi
1849+
if test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \
1850+
if test -d "$(LDLIBRARY).dSYM"; then \
1851+
echo $(DSYMUTIL_PATH) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \
1852+
$(DSYMUTIL_PATH) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \
1853+
fi \
1854+
else \
1855+
if test -d "$(LDLIBRARY).dSYM"; then \
1856+
echo $(DSYMUTIL_PATH) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(INSTSONAME); \
1857+
$(DSYMUTIL_PATH) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(INSTSONAME); \
1858+
fi \
1859+
fi
1860+
18211861

18221862
bininstall: altbininstall
18231863
if test ! -d $(DESTDIR)$(LIBPC); then \
@@ -2392,6 +2432,7 @@ clean-retain-profile: pycremoval
23922432
find . -name '*.[oa]' -exec rm -f {} ';'
23932433
find . -name '*.s[ol]' -exec rm -f {} ';'
23942434
find . -name '*.so.[0-9]*.[0-9]*' -exec rm -f {} ';'
2435+
find . -name '*.lto' -exec rm -f {} ';'
23952436
find . -name '*.wasm' -exec rm -f {} ';'
23962437
find . -name '*.lst' -exec rm -f {} ';'
23972438
find build -name 'fficonfig.h' -exec rm -f {} ';' || true
@@ -2508,7 +2549,7 @@ Python/thread.o: @THREADHEADERS@ $(srcdir)/Python/condvar.h
25082549

25092550
# Declare targets that aren't real files
25102551
.PHONY: all build_all build_wasm check-clean-src
2511-
.PHONY: sharedmods checksharedmods test quicktest
2552+
.PHONY: sharedmods checksharedmods test quicktest rundsymutil
25122553
.PHONY: install altinstall sharedinstall bininstall altbininstall
25132554
.PHONY: maninstall libinstall inclinstall libainstall
25142555
.PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add a new ``--with-dsymutil`` configure option to to link debug information
2+
in macOS. Patch by Pablo Galindo.

Diff for: configure

+83-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: configure.ac

+30-3
Original file line numberDiff line numberDiff line change
@@ -1863,10 +1863,10 @@ if test "$Py_LTO" = 'true' ; then
18631863
# Any changes made here should be reflected in the GCC+Darwin case below
18641864
if test $Py_LTO_POLICY = default
18651865
then
1866-
LTOFLAGS="-flto -Wl,-export_dynamic"
1866+
LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
18671867
LTOCFLAGS="-flto"
18681868
else
1869-
LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic"
1869+
LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
18701870
LTOCFLAGS="-flto=${Py_LTO_POLICY}"
18711871
fi
18721872
;;
@@ -1896,7 +1896,7 @@ if test "$Py_LTO" = 'true' ; then
18961896
LDFLAGS_NOLTO="-fno-lto"
18971897
case $ac_sys_system in
18981898
Darwin*)
1899-
LTOFLAGS="-flto -Wl,-export_dynamic"
1899+
LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
19001900
LTOCFLAGS="-flto"
19011901
;;
19021902
*)
@@ -3053,6 +3053,33 @@ else
30533053
AC_MSG_RESULT(no)
30543054
fi
30553055

3056+
# Check for --with-dsymutil
3057+
AC_SUBST(DSYMUTIL)
3058+
AC_SUBST(DSYMUTIL_PATH)
3059+
DSYMUTIL=
3060+
DSYMUTIL_PATH=
3061+
AC_MSG_CHECKING(for --with-dsymutil)
3062+
AC_ARG_WITH(dsymutil,
3063+
AS_HELP_STRING([--with-dsymutil], [link debug information into final executable with dsymutil in macOS (default is no)]),
3064+
[
3065+
if test "$withval" != no
3066+
then
3067+
if test "$MACHDEP" != "darwin"; then
3068+
AC_MSG_ERROR([dsymutil debug linking is only available in macOS.])
3069+
fi
3070+
AC_MSG_RESULT(yes);
3071+
DSYMUTIL='true'
3072+
else AC_MSG_RESULT(no); DSYMUTIL=
3073+
fi],
3074+
[AC_MSG_RESULT(no)])
3075+
3076+
if test "$DSYMUTIL"; then
3077+
AC_PATH_PROG(DSYMUTIL_PATH, [dsymutil], [not found])
3078+
if test "$DSYMUTIL_PATH" = "not found"; then
3079+
AC_MSG_ERROR([dsymutil command not found on \$PATH])
3080+
fi
3081+
fi
3082+
30563083
AC_MSG_CHECKING(for dyld)
30573084
case $ac_sys_system/$ac_sys_release in
30583085
Darwin/*)

0 commit comments

Comments
 (0)