Skip to content

Commit

Permalink
write/xcoff: add support.
Browse files Browse the repository at this point in the history
  • Loading branch information
EsmeYi committed Nov 7, 2022
1 parent a7b1655 commit 2661489
Show file tree
Hide file tree
Showing 5 changed files with 520 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- run: cargo build --no-default-features --features read_core,write_core,macho
- run: cargo build --no-default-features --features read_core,pe
- run: cargo build --no-default-features --features read_core,wasm
- run: cargo build --no-default-features --features read_core,xcoff
- run: cargo build --no-default-features --features read_core,write_core,xcoff
- run: cargo build --no-default-features --features doc

cross:
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name = "object"
version = "0.29.0"
edition = "2018"
exclude = ["/.github", "/testfiles"]
keywords = ["object", "elf", "mach-o", "pe", "coff"]
keywords = ["object", "elf", "mach-o", "pe", "coff", "xcoff"]
license = "Apache-2.0 OR MIT"
repository = "https://github.com/gimli-rs/object"
description = "A unified interface for reading and writing object file formats."
Expand Down Expand Up @@ -39,7 +39,7 @@ write_core = ["crc32fast", "indexmap", "hashbrown"]
# Core write support with libstd features. You will need to enable some file formats too.
write_std = ["write_core", "std", "indexmap/std", "crc32fast/std"]
# Write support for all file formats, including libstd features.
write = ["write_std", "coff", "elf", "macho", "pe"]
write = ["write_std", "coff", "elf", "macho", "pe", "xcoff"]

#=======================================
# Misc features.
Expand Down
16 changes: 14 additions & 2 deletions src/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ mod macho;
#[cfg(feature = "pe")]
pub mod pe;

#[cfg(feature = "xcoff")]
mod xcoff;

mod string;
pub use string::StringId;

Expand Down Expand Up @@ -218,6 +221,8 @@ impl<'a> Object<'a> {
BinaryFormat::Elf => self.elf_section_info(section),
#[cfg(feature = "macho")]
BinaryFormat::MachO => self.macho_section_info(section),
#[cfg(feature = "xcoff")]
BinaryFormat::Xcoff => self.xcoff_section_info(section),
_ => unimplemented!(),
}
}
Expand All @@ -243,7 +248,7 @@ impl<'a> Object<'a> {

fn has_subsections_via_symbols(&self) -> bool {
match self.format {
BinaryFormat::Coff | BinaryFormat::Elf => false,
BinaryFormat::Coff | BinaryFormat::Elf | BinaryFormat::Xcoff => false,
BinaryFormat::MachO => true,
_ => unimplemented!(),
}
Expand Down Expand Up @@ -506,6 +511,8 @@ impl<'a> Object<'a> {
BinaryFormat::Elf => self.elf_fixup_relocation(&mut relocation)?,
#[cfg(feature = "macho")]
BinaryFormat::MachO => self.macho_fixup_relocation(&mut relocation),
#[cfg(feature = "xcoff")]
BinaryFormat::Xcoff => self.xcoff_fixup_relocation(&mut relocation),
_ => unimplemented!(),
};
if addend != 0 {
Expand Down Expand Up @@ -574,6 +581,8 @@ impl<'a> Object<'a> {
BinaryFormat::Elf => self.elf_write(buffer),
#[cfg(feature = "macho")]
BinaryFormat::MachO => self.macho_write(buffer),
#[cfg(feature = "xcoff")]
BinaryFormat::Xcoff => self.xcoff_write(buffer),
_ => unimplemented!(),
}
}
Expand Down Expand Up @@ -894,6 +903,8 @@ pub enum Mangling {
Elf,
/// Mach-O symbol mangling.
MachO,
/// Xcoff symbol mangling.
Xcoff,
}

impl Mangling {
Expand All @@ -904,14 +915,15 @@ impl Mangling {
(BinaryFormat::Coff, _) => Mangling::Coff,
(BinaryFormat::Elf, _) => Mangling::Elf,
(BinaryFormat::MachO, _) => Mangling::MachO,
(BinaryFormat::Xcoff, _) => Mangling::Xcoff,
_ => Mangling::None,
}
}

/// Return the prefix to use for global symbols.
pub fn global_prefix(self) -> Option<u8> {
match self {
Mangling::None | Mangling::Elf | Mangling::Coff => None,
Mangling::None | Mangling::Elf | Mangling::Coff | Mangling::Xcoff => None,
Mangling::CoffI386 | Mangling::MachO => Some(b'_'),
}
}
Expand Down
Loading

0 comments on commit 2661489

Please sign in to comment.