Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the arm64e architecture for macOS/iOS #574

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,7 @@ pub const GNU_PROPERTY_HIUSER: u32 = 0xffffffff;

/// AArch64 specific GNU properties.
pub const GNU_PROPERTY_AARCH64_FEATURE_1_AND: u32 = 0xc0000000;
pub const GNU_PROPERTY_AARCH64_FEATURE_PAUTH: u32 = 0xc0000001;

pub const GNU_PROPERTY_AARCH64_FEATURE_1_BTI: u32 = 1 << 0;
pub const GNU_PROPERTY_AARCH64_FEATURE_1_PAC: u32 = 1 << 1;
Expand Down
2 changes: 1 addition & 1 deletion src/write/coff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'a> Object<'a> {
name
}

pub(crate) fn coff_fixup_relocation(&mut self, mut relocation: &mut Relocation) -> i64 {
pub(crate) fn coff_fixup_relocation(&mut self, relocation: &mut Relocation) -> i64 {
if relocation.kind == RelocationKind::GotRelative {
// Use a stub symbol for the relocation instead.
// This isn't really a GOT, but it's a similar purpose.
Expand Down
2 changes: 1 addition & 1 deletion src/write/elf/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl<'a> Object<'a> {
})
}

pub(crate) fn elf_fixup_relocation(&mut self, mut relocation: &mut Relocation) -> Result<i64> {
pub(crate) fn elf_fixup_relocation(&mut self, relocation: &mut Relocation) -> Result<i64> {
// Return true if we should use a section symbol to avoid preemption.
fn want_section_symbol(relocation: &Relocation, symbol: &Symbol) -> bool {
if symbol.scope != SymbolScope::Dynamic {
Expand Down
16 changes: 14 additions & 2 deletions src/write/macho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ impl MachOBuildVersion {

// Public methods.
impl<'a> Object<'a> {
/// Specify the Mach-O CPU subtype.
///
/// Requires `feature = "macho"`.
#[inline]
pub fn set_macho_cpu_subtype(&mut self, cpu_subtype: u32) {
self.macho_cpu_subtype = Some(cpu_subtype);
}

/// Specify information for a Mach-O `LC_BUILD_VERSION` command.
///
/// Requires `feature = "macho"`.
Expand Down Expand Up @@ -243,7 +251,7 @@ impl<'a> Object<'a> {
init_symbol_id
}

pub(crate) fn macho_fixup_relocation(&mut self, mut relocation: &mut Relocation) -> i64 {
pub(crate) fn macho_fixup_relocation(&mut self, relocation: &mut Relocation) -> i64 {
let constant = match relocation.kind {
// AArch64Call relocations have special handling for the addend, so don't adjust it
RelocationKind::Relative if relocation.encoding == RelocationEncoding::AArch64Call => 0,
Expand Down Expand Up @@ -385,7 +393,7 @@ impl<'a> Object<'a> {
.map_err(|_| Error(String::from("Cannot allocate buffer")))?;

// Write file header.
let (cputype, cpusubtype) = match self.architecture {
let (cputype, mut cpusubtype) = match self.architecture {
Architecture::Arm => (macho::CPU_TYPE_ARM, macho::CPU_SUBTYPE_ARM_ALL),
Architecture::Aarch64 => (macho::CPU_TYPE_ARM64, macho::CPU_SUBTYPE_ARM64_ALL),
Architecture::Aarch64_Ilp32 => {
Expand All @@ -403,6 +411,10 @@ impl<'a> Object<'a> {
}
};

if let Some(cpu_subtype) = self.macho_cpu_subtype {
cpusubtype = cpu_subtype;
}

let flags = match self.flags {
FileFlags::MachO { flags } => flags,
_ => 0,
Expand Down
5 changes: 5 additions & 0 deletions src/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ pub struct Object<'a> {
pub mangling: Mangling,
/// Mach-O "_tlv_bootstrap" symbol.
tlv_bootstrap: Option<SymbolId>,
/// Mach-O CPU subtype.
#[cfg(feature = "macho")]
macho_cpu_subtype: Option<u32>,
#[cfg(feature = "macho")]
macho_build_version: Option<MachOBuildVersion>,
}
Expand All @@ -96,6 +99,8 @@ impl<'a> Object<'a> {
mangling: Mangling::default(format, architecture),
tlv_bootstrap: None,
#[cfg(feature = "macho")]
macho_cpu_subtype: None,
#[cfg(feature = "macho")]
macho_build_version: None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/write/xcoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<'a> Object<'a> {
}
}

pub(crate) fn xcoff_fixup_relocation(&mut self, mut relocation: &mut Relocation) -> i64 {
pub(crate) fn xcoff_fixup_relocation(&mut self, relocation: &mut Relocation) -> i64 {
let constant = match relocation.kind {
RelocationKind::Relative => relocation.addend + 4,
_ => relocation.addend,
Expand Down
Loading