Skip to content

Commit 6700047

Browse files
committed
proper fix for stapsdt note and gc-sections interaction
1 parent 9806f68 commit 6700047

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

tokio/src/util/usdt/stapsdt.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,13 @@ macro_rules! call_probe {
3535
) => {
3636
// <https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation>
3737
// <https://github.com/cdkey/systemtap/blob/cbb34b7244ba60cb0904d61dc9167290855106aa/includes/sys/sdt.h#L240-L254>
38-
//
39-
// The `R` here means "retained". It prevents the linker from GC the note.
40-
// This additionally means that the function containing the `nop` is also not GCd.
41-
//
42-
// This is not great, but without this we get notes that are not GCd but the functions
43-
// they reference are GCd. This causes notes to have incorrect addresses.
4438
std::arch::asm!(
45-
"990: nop
46-
.pushsection .note.stapsdt, \"R\", \"note\"
47-
.balign 4
39+
"990: nop",
40+
// We deviate from what systemtap source code does here.
41+
// This is to fix an issue with how gc-sections is implemented while linking.
42+
// This problem seems to manifest only when monomorphising certain functions with many CGUs.
43+
concat!(".pushsection .note.stapsdt, \"G\", \"note\", \".note.stapsdt.tokio.", $name, "\", comdat"),
44+
".balign 4
4845
.4byte 992f-991f, 994f-993f, 3
4946
991:
5047
.asciz \"stapsdt\"
@@ -76,16 +73,13 @@ macro_rules! call_probe {
7673
) => {
7774
// <https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation>
7875
// <https://github.com/cdkey/systemtap/blob/cbb34b7244ba60cb0904d61dc9167290855106aa/includes/sys/sdt.h#L240-L254>
79-
//
80-
// The `R` here means "retained". It prevents the linker from GC the note.
81-
// This additionally means that the function containing the `nop` is also not GCd.
82-
//
83-
// This is not great, but without this we get notes that are not GCd but the functions
84-
// they reference are GCd. This causes notes to have incorrect addresses.
8576
std::arch::asm!(
86-
"990: nop
87-
.pushsection .note.stapsdt, \"R\", \"note\"
88-
.balign 4
77+
"990: nop",
78+
// We deviate from what systemtap source code does here.
79+
// This is to fix an issue with how gc-sections is implemented while linking.
80+
// This problem seems to manifest only when monomorphising certain functions with many CGUs.
81+
concat!(".pushsection .note.stapsdt, \"G\", \"note\", \".note.stapsdt.tokio.", $name, "\", comdat"),
82+
".balign 4
8983
.4byte 992f-991f, 994f-993f, 3
9084
991:
9185
.asciz \"stapsdt\"

0 commit comments

Comments
 (0)