Skip to content

Commit 1de046f

Browse files
committed
Update for review
1 parent a85700a commit 1de046f

File tree

1 file changed

+17
-2
lines changed
  • compiler/rustc_hir_analysis/src/check

1 file changed

+17
-2
lines changed

compiler/rustc_hir_analysis/src/check/mod.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,35 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
160160
}
161161

162162
// 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
164164
// custom sections of other executable formats. Namely we can only embed a list
165165
// of bytes, nothing with provenance (pointers to anything else). If any
166166
// provenance show up, reject it here.
167167
// `#[link_section]` may contain arbitrary, or even undefined bytes, but it is
168168
// the consumer's responsibility to ensure all bytes that have been read
169169
// 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+
170185
if let Ok(alloc) = tcx.eval_static_initializer(id.to_def_id())
171186
&& alloc.inner().provenance().ptrs().len() != 0
172187
{
173188
if attrs
174189
.link_section
175190
.map(|link_section| !link_section.as_str().starts_with(".init_array"))
176-
.unwrap_or(true)
191+
.unwrap()
177192
{
178193
let msg = "statics with a custom `#[link_section]` must be a \
179194
simple list of bytes on the wasm target with no \

0 commit comments

Comments
 (0)