use elf::{
abi::{
R_AARCH64_ABS64, R_AARCH64_GLOB_DAT, R_AARCH64_JUMP_SLOT, R_AARCH64_RELATIVE,
R_AARCH64_TLSDESC, R_AARCH64_TLS_TPREL,
},
relocation::{Rel, Rela},
};
use crate::{builtins, error::Error, object::ResolvedSymbol, state::State};
use super::{RelValue, RelaValue, Relocation};
// Descriptor method of TLS access:
// * For static access:
// [0]: resolver function pointer
// [1]: fixed offset of the variable with the TLS area
// * For dynamic, TODO
fn make_tlsdesc_relocation(
dynamic: bool,
state: &State,
module_id: u32,
symbol_offset: usize,
) -> RelaValue {
if dynamic {
todo!("Dynamic TLSDESC relocations are not yet supported")
}
let layout = state
.tls_layout
.as_ref()
.expect("TLSDESC relocation, but no TLS segments in linked objects");
let Some(offset) = layout.offset(module_id, symbol_offset) else {
panic!("TLSDESC relocation against unknown module_id={module_id}, offset={symbol_offset}");
};
let resolver = builtins::tlsdesc_resolve_static as usize;
RelaValue::DQWord(resolver as i64, offset as i64)
}
impl Relocation for Rel {
type Value = RelValue;
fn resolve(
&self,
_state: &State,
_name: &str,
_symbol: &ResolvedSymbol,
_load_base: usize,
) -> Result