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

elf.reloc: fix mips64 parse error #382

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/elf/reloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,58 @@ pub mod reloc64 {
pub const SIZEOF_RELA: usize = 8 + 8 + 8;
pub const SIZEOF_REL: usize = 8 + 8;

#[cfg(not(all(
Copy link
Owner

Choose a reason for hiding this comment

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

Why would these bit masking helper functions be cfg’d out on mips systems?

Copy link
Owner

Choose a reason for hiding this comment

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

Ah I see further down is the other condition. So I have to reread the linked thread but is the issue with how mips itself does some bit masking here or if the binary is from a mips arch ? If the latter a cfg is not appropriate as we should be able to read a mips elf binary on a whatever machine.

target_os = "linux",
any(target_arch = "mips64le", target_arch = "mips64")
)))]
#[inline(always)]
pub fn r_sym(info: u64) -> u32 {
(info >> 32) as u32
}

#[cfg(not(all(
target_os = "linux",
any(target_arch = "mips64le", target_arch = "mips64")
)))]
#[inline(always)]
pub fn r_type(info: u64) -> u32 {
(info & 0xffff_ffff) as u32
}

#[cfg(all(
target_os = "linux",
any(target_arch = "mips64le", target_arch = "mips64")
))]
pub fn get_info(info: u64) -> u64 {
let mut t = info;
t = (t << 32)
| ((t >> 8) & 0xff000000)
| ((t >> 24) & 0x00ff0000)
| ((t >> 40) & 0x0000ff00)
| ((t >> 56) & 0x000000ff);
t
}

#[cfg(all(
target_os = "linux",
any(target_arch = "mips64le", target_arch = "mips64")
))]
#[inline(always)]
pub fn r_sym(info: u64) -> u32 {
let trans_info = get_info(info);
(trans_info >> 32) as u32
}

#[cfg(all(
target_os = "linux",
any(target_arch = "mips64le", target_arch = "mips64")
))]
#[inline(always)]
pub fn r_type(info: u64) -> u32 {
let trans_info = get_info(info);
(trans_info & 0xffff_ffff) as u32
}

#[inline(always)]
pub fn r_info(sym: u64, typ: u64) -> u64 {
(sym << 32) + typ
Expand Down