Skip to content

Commit

Permalink
test(trim-paths): verify SO symbols didn't get remapped
Browse files Browse the repository at this point in the history
When `--remap-path-scope=object` is specified, user expect that there is
no local path embedded in final executables. Under `object` scope, the
current implementation only remap debug symbols if debug info is
splitted into its own file. In other words, when
`split-debuginfo=packed|unpacked` is set, rustc assumes there is no
embedded path in the final executable needing to be remapped.

However, this doesn't work on macOS. On macOS, `SO` symbols are embedded
in binary executables and libraries regardless a split-debuginfo file is
built. Each `SO` symbol contains a path to the root source file of a
debug info compile unit.

This commit demonstrates the case, and hope there is a fix soon.
  • Loading branch information
weihanglo committed Dec 5, 2023
1 parent 8a7b203 commit 3a9c9fe
Showing 1 changed file with 59 additions and 11 deletions.
70 changes: 59 additions & 11 deletions tests/run-make/split-debuginfo/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ignore-cross-compile
include ../tools.mk

export HERE := $(shell pwd)

all: off packed unpacked

ifeq ($(UNAME),Darwin)
Expand All @@ -11,23 +13,69 @@ off:
[ ! -d $(TMPDIR)/foo.dSYM ]

# Packed by default, but only if debuginfo is requested
packed:
rm -rf $(TMPDIR)/*.dSYM
$(RUSTC) foo.rs
[ ! -d $(TMPDIR)/foo.dSYM ]
rm -rf $(TMPDIR)/*.dSYM
$(RUSTC) foo.rs -g
packed: packed-remapped-scope packed-remapped-wrong-scope

# - Debuginfo in binary file
# - file paths from `SO` (source files) and `OSO` (object files) should be remapped
packed-remapped-scope:
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=packed -C debuginfo=2 \
--remap-path-prefix $(TMPDIR)=/a \
--remap-path-prefix $(HERE)=/b \
-Z remap-path-scope=object foo.rs -g
ls $(TMPDIR)/*.o && exit 1 || exit 0
[ -d $(TMPDIR)/foo.dSYM ]
rm -rf $(TMPDIR)/*.dSYM
$(RUSTC) foo.rs -g -C split-debuginfo=packed
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | grep $(HERE) || exit 1 # expected behavior is (! grep ...)
# As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948
dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | grep $(TMPDIR) || exit 1 # expected behavior is (! grep ...)
rm -rf $(TMPDIR)/foo.dSYM
rm $(TMPDIR)/$(call BIN,foo)

# - Debuginfo in binary file
# - file paths from `N_SO` (source files) and `N_OSO` (object files) shouldn't be remapped
packed-remapped-wrong-scope:
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=packed -C debuginfo=2 \
--remap-path-prefix $(TMPDIR)=/a \
--remap-path-prefix $(HERE)=/b \
-Z remap-path-scope=macro foo.rs -g
ls $(TMPDIR)/*.o && exit 1 || exit 0
[ -d $(TMPDIR)/foo.dSYM ]
rm -rf $(TMPDIR)/*.dSYM
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | grep $(HERE) || exit 1
dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | grep $(TMPDIR) || exit 1
rm -rf $(TMPDIR)/foo.dSYM
rm $(TMPDIR)/$(call BIN,foo)

# Object files are preserved with unpacked and `dsymutil` isn't run
unpacked:
$(RUSTC) foo.rs -g -C split-debuginfo=unpacked
unpacked: unpacked-remapped-scope #unpacked-remapped-wrong-scope

# - Debuginfo in object files
# - file paths from `N_SO` (source files) and `N_OSO` (object files) should be remapped
unpacked-remapped-scope:
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=unpacked -C debuginfo=2 \
--remap-path-prefix $(TMPDIR)=/a \
--remap-path-prefix $(HERE)=/b \
-Z remap-path-scope=object foo.rs -g
ls $(TMPDIR)/*.o
[ ! -d $(TMPDIR)/foo.dSYM ]
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | (grep $(HERE)) || exit 1 # expected behavior is (! grep ...)
# As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948
dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | (grep $(TMPDIR)) || exit 1 # expected behavior is (! grep ...)
rm $(TMPDIR)/*.o
rm $(TMPDIR)/$(call BIN,foo)

# - Debuginfo in object files
# - file paths from `N_SO` (source files) and `N_OSO` (object files) shouldn't be remapped
unpacked-remapped-wrong-scope:
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=unpacked -C debuginfo=2 \
--remap-path-prefix $(TMPDIR)=/a \
--remap-path-prefix $(HERE)=/b \
-Z remap-path-scope=macro foo.rs -g
ls $(TMPDIR)/*.o
[ ! -d $(TMPDIR)/foo.dSYM ]
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | (grep $(HERE)) || exit 1
dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | (grep $(TMPDIR)) || exit 1
rm $(TMPDIR)/*.o
rm $(TMPDIR)/$(call BIN,foo)

else
ifdef IS_WINDOWS
# Windows only supports packed debuginfo - nothing to test.
Expand Down

0 comments on commit 3a9c9fe

Please sign in to comment.