@@ -160,20 +160,35 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
160
160
}
161
161
162
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
163
+ // are placed into custom sections of the final output file, but this isn't like
164
164
// custom sections of other executable formats. Namely we can only embed a list
165
165
// of bytes, nothing with provenance (pointers to anything else). If any
166
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
+ //
171
+ // The `.init_array` section is left to go through the normal custom section code path.
172
+ // When dealing with `.init_array` wasm-ld currently has several limitations. This manifests
173
+ // in workarounds in user-code.
174
+ //
175
+ // * The linker fails to merge multiple items in a crate into the .init_array section.
176
+ // To work around this, a single array can be used placing multiple items in the array.
177
+ // #[link_section = ".init_array"]
178
+ // static FOO: [unsafe extern "C" fn(); 2] = [ctor, ctor];
179
+ // * Even symbols marked used get gc'd from dependant crates unless at least one symbol
180
+ // in the crate is marked with an `#[export_name]`
181
+ //
182
+ // Once `.init_array` support in wasm-ld is complete, the user code workarounds should
183
+ // continue to work, but would no longer be necessary.
184
+
170
185
if let Ok ( alloc) = tcx. eval_static_initializer ( id. to_def_id ( ) )
171
186
&& alloc. inner ( ) . provenance ( ) . ptrs ( ) . len ( ) != 0
172
187
{
173
188
if attrs
174
189
. link_section
175
190
. map ( |link_section| !link_section. as_str ( ) . starts_with ( ".init_array" ) )
176
- . unwrap_or ( true )
191
+ . unwrap ( )
177
192
{
178
193
let msg = "statics with a custom `#[link_section]` must be a \
179
194
simple list of bytes on the wasm target with no \
0 commit comments