Skip to content

Commit d263ea7

Browse files
committed
linux elf relocation related structs addition.
close rust-lang#3577
1 parent 3d0b15b commit d263ea7

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

libc-test/build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -3621,6 +3621,10 @@ fn test_linux(target: &str) {
36213621
if musl && ty == "fanout_args" {
36223622
return true;
36233623
}
3624+
// FIXME: very recent additions to musl, not yet released.
3625+
if musl && (ty.starts_with("Elf") && ty.ends_with("Relr")) {
3626+
return true;
3627+
}
36243628

36253629
match ty {
36263630
// These cannot be tested when "resolv.h" is included and are tested

libc-test/semver/linux.txt

+15
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

+56
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,27 @@ 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+
pub type Elf32_Rela = __c_anonymous_elf32_rela;
49+
pub type Elf64_Rela = __c_anonymous_elf64_rela;
50+
4151
// linux/can.h
4252
pub type canid_t = u32;
4353

@@ -564,6 +574,28 @@ s! {
564574
pub sh_entsize: Elf64_Xword,
565575
}
566576

577+
pub struct __c_anonymous_elf32_rel {
578+
pub r_offset: Elf32_Addr,
579+
pub r_info: Elf32_Word,
580+
}
581+
582+
pub struct __c_anonymous_elf64_rel {
583+
pub r_offset: Elf64_Addr,
584+
pub r_info: Elf64_Xword,
585+
}
586+
587+
pub struct __c_anonymous_elf32_rela {
588+
pub r_offset: Elf32_Addr,
589+
pub r_info: Elf32_Word,
590+
pub r_addend: Elf32_Sword,
591+
}
592+
593+
pub struct __c_anonymous_elf64_rela {
594+
pub r_offset: Elf64_Addr,
595+
pub r_info: Elf64_Xword,
596+
pub r_addend: Elf64_Sxword,
597+
}
598+
567599
pub struct ucred {
568600
pub pid: ::pid_t,
569601
pub uid: ::uid_t,
@@ -5214,6 +5246,30 @@ f! {
52145246
pub fn BPF_JUMP(code: ::__u16, k: ::__u32, jt: ::__u8, jf: ::__u8) -> sock_filter {
52155247
sock_filter{code: code, jt: jt, jf: jf, k: k}
52165248
}
5249+
5250+
pub fn ELF32_R_SYM(val: Elf32_Word) -> Elf32_Word {
5251+
val >> 8
5252+
}
5253+
5254+
pub fn ELF32_R_TYPE(val: Elf32_Word) -> Elf32_Word {
5255+
val & 0xff
5256+
}
5257+
5258+
pub fn ELF32_R_INFO(sym: Elf32_Word, t: Elf32_Word) -> Elf32_Word {
5259+
sym << 8 + t & 0xff
5260+
}
5261+
5262+
pub fn ELF64_R_SYM(val: Elf64_Xword) -> Elf64_Xword {
5263+
val >> 32
5264+
}
5265+
5266+
pub fn ELF64_R_TYPE(val: Elf64_Xword) -> Elf64_Xword {
5267+
val & 0xffffffff
5268+
}
5269+
5270+
pub fn ELF64_R_INFO(sym: Elf64_Xword, t: Elf64_Xword) -> Elf64_Xword {
5271+
sym << 32 + t
5272+
}
52175273
}
52185274

52195275
safe_f! {

0 commit comments

Comments
 (0)