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

linux elf relocation related structs addition. #3583

Merged
merged 1 commit into from
Feb 25, 2024
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
7 changes: 7 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3532,6 +3532,13 @@ fn test_linux(target: &str) {
});

cfg.skip_type(move |ty| {
// FIXME: very recent additions to musl, not yet released.
if musl && (ty == "Elf32_Relr" || ty == "Elf64_Relr") {
return true;
}
if sparc64 && (ty == "Elf32_Rela" || ty == "Elf64_Rela") {
return true;
}
match ty {
// FIXME: `sighandler_t` type is incorrect, see:
// https://github.com/rust-lang/libc/issues/1359
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/linux-aarch64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ BPF_W
BPF_X
BPF_XOR
CIBAUD
Elf32_Rela
Elf64_Rela
FICLONE
FICLONERANGE
MADV_SOFT_OFFLINE
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/linux-i686.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ EDI
EDX
EFL
EIP
Elf32_Rela
Elf64_Rela
ES
ESI
FS
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/linux-powerpc64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ B2500000
B3000000
B3500000
B4000000
Elf32_Rela
Elf64_Rela
KEYCTL_CAPABILITIES
KEYCTL_CAPS0_BIG_KEY
KEYCTL_CAPS0_CAPABILITIES
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/linux-riscv64gc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ B3000000
B3500000
B4000000
CIBAUD
Elf32_Rela
Elf64_Rela
KEYCTL_CAPABILITIES
KEYCTL_CAPS0_BIG_KEY
KEYCTL_CAPS0_CAPABILITIES
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/linux-x86_64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ BPF_XOR
CIBAUD
CS
DS
Elf32_Rela
Elf64_Rela
ES
FS
GS
Expand Down
13 changes: 13 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,14 @@ EKEYREJECTED
EKEYREVOKED
EL2HLT
EL2NSYNC
ELF32_R_SYM
ELF32_R_TYPE
ELF32_R_INFO
EL3HLT
EL3RST
ELF64_R_SYM
ELF64_R_TYPE
ELF64_R_INFO
ELFCLASS32
ELFCLASS64
ELFCLASSNONE
Expand Down Expand Up @@ -694,17 +700,24 @@ Elf32_Ehdr
Elf32_Half
Elf32_Off
Elf32_Phdr
Elf32_Rel
Elf32_Relr
Elf32_Section
Elf32_Shdr
Elf32_Sym
Elf32_Sword
Elf32_Word
Elf32_Xword
Elf64_Addr
Elf64_Ehdr
Elf64_Half
Elf64_Off
Elf64_Phdr
Elf64_Rel
Elf64_Relr
Elf64_Section
Elf64_Shdr
Elf64_Sword
Elf64_Sxword
Elf64_Sym
Elf64_Word
Expand Down
60 changes: 60 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,32 @@ pub type Elf32_Half = u16;
pub type Elf32_Word = u32;
pub type Elf32_Off = u32;
pub type Elf32_Addr = u32;
pub type Elf32_Xword = u64;
pub type Elf32_Sword = i32;

pub type Elf64_Half = u16;
pub type Elf64_Word = u32;
pub type Elf64_Off = u64;
pub type Elf64_Addr = u64;
pub type Elf64_Xword = u64;
pub type Elf64_Sxword = i64;
pub type Elf64_Sword = i32;

pub type Elf32_Section = u16;
pub type Elf64_Section = u16;

pub type Elf32_Relr = Elf32_Word;
pub type Elf64_Relr = Elf32_Xword;
pub type Elf32_Rel = __c_anonymous_elf32_rel;
pub type Elf64_Rel = __c_anonymous_elf64_rel;

cfg_if! {
if #[cfg(not(target_arch = "sparc64"))] {
pub type Elf32_Rela = __c_anonymous_elf32_rela;
pub type Elf64_Rela = __c_anonymous_elf64_rela;
}
}

// linux/can.h
pub type canid_t = u32;

Expand Down Expand Up @@ -564,6 +579,16 @@ s! {
pub sh_entsize: Elf64_Xword,
}

pub struct __c_anonymous_elf32_rel {
pub r_offset: Elf32_Addr,
pub r_info: Elf32_Word,
}

pub struct __c_anonymous_elf64_rel {
pub r_offset: Elf64_Addr,
pub r_info: Elf64_Xword,
}

pub struct ucred {
pub pid: ::pid_t,
pub uid: ::uid_t,
Expand Down Expand Up @@ -1014,6 +1039,17 @@ cfg_if! {
pub src_addr: ::sockaddr,
pub tsc: [__u8; IW_ENCODE_SEQ_MAX_SIZE],
}
pub struct __c_anonymous_elf32_rela {
pub r_offset: Elf32_Addr,
pub r_info: Elf32_Word,
pub r_addend: Elf32_Sword,
}

pub struct __c_anonymous_elf64_rela {
pub r_offset: Elf64_Addr,
pub r_info: Elf64_Xword,
pub r_addend: Elf64_Sxword,
}
}
}
}
Expand Down Expand Up @@ -5214,6 +5250,30 @@ f! {
pub fn BPF_JUMP(code: ::__u16, k: ::__u32, jt: ::__u8, jf: ::__u8) -> sock_filter {
sock_filter{code: code, jt: jt, jf: jf, k: k}
}

pub fn ELF32_R_SYM(val: Elf32_Word) -> Elf32_Word {
val >> 8
}

pub fn ELF32_R_TYPE(val: Elf32_Word) -> Elf32_Word {
val & 0xff
}

pub fn ELF32_R_INFO(sym: Elf32_Word, t: Elf32_Word) -> Elf32_Word {
sym << 8 + t & 0xff
}

pub fn ELF64_R_SYM(val: Elf64_Xword) -> Elf64_Xword {
val >> 32
}

pub fn ELF64_R_TYPE(val: Elf64_Xword) -> Elf64_Xword {
val & 0xffffffff
}

pub fn ELF64_R_INFO(sym: Elf64_Xword, t: Elf64_Xword) -> Elf64_Xword {
sym << 32 + t
}
}

safe_f! {
Expand Down