@@ -99,7 +99,8 @@ To preserve the section you can use a linker script like the one shown below.
99
99
/* file: keep-stack-sizes.x */
100
100
SECTIONS
101
101
{
102
- .stack_sizes :
102
+ /* `INFO` makes the section not allocatable so it won't be loaded into memory */
103
+ .stack_sizes (INFO) :
103
104
{
104
105
KEEP(*(.stack_sizes));
105
106
}
@@ -133,19 +134,28 @@ $ RUSTFLAGS="-Z emit-stack-sizes" cargo rustc --release -- \
133
134
-C link-arg=-N
134
135
135
136
$ 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
137
147
138
148
$ objdump -s -j .stack_sizes target/release/hello
139
149
140
150
target/release/hello: file format elf64-x86-64
141
151
142
152
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 ..........
149
159
```
150
160
151
161
> Author note: I'm not entirely sure why, in * this* case, ` -N ` is required in
0 commit comments