A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Return an error when data object decls have different TLS value (#14469)
bjorn37d334af68ee2
diff --git a/cranelift/module/src/module.rs b/cranelift/module/src/module.rsindex 2afa4424ef..e642e74f68 100644--- a/cranelift/module/src/module.rs+++ b/cranelift/module/src/module.rs@@ -275,6 +275,10 @@ pub enum ModuleError {/// different signature than declared previouslyIncompatibleSignature(String, ir::Signature, ir::Signature),+ /// Indicates a data object was declared as TLS but previously+ /// declared as not TLS or vice versa.+ IncompatibleDataTls(String, bool, bool),+/// Indicates an identifier was defined more than onceDuplicateDefinition(String),@@ -316,6 +320,7 @@ impl core::error::Error for ModuleError {Self::Undeclared { .. }| Self::IncompatibleDeclaration { .. }| Self::IncompatibleSignature { .. }+ | Self::IncompatibleDataTls { .. }| Self::DuplicateDefinition { .. }| Self::InvalidImportDefinition { .. } => None,Self::Compilation(source) => Some(source),@@ -342,6 +347,12 @@ impl std::fmt::Display for ModuleError {"Function {name} signature {new_sig:?} is incompatible with previous declaration {prev_sig:?}",)}+ Self::IncompatibleDataTls(name, prev_tls, new_tls) => {+ write!(+ f,+ "Data object {name} TLS {new_tls:?} is incompatible with previous declaration TLS {prev_tls:?}",+ )+ }Self::DuplicateDefinition(name) => {write!(f, "Duplicate definition of identifier: {name}")}@@ -407,13 +418,17 @@ impl DataDeclaration {}}- fn merge(&mut self, linkage: Linkage, writable: bool, tls: bool) {+ fn merge(&mut self, linkage: Linkage, writable: bool, tls: bool) -> Result<(), ModuleError> {self.linkage = Linkage::merge(self.linkage, linkage);self.writable = self.writable || writable;- assert_eq!(- self.tls, tls,- "Can't change TLS data object to normal or in the opposite way",- );+ if self.tls != tls {+ return Err(ModuleError::IncompatibleDataTls(+ self.name.clone().unwrap(),+ self.tls,+ tls,+ ));+ }+ Ok(())}}@@ -789,7 +804,7 @@ impl ModuleDeclarations {Occupied(entry) => match *entry.get() {FuncOrDataId::Data(id) => {let existing = &mut self.data_objects[id];- existing.merge(linkage, writable, tls);+ existing.merge(linkage, writable, tls)?;Ok((id, existing.linkage))}