@@ -159,21 +159,27 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
159
159
return ;
160
160
}
161
161
162
- // For the wasm32 target statics with `#[link_section]` are placed into custom
163
- // sections of the final output file, but this isn't link custom sections of
164
- // other executable formats. Namely we can only embed a list of bytes,
165
- // nothing with provenance (pointers to anything else). If any provenance
166
- // show up, reject it here.
162
+ // For the wasm32 target statics with `#[link_section]` other than `.init_array`
163
+ // are placed into custom sections of the final output file, but this isn't link
164
+ // custom sections of other executable formats. Namely we can only embed a list
165
+ // of bytes, nothing with provenance (pointers to anything else). If any
166
+ // provenance show up, reject it here.
167
167
// `#[link_section]` may contain arbitrary, or even undefined bytes, but it is
168
168
// the consumer's responsibility to ensure all bytes that have been read
169
169
// have defined values.
170
170
if let Ok ( alloc) = tcx. eval_static_initializer ( id. to_def_id ( ) )
171
171
&& alloc. inner ( ) . provenance ( ) . ptrs ( ) . len ( ) != 0
172
172
{
173
- let msg = "statics with a custom `#[link_section]` must be a \
173
+ if attrs
174
+ . link_section
175
+ . map ( |link_section| !link_section. as_str ( ) . starts_with ( ".init_array" ) )
176
+ . unwrap_or ( true )
177
+ {
178
+ let msg = "statics with a custom `#[link_section]` must be a \
174
179
simple list of bytes on the wasm target with no \
175
180
extra levels of indirection such as references";
176
- tcx. dcx ( ) . span_err ( tcx. def_span ( id) , msg) ;
181
+ tcx. dcx ( ) . span_err ( tcx. def_span ( id) , msg) ;
182
+ }
177
183
}
178
184
}
179
185
0 commit comments