| 572 | } |
| 573 | |
| 574 | fn define_data(&mut self, id: DataId, data: &DataDescription) -> ModuleResult<()> { |
| 575 | let decl = self.declarations.get_data_decl(id); |
| 576 | if !decl.linkage.is_definable() { |
| 577 | return Err(ModuleError::InvalidImportDefinition( |
| 578 | decl.linkage_name(id).into_owned(), |
| 579 | )); |
| 580 | } |
| 581 | |
| 582 | if !self.compiled_data_objects[id].is_none() { |
| 583 | return Err(ModuleError::DuplicateDefinition( |
| 584 | decl.linkage_name(id).into_owned(), |
| 585 | )); |
| 586 | } |
| 587 | |
| 588 | assert!(!decl.tls, "JIT doesn't yet support TLS"); |
| 589 | |
| 590 | let &DataDescription { |
| 591 | ref init, |
| 592 | function_decls: _, |
| 593 | data_decls: _, |
| 594 | function_relocs: _, |
| 595 | data_relocs: _, |
| 596 | custom_segment_section: _, |
| 597 | align, |
| 598 | used: _, |
| 599 | } = data; |
| 600 | |
| 601 | let (align, kind) = if decl.writable { |
| 602 | ( |
| 603 | align.unwrap_or(WRITABLE_DATA_ALIGNMENT), |
| 604 | JITMemoryKind::Writable, |
| 605 | ) |
| 606 | } else { |
| 607 | ( |
| 608 | align.unwrap_or(READONLY_DATA_ALIGNMENT), |
| 609 | JITMemoryKind::ReadOnly, |
| 610 | ) |
| 611 | }; |
| 612 | |
| 613 | let pointer_reloc = match self.isa.triple().pointer_width().unwrap() { |
| 614 | PointerWidth::U16 => panic!(), |
| 615 | PointerWidth::U32 => Reloc::Abs4, |
| 616 | PointerWidth::U64 => Reloc::Abs8, |
| 617 | }; |
| 618 | let relocs = data.all_relocs(pointer_reloc).collect::<Vec<_>>(); |
| 619 | |
| 620 | self.compiled_data_objects[id] = Some(match *init { |
| 621 | Init::Uninitialized => { |
| 622 | panic!("data is not initialized yet"); |
| 623 | } |
| 624 | Init::Zeros { size } => CompiledBlob::new_zeroed( |
| 625 | &mut *self.memory, |
| 626 | size.max(1), |
| 627 | align, |
| 628 | relocs, |
| 629 | #[cfg(feature = "wasmtime-unwinder")] |
| 630 | None, |
| 631 | kind, |