Add TLS support for ELF and MachO (#1174)

* Add TLS support
* Add binemit and legalize tests
* Spill all caller-saved registers when necessary
This commit is contained in:
bjorn3
2020-02-26 02:50:04 +01:00
committed by GitHub
parent 0a11736fbf
commit 0a1bb3ba6c
27 changed files with 354 additions and 19 deletions

View File

@@ -188,6 +188,7 @@ pub struct DataDeclaration {
pub name: String,
pub linkage: Linkage,
pub writable: bool,
pub tls: bool,
pub align: Option<u8>,
}
@@ -206,10 +207,14 @@ impl<B> ModuleData<B>
where
B: Backend,
{
fn merge(&mut self, linkage: Linkage, writable: bool, align: Option<u8>) {
fn merge(&mut self, linkage: Linkage, writable: bool, tls: bool, align: Option<u8>) {
self.decl.linkage = Linkage::merge(self.decl.linkage, linkage);
self.decl.writable = self.decl.writable || writable;
self.decl.align = self.decl.align.max(align);
assert_eq!(
self.decl.tls, tls,
"Can't change TLS data object to normal or in the opposite way",
);
}
}
@@ -460,6 +465,7 @@ where
name: &str,
linkage: Linkage,
writable: bool,
tls: bool,
align: Option<u8>, // An alignment bigger than 128 is unlikely
) -> ModuleResult<DataId> {
// TODO: Can we avoid allocating names so often?
@@ -468,12 +474,13 @@ where
Occupied(entry) => match *entry.get() {
FuncOrDataId::Data(id) => {
let existing = &mut self.contents.data_objects[id];
existing.merge(linkage, writable, align);
existing.merge(linkage, writable, tls, align);
self.backend.declare_data(
id,
name,
existing.decl.linkage,
existing.decl.writable,
existing.decl.tls,
existing.decl.align,
);
Ok(id)
@@ -489,13 +496,14 @@ where
name: name.to_owned(),
linkage,
writable,
tls,
align,
},
compiled: None,
});
entry.insert(FuncOrDataId::Data(id));
self.backend
.declare_data(id, name, linkage, writable, align);
.declare_data(id, name, linkage, writable, tls, align);
Ok(id)
}
}
@@ -526,6 +534,7 @@ where
name: ir::ExternalName::user(1, data.as_u32()),
offset: ir::immediates::Imm64::new(0),
colocated,
tls: decl.tls,
})
}
@@ -634,6 +643,7 @@ where
data,
&info.decl.name,
info.decl.writable,
info.decl.tls,
info.decl.align,
data_ctx,
&ModuleNamespace::<B> {