Skip to content

Commit 3a9c9fe

Browse files
committed
test(trim-paths): verify SO symbols didn't get remapped
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.
1 parent 8a7b203 commit 3a9c9fe

File tree

1 file changed

+59
-11
lines changed

1 file changed

+59
-11
lines changed

tests/run-make/split-debuginfo/Makefile

+59-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# ignore-cross-compile
22
include ../tools.mk
33

4+
export HERE := $(shell pwd)
5+
46
all: off packed unpacked
57

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

1315
# Packed by default, but only if debuginfo is requested
14-
packed:
15-
rm -rf $(TMPDIR)/*.dSYM
16-
$(RUSTC) foo.rs
17-
[ ! -d $(TMPDIR)/foo.dSYM ]
18-
rm -rf $(TMPDIR)/*.dSYM
19-
$(RUSTC) foo.rs -g
16+
packed: packed-remapped-scope packed-remapped-wrong-scope
17+
18+
# - Debuginfo in binary file
19+
# - file paths from `SO` (source files) and `OSO` (object files) should be remapped
20+
packed-remapped-scope:
21+
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=packed -C debuginfo=2 \
22+
--remap-path-prefix $(TMPDIR)=/a \
23+
--remap-path-prefix $(HERE)=/b \
24+
-Z remap-path-scope=object foo.rs -g
25+
ls $(TMPDIR)/*.o && exit 1 || exit 0
2026
[ -d $(TMPDIR)/foo.dSYM ]
21-
rm -rf $(TMPDIR)/*.dSYM
22-
$(RUSTC) foo.rs -g -C split-debuginfo=packed
27+
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | grep $(HERE) || exit 1 # expected behavior is (! grep ...)
28+
# As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948
29+
dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | grep $(TMPDIR) || exit 1 # expected behavior is (! grep ...)
30+
rm -rf $(TMPDIR)/foo.dSYM
31+
rm $(TMPDIR)/$(call BIN,foo)
32+
33+
# - Debuginfo in binary file
34+
# - file paths from `N_SO` (source files) and `N_OSO` (object files) shouldn't be remapped
35+
packed-remapped-wrong-scope:
36+
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=packed -C debuginfo=2 \
37+
--remap-path-prefix $(TMPDIR)=/a \
38+
--remap-path-prefix $(HERE)=/b \
39+
-Z remap-path-scope=macro foo.rs -g
40+
ls $(TMPDIR)/*.o && exit 1 || exit 0
2341
[ -d $(TMPDIR)/foo.dSYM ]
24-
rm -rf $(TMPDIR)/*.dSYM
42+
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | grep $(HERE) || exit 1
43+
dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | grep $(TMPDIR) || exit 1
44+
rm -rf $(TMPDIR)/foo.dSYM
45+
rm $(TMPDIR)/$(call BIN,foo)
2546

2647
# Object files are preserved with unpacked and `dsymutil` isn't run
27-
unpacked:
28-
$(RUSTC) foo.rs -g -C split-debuginfo=unpacked
48+
unpacked: unpacked-remapped-scope #unpacked-remapped-wrong-scope
49+
50+
# - Debuginfo in object files
51+
# - file paths from `N_SO` (source files) and `N_OSO` (object files) should be remapped
52+
unpacked-remapped-scope:
53+
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=unpacked -C debuginfo=2 \
54+
--remap-path-prefix $(TMPDIR)=/a \
55+
--remap-path-prefix $(HERE)=/b \
56+
-Z remap-path-scope=object foo.rs -g
2957
ls $(TMPDIR)/*.o
3058
[ ! -d $(TMPDIR)/foo.dSYM ]
59+
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | (grep $(HERE)) || exit 1 # expected behavior is (! grep ...)
60+
# As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948
61+
dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | (grep $(TMPDIR)) || exit 1 # expected behavior is (! grep ...)
62+
rm $(TMPDIR)/*.o
63+
rm $(TMPDIR)/$(call BIN,foo)
64+
65+
# - Debuginfo in object files
66+
# - file paths from `N_SO` (source files) and `N_OSO` (object files) shouldn't be remapped
67+
unpacked-remapped-wrong-scope:
68+
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=unpacked -C debuginfo=2 \
69+
--remap-path-prefix $(TMPDIR)=/a \
70+
--remap-path-prefix $(HERE)=/b \
71+
-Z remap-path-scope=macro foo.rs -g
72+
ls $(TMPDIR)/*.o
73+
[ ! -d $(TMPDIR)/foo.dSYM ]
74+
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | (grep $(HERE)) || exit 1
75+
dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | (grep $(TMPDIR)) || exit 1
76+
rm $(TMPDIR)/*.o
77+
rm $(TMPDIR)/$(call BIN,foo)
78+
3179
else
3280
ifdef IS_WINDOWS
3381
# Windows only supports packed debuginfo - nothing to test.

0 commit comments

Comments
 (0)