Skip to content

Commit 92e8999

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 174e73a commit 92e8999

File tree

1 file changed

+67
-11
lines changed

1 file changed

+67
-11
lines changed

tests/run-make/split-debuginfo/Makefile

+67-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,77 @@ 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+
# - `.o` deleted
20+
# - `.dSYM` present
21+
# - in binary, paths from `N_SO` (source files) and `N_OSO` (object files) shouldn be remapped
22+
packed-remapped-scope:
23+
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=packed -C debuginfo=2 \
24+
--remap-path-prefix $(TMPDIR)=/a \
25+
--remap-path-prefix $(HERE)=/b \
26+
-Z remap-path-scope=object foo.rs -g
27+
ls $(TMPDIR)/*.o && exit 1 || exit 0
2028
[ -d $(TMPDIR)/foo.dSYM ]
21-
rm -rf $(TMPDIR)/*.dSYM
22-
$(RUSTC) foo.rs -g -C split-debuginfo=packed
29+
# As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948
30+
dsymutil -s $(TMPDIR)/foo | grep $(TMPDIR) || exit 1 # expected: `grep $(TMPDIR)` to exit 1
31+
dsymutil -s $(TMPDIR)/foo | grep $(HERE) || exit 1 # expected: `grep $(HERE)` to exit 1
32+
rm -rf $(TMPDIR)/foo.dSYM
33+
rm $(TMPDIR)/$(call BIN,foo)
34+
35+
# - Debuginfo in binary file
36+
# - `.o` deleted
37+
# - `.dSYM` present
38+
# - in binary, paths from `N_SO` (source files) and `N_OSO` (object files) shouldn't be remapped
39+
packed-remapped-wrong-scope:
40+
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=packed -C debuginfo=2 \
41+
--remap-path-prefix $(TMPDIR)=/a \
42+
--remap-path-prefix $(HERE)=/b \
43+
-Z remap-path-scope=macro foo.rs -g
44+
ls $(TMPDIR)/*.o && exit 1 || exit 0
2345
[ -d $(TMPDIR)/foo.dSYM ]
24-
rm -rf $(TMPDIR)/*.dSYM
46+
dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | grep $(TMPDIR) || exit 1
47+
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | grep $(HERE) || exit 1
48+
rm -rf $(TMPDIR)/foo.dSYM
49+
rm $(TMPDIR)/$(call BIN,foo)
2550

2651
# Object files are preserved with unpacked and `dsymutil` isn't run
27-
unpacked:
28-
$(RUSTC) foo.rs -g -C split-debuginfo=unpacked
52+
unpacked: unpacked-remapped-scope unpacked-remapped-wrong-scope
53+
54+
# - Debuginfo in object files
55+
# - `.o` present
56+
# - `.dSYM` never created
57+
# - in binary, paths from `N_SO` (source files) and `N_OSO` (object files) should be remapped
58+
unpacked-remapped-scope:
59+
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=unpacked -C debuginfo=2 \
60+
--remap-path-prefix $(TMPDIR)=/a \
61+
--remap-path-prefix $(HERE)=/b \
62+
-Z remap-path-scope=split-debuginfo-path foo.rs -g
2963
ls $(TMPDIR)/*.o
3064
[ ! -d $(TMPDIR)/foo.dSYM ]
65+
# As of 2023-12, `OSO` should be the only thing that cannot be trimmed. See rust-lang/rust#116948
66+
dsymutil -s $(TMPDIR)/foo | grep $(TMPDIR) || exit 1 # expected: `grep $(TMPDIR)` to exit 1
67+
dsymutil -s $(TMPDIR)/foo | grep $(HERE) || exit 1 # expected: `grep $(HERE)` to exit 1
68+
rm $(TMPDIR)/*.o
69+
rm $(TMPDIR)/$(call BIN,foo)
70+
71+
# - Debuginfo in object files
72+
# - `.o` present,
73+
# - `.dSYM` never created
74+
# - in binary, paths from `N_SO` (source files) and `N_OSO` (object files) shouldn't be remapped
75+
unpacked-remapped-wrong-scope:
76+
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=unpacked -C debuginfo=2 \
77+
--remap-path-prefix $(TMPDIR)=/a \
78+
--remap-path-prefix $(HERE)=/b \
79+
-Z remap-path-scope=macro foo.rs -g
80+
ls $(TMPDIR)/*.o
81+
[ ! -d $(TMPDIR)/foo.dSYM ]
82+
dsymutil -s $(TMPDIR)/foo | grep 'N_OSO' | (grep $(TMPDIR)) || exit 1
83+
dsymutil -s $(TMPDIR)/foo | grep 'N_SO' | (grep $(HERE)) || exit 1
84+
rm $(TMPDIR)/*.o
85+
rm $(TMPDIR)/$(call BIN,foo)
86+
3187
else
3288
ifdef IS_WINDOWS
3389
# Windows only supports packed debuginfo - nothing to test.

0 commit comments

Comments
 (0)