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

Method declare_data

cranelift/object/src/backend.rs:373–415  ·  view source on GitHub ↗
(
        &mut self,
        name: &str,
        linkage: Linkage,
        writable: bool,
        tls: bool,
    )

Source from the content-addressed store, hash-verified

371 }
372
373 fn declare_data(
374 &mut self,
375 name: &str,
376 linkage: Linkage,
377 writable: bool,
378 tls: bool,
379 ) -> ModuleResult<DataId> {
380 validate_symbol(name)?;
381
382 let (id, linkage) = self
383 .declarations
384 .declare_data(name, linkage, writable, tls)?;
385
386 // Merging declarations with conflicting values for tls is not allowed, so it is safe to use
387 // the passed in tls value here.
388 let kind = if tls {
389 SymbolKind::Tls
390 } else {
391 SymbolKind::Data
392 };
393 let (scope, weak) = translate_linkage(linkage);
394
395 if let Some((data, _defined)) = self.data_objects[id] {
396 let symbol = self.object.symbol_mut(data);
397 symbol.kind = kind;
398 symbol.scope = scope;
399 symbol.weak = weak;
400 } else {
401 let symbol_id = self.object.add_symbol(Symbol {
402 name: name.as_bytes().to_vec(),
403 value: 0,
404 size: 0,
405 kind,
406 scope,
407 weak,
408 section: SymbolSection::Undefined,
409 flags: SymbolFlags::None,
410 });
411 self.data_objects[id] = Some((symbol_id, false));
412 }
413
414 Ok(id)
415 }
416
417 fn declare_anonymous_data(&mut self, writable: bool, tls: bool) -> ModuleResult<DataId> {
418 let id = self.declarations.declare_anonymous_data(writable, tls)?;

Calls 5

validate_symbolFunction · 0.85
translate_linkageFunction · 0.85
OkFunction · 0.85
as_bytesMethod · 0.80
to_vecMethod · 0.45