Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions lib/wasix/src/state/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ pub enum LinkError {

#[error("Bad __tls_base export, expected a global of type I32 or I64")]
BadTlsBaseExport,

#[error("Missing __tls_base export, required for TLS symbol '{0}'.{1}")]
MissingTlsBaseExport(String, String),
}

#[derive(Debug)]
Expand Down Expand Up @@ -583,10 +586,8 @@ pub enum ResolveError {
#[error("Failed to perform pending DL operation: {0}")]
PendingDlOperationFailed(#[from] LinkError),

#[error(
"Tried to resolve a tls symbol from a module that did not initialize thread local storage"
)]
TlsSymbolWithoutTls,
#[error("Module must export a `__tls_base` global to use thread-local symbols")]
NoTlsBaseGlobalExport,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -1774,7 +1775,7 @@ impl Linker {
offset,
} => {
let Some(tls_base) = group_state.tls_base(*resolved_from) else {
return Err(ResolveError::TlsSymbolWithoutTls);
return Err(ResolveError::NoTlsBaseGlobalExport);
};
return Ok(ResolvedExport::Global {
data_ptr: tls_base + offset,
Expand Down Expand Up @@ -3113,18 +3114,27 @@ impl InstanceGroupState {
}

InProgressSymbolResolution::MemGlobal(module_handle) => {
let export = self
.resolve_export_from(
store,
*module_handle,
import.name(),
self.instance(*module_handle),
linker_state.dylink_info(*module_handle),
linker_state.memory_base(*module_handle),
self.tls_base(*module_handle),
true,
)
.expect("Internal error: bad in-progress symbol resolution");
let export = match self.resolve_export_from(
store,
*module_handle,
import.name(),
self.instance(*module_handle),
linker_state.dylink_info(*module_handle),
linker_state.memory_base(*module_handle),
self.tls_base(*module_handle),
true,
) {
Ok(e) => e,
Err(ResolveError::NoTlsBaseGlobalExport) => {
return Err(LinkError::MissingTlsBaseExport(
import.module().to_string(),
import.name().to_string(),
));
}
Err(e) => {
panic!("Internal error: failed to resolve exported symbol: {e}")
}
Comment on lines +3127 to +3136
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Arshia001 I don't really like having to match here, because that will still cause a panic if we unwrap that error type on another path. Do you have a better idea on how to handle this?

};

match export {
PartiallyResolvedExport::Global(addr) => {
Expand Down Expand Up @@ -3623,7 +3633,7 @@ impl InstanceGroupState {

if is_tls {
let Some(tls_base) = tls_base else {
return Err(ResolveError::TlsSymbolWithoutTls);
return Err(ResolveError::NoTlsBaseGlobalExport);
};
let final_value = value + tls_base;
trace!(
Expand Down
Loading