Skip to content

Commit 5e686b2

Browse files
committed
unstable-book: recommend an INFO section
that makes the output .stack_sizes section non-allocatable when linking with either GNU LD or LLD
1 parent 7d2bb28 commit 5e686b2

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/doc/unstable-book/src/compiler-flags/emit-stack-sizes.md

+18-8
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ To preserve the section you can use a linker script like the one shown below.
9999
/* file: keep-stack-sizes.x */
100100
SECTIONS
101101
{
102-
.stack_sizes :
102+
/* `INFO` makes the section not allocatable so it won't be loaded into memory */
103+
.stack_sizes (INFO) :
103104
{
104105
KEEP(*(.stack_sizes));
105106
}
@@ -133,19 +134,28 @@ $ RUSTFLAGS="-Z emit-stack-sizes" cargo rustc --release -- \
133134
-C link-arg=-N
134135

135136
$ size -A target/release/hello | grep stack_sizes
136-
.stack_sizes 90 205368
137+
.stack_sizes 90 176272
138+
139+
$ # non-allocatable section (flags don't contain the "A" (alloc) flag)
140+
$ readelf -S target/release/hello
141+
Section Headers:
142+
[Nr] Name Type Address Offset
143+
Size EntSize Flags Link Info Align
144+
(..)
145+
[1031] .stack_sizes PROGBITS 000000000002b090 0002b0f0
146+
000000000000005a 0000000000000000 L 5 0 1
137147

138148
$ objdump -s -j .stack_sizes target/release/hello
139149

140150
target/release/hello: file format elf64-x86-64
141151

142152
Contents of section .stack_sizes:
143-
32238 c0040000 00000000 08f00400 00000000 ................
144-
32248 00080005 00000000 00000810 05000000 ................
145-
32258 00000000 20050000 00000000 10400500 .... ........@..
146-
32268 00000000 00087005 00000000 00000080 ......p.........
147-
32278 05000000 00000000 90050000 00000000 ................
148-
32288 00a00500 00000000 0000 ..........
153+
2b090 c0040000 00000000 08f00400 00000000 ................
154+
2b0a0 00080005 00000000 00000810 05000000 ................
155+
2b0b0 00000000 20050000 00000000 10400500 .... ........@..
156+
2b0c0 00000000 00087005 00000000 00000080 ......p.........
157+
2b0d0 05000000 00000000 90050000 00000000 ................
158+
2b0e0 00a00500 00000000 0000 ..........
149159
```
150160

151161
> Author note: I'm not entirely sure why, in *this* case, `-N` is required in

0 commit comments

Comments
 (0)