Skip to content

Commit 2e500eb

Browse files
committed
linux elf relocation related structs addition.
close #3577
1 parent 3d0b15b commit 2e500eb

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

libc-test/build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,6 +3532,13 @@ fn test_linux(target: &str) {
35323532
});
35333533

35343534
cfg.skip_type(move |ty| {
3535+
// FIXME: very recent additions to musl, not yet released.
3536+
if musl && (ty == "Elf32_Relr" || ty == "Elf64_Relr") {
3537+
return true;
3538+
}
3539+
if sparc64 && (ty == "Elf32_Rela" || ty == "Elf64_Rela") {
3540+
return true;
3541+
}
35353542
match ty {
35363543
// FIXME: `sighandler_t` type is incorrect, see:
35373544
// https://github.com/rust-lang/libc/issues/1359

libc-test/semver/linux.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,14 @@ EKEYREJECTED
415415
EKEYREVOKED
416416
EL2HLT
417417
EL2NSYNC
418+
ELF32_R_SYM
419+
ELF32_R_TYPE
420+
ELF32_R_INFO
418421
EL3HLT
419422
EL3RST
423+
ELF64_R_SYM
424+
ELF64_R_TYPE
425+
ELF64_R_INFO
420426
ELFCLASS32
421427
ELFCLASS64
422428
ELFCLASSNONE
@@ -694,17 +700,26 @@ Elf32_Ehdr
694700
Elf32_Half
695701
Elf32_Off
696702
Elf32_Phdr
703+
Elf32_Rel
704+
Elf32_Rela
705+
Elf32_Relr
697706
Elf32_Section
698707
Elf32_Shdr
699708
Elf32_Sym
709+
Elf32_Sword
700710
Elf32_Word
711+
Elf32_Xword
701712
Elf64_Addr
702713
Elf64_Ehdr
703714
Elf64_Half
704715
Elf64_Off
705716
Elf64_Phdr
717+
Elf64_Rel
718+
Elf64_Rela
719+
Elf64_Relr
706720
Elf64_Section
707721
Elf64_Shdr
722+
Elf64_Sword
708723
Elf64_Sxword
709724
Elf64_Sym
710725
Elf64_Word

src/unix/linux_like/linux/mod.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,25 @@ pub type Elf32_Half = u16;
2727
pub type Elf32_Word = u32;
2828
pub type Elf32_Off = u32;
2929
pub type Elf32_Addr = u32;
30+
pub type Elf32_Xword = u64;
31+
pub type Elf32_Sword = i32;
3032

3133
pub type Elf64_Half = u16;
3234
pub type Elf64_Word = u32;
3335
pub type Elf64_Off = u64;
3436
pub type Elf64_Addr = u64;
3537
pub type Elf64_Xword = u64;
3638
pub type Elf64_Sxword = i64;
39+
pub type Elf64_Sword = i32;
3740

3841
pub type Elf32_Section = u16;
3942
pub type Elf64_Section = u16;
4043

44+
pub type Elf32_Relr = Elf32_Word;
45+
pub type Elf64_Relr = Elf32_Xword;
46+
pub type Elf32_Rel = __c_anonymous_elf32_rel;
47+
pub type Elf64_Rel = __c_anonymous_elf64_rel;
48+
4149
// linux/can.h
4250
pub type canid_t = u32;
4351

@@ -564,6 +572,16 @@ s! {
564572
pub sh_entsize: Elf64_Xword,
565573
}
566574

575+
pub struct __c_anonymous_elf32_rel {
576+
pub r_offset: Elf32_Addr,
577+
pub r_info: Elf32_Word,
578+
}
579+
580+
pub struct __c_anonymous_elf64_rel {
581+
pub r_offset: Elf64_Addr,
582+
pub r_info: Elf64_Xword,
583+
}
584+
567585
pub struct ucred {
568586
pub pid: ::pid_t,
569587
pub uid: ::uid_t,
@@ -997,6 +1015,8 @@ s! {
9971015

9981016
cfg_if! {
9991017
if #[cfg(not(target_arch = "sparc64"))] {
1018+
pub type Elf32_Rela = __c_anonymous_elf32_rela;
1019+
pub type Elf64_Rela = __c_anonymous_elf64_rela;
10001020
s!{
10011021
pub struct iw_thrspy {
10021022
pub addr: ::sockaddr,
@@ -1014,6 +1034,17 @@ cfg_if! {
10141034
pub src_addr: ::sockaddr,
10151035
pub tsc: [__u8; IW_ENCODE_SEQ_MAX_SIZE],
10161036
}
1037+
pub struct __c_anonymous_elf32_rela {
1038+
pub r_offset: Elf32_Addr,
1039+
pub r_info: Elf32_Word,
1040+
pub r_addend: Elf32_Sword,
1041+
}
1042+
1043+
pub struct __c_anonymous_elf64_rela {
1044+
pub r_offset: Elf64_Addr,
1045+
pub r_info: Elf64_Xword,
1046+
pub r_addend: Elf64_Sxword,
1047+
}
10171048
}
10181049
}
10191050
}
@@ -5214,6 +5245,30 @@ f! {
52145245
pub fn BPF_JUMP(code: ::__u16, k: ::__u32, jt: ::__u8, jf: ::__u8) -> sock_filter {
52155246
sock_filter{code: code, jt: jt, jf: jf, k: k}
52165247
}
5248+
5249+
pub fn ELF32_R_SYM(val: Elf32_Word) -> Elf32_Word {
5250+
val >> 8
5251+
}
5252+
5253+
pub fn ELF32_R_TYPE(val: Elf32_Word) -> Elf32_Word {
5254+
val & 0xff
5255+
}
5256+
5257+
pub fn ELF32_R_INFO(sym: Elf32_Word, t: Elf32_Word) -> Elf32_Word {
5258+
sym << 8 + t & 0xff
5259+
}
5260+
5261+
pub fn ELF64_R_SYM(val: Elf64_Xword) -> Elf64_Xword {
5262+
val >> 32
5263+
}
5264+
5265+
pub fn ELF64_R_TYPE(val: Elf64_Xword) -> Elf64_Xword {
5266+
val & 0xffffffff
5267+
}
5268+
5269+
pub fn ELF64_R_INFO(sym: Elf64_Xword, t: Elf64_Xword) -> Elf64_Xword {
5270+
sym << 32 + t
5271+
}
52175272
}
52185273

52195274
safe_f! {

0 commit comments

Comments
 (0)