Skip to content

Commit 3daa8bd

Browse files
authored
Merge pull request #3583 from devnexen/elf64_rela_linux
linux elf relocation related structs addition.
2 parents 7ce81ca + 7763956 commit 3daa8bd

File tree

8 files changed

+90
-0
lines changed

8 files changed

+90
-0
lines changed

libc-test/build.rs

+7
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-aarch64.txt

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ BPF_W
3838
BPF_X
3939
BPF_XOR
4040
CIBAUD
41+
Elf32_Rela
42+
Elf64_Rela
4143
FICLONE
4244
FICLONERANGE
4345
MADV_SOFT_OFFLINE

libc-test/semver/linux-i686.txt

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ EDI
1313
EDX
1414
EFL
1515
EIP
16+
Elf32_Rela
17+
Elf64_Rela
1618
ES
1719
ESI
1820
FS

libc-test/semver/linux-powerpc64.txt

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ B2500000
22
B3000000
33
B3500000
44
B4000000
5+
Elf32_Rela
6+
Elf64_Rela
57
KEYCTL_CAPABILITIES
68
KEYCTL_CAPS0_BIG_KEY
79
KEYCTL_CAPS0_CAPABILITIES

libc-test/semver/linux-riscv64gc.txt

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ B3000000
33
B3500000
44
B4000000
55
CIBAUD
6+
Elf32_Rela
7+
Elf64_Rela
68
KEYCTL_CAPABILITIES
79
KEYCTL_CAPS0_BIG_KEY
810
KEYCTL_CAPS0_CAPABILITIES

libc-test/semver/linux-x86_64.txt

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ BPF_XOR
4040
CIBAUD
4141
CS
4242
DS
43+
Elf32_Rela
44+
Elf64_Rela
4345
ES
4446
FS
4547
GS

libc-test/semver/linux.txt

+13
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,24 @@ Elf32_Ehdr
694700
Elf32_Half
695701
Elf32_Off
696702
Elf32_Phdr
703+
Elf32_Rel
704+
Elf32_Relr
697705
Elf32_Section
698706
Elf32_Shdr
699707
Elf32_Sym
708+
Elf32_Sword
700709
Elf32_Word
710+
Elf32_Xword
701711
Elf64_Addr
702712
Elf64_Ehdr
703713
Elf64_Half
704714
Elf64_Off
705715
Elf64_Phdr
716+
Elf64_Rel
717+
Elf64_Relr
706718
Elf64_Section
707719
Elf64_Shdr
720+
Elf64_Sword
708721
Elf64_Sxword
709722
Elf64_Sym
710723
Elf64_Word

src/unix/linux_like/linux/mod.rs

+60
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,32 @@ 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+
49+
cfg_if! {
50+
if #[cfg(not(target_arch = "sparc64"))] {
51+
pub type Elf32_Rela = __c_anonymous_elf32_rela;
52+
pub type Elf64_Rela = __c_anonymous_elf64_rela;
53+
}
54+
}
55+
4156
// linux/can.h
4257
pub type canid_t = u32;
4358

@@ -564,6 +579,16 @@ s! {
564579
pub sh_entsize: Elf64_Xword,
565580
}
566581

582+
pub struct __c_anonymous_elf32_rel {
583+
pub r_offset: Elf32_Addr,
584+
pub r_info: Elf32_Word,
585+
}
586+
587+
pub struct __c_anonymous_elf64_rel {
588+
pub r_offset: Elf64_Addr,
589+
pub r_info: Elf64_Xword,
590+
}
591+
567592
pub struct ucred {
568593
pub pid: ::pid_t,
569594
pub uid: ::uid_t,
@@ -1014,6 +1039,17 @@ cfg_if! {
10141039
pub src_addr: ::sockaddr,
10151040
pub tsc: [__u8; IW_ENCODE_SEQ_MAX_SIZE],
10161041
}
1042+
pub struct __c_anonymous_elf32_rela {
1043+
pub r_offset: Elf32_Addr,
1044+
pub r_info: Elf32_Word,
1045+
pub r_addend: Elf32_Sword,
1046+
}
1047+
1048+
pub struct __c_anonymous_elf64_rela {
1049+
pub r_offset: Elf64_Addr,
1050+
pub r_info: Elf64_Xword,
1051+
pub r_addend: Elf64_Sxword,
1052+
}
10171053
}
10181054
}
10191055
}
@@ -5214,6 +5250,30 @@ f! {
52145250
pub fn BPF_JUMP(code: ::__u16, k: ::__u32, jt: ::__u8, jf: ::__u8) -> sock_filter {
52155251
sock_filter{code: code, jt: jt, jf: jf, k: k}
52165252
}
5253+
5254+
pub fn ELF32_R_SYM(val: Elf32_Word) -> Elf32_Word {
5255+
val >> 8
5256+
}
5257+
5258+
pub fn ELF32_R_TYPE(val: Elf32_Word) -> Elf32_Word {
5259+
val & 0xff
5260+
}
5261+
5262+
pub fn ELF32_R_INFO(sym: Elf32_Word, t: Elf32_Word) -> Elf32_Word {
5263+
sym << 8 + t & 0xff
5264+
}
5265+
5266+
pub fn ELF64_R_SYM(val: Elf64_Xword) -> Elf64_Xword {
5267+
val >> 32
5268+
}
5269+
5270+
pub fn ELF64_R_TYPE(val: Elf64_Xword) -> Elf64_Xword {
5271+
val & 0xffffffff
5272+
}
5273+
5274+
pub fn ELF64_R_INFO(sym: Elf64_Xword, t: Elf64_Xword) -> Elf64_Xword {
5275+
sym << 32 + t
5276+
}
52175277
}
52185278

52195279
safe_f! {

0 commit comments

Comments
 (0)