MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / define_data

Method define_data

cranelift/object/src/backend.rs:495–634  ·  view source on GitHub ↗
(&mut self, data_id: DataId, data: &DataDescription)

Source from the content-addressed store, hash-verified

493 }
494
495 fn define_data(&mut self, data_id: DataId, data: &DataDescription) -> ModuleResult<()> {
496 let decl = self.declarations.get_data_decl(data_id);
497 if !decl.linkage.is_definable() {
498 return Err(ModuleError::InvalidImportDefinition(
499 decl.linkage_name(data_id).into_owned(),
500 ));
501 }
502
503 let &mut (symbol, ref mut defined) = self.data_objects[data_id].as_mut().unwrap();
504 if *defined {
505 return Err(ModuleError::DuplicateDefinition(
506 decl.linkage_name(data_id).into_owned(),
507 ));
508 }
509 *defined = true;
510
511 let &DataDescription {
512 ref init,
513 function_decls: _,
514 data_decls: _,
515 function_relocs: _,
516 data_relocs: _,
517 ref custom_segment_section,
518 align,
519 used,
520 } = data;
521
522 let pointer_reloc = match self.isa.triple().pointer_width().unwrap() {
523 PointerWidth::U16 => unimplemented!("16bit pointers"),
524 PointerWidth::U32 => Reloc::Abs4,
525 PointerWidth::U64 => Reloc::Abs8,
526 };
527 let relocs = data
528 .all_relocs(pointer_reloc)
529 .map(|record| self.process_reloc(&record))
530 .collect::<Vec<_>>();
531
532 let section = if custom_segment_section.is_none() {
533 let section_kind = if let Init::Zeros { .. } = *init {
534 if decl.tls {
535 StandardSection::UninitializedTls
536 } else {
537 StandardSection::UninitializedData
538 }
539 } else if decl.tls {
540 StandardSection::Tls
541 } else if decl.writable {
542 StandardSection::Data
543 } else if relocs.is_empty() {
544 StandardSection::ReadOnlyData
545 } else {
546 StandardSection::ReadOnlyDataWithRel
547 };
548 if self.per_data_object_section || used {
549 // FIXME pass empty symbol name once add_subsection produces `.text` as section name
550 // instead of `.text.` when passed an empty symbol name. (object#748) Until then
551 // pass `subsection` to produce `.text.subsection` as section name to reduce
552 // confusion.

Callers 1

Calls 15

BackendClass · 0.85
fromFunction · 0.85
maxFunction · 0.85
OkFunction · 0.85
get_data_declMethod · 0.80
is_definableMethod · 0.80
into_ownedMethod · 0.80
linkage_nameMethod · 0.80
all_relocsMethod · 0.80
process_relocMethod · 0.80
into_bytesMethod · 0.80
symbol_alignmentMethod · 0.80

Tested by 1