Skip to content

Commit 8e55d58

Browse files
devnexentgross35
authored andcommittedNov 17, 2024
linux elf relocation related structs addition.
close rust-lang#3577 (backport <rust-lang#3583>) (cherry picked from commit 7763956)
1 parent ddf5f93 commit 8e55d58

File tree

8 files changed

+87
-0
lines changed

8 files changed

+87
-0
lines changed
 

‎libc-test/build.rs

+7
Original file line numberDiff line numberDiff line change
@@ -3695,6 +3695,13 @@ fn test_linux(target: &str) {
36953695
});
36963696

36973697
cfg.skip_type(move |ty| {
3698+
// FIXME: very recent additions to musl, not yet released.
3699+
if musl && (ty == "Elf32_Relr" || ty == "Elf64_Relr") {
3700+
return true;
3701+
}
3702+
if sparc64 && (ty == "Elf32_Rela" || ty == "Elf64_Rela") {
3703+
return true;
3704+
}
36983705
match ty {
36993706
// FIXME: `sighandler_t` type is incorrect, see:
37003707
// 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
@@ -15,6 +15,8 @@ EFL
1515
EIP
1616
ES
1717
ESI
18+
Elf32_Rela
19+
Elf64_Rela
1820
FS
1921
GS
2022
KEYCTL_CAPABILITIES

‎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
@@ -10,6 +10,8 @@ COMPAT_HWCAP_ISA_F
1010
COMPAT_HWCAP_ISA_I
1111
COMPAT_HWCAP_ISA_M
1212
COMPAT_HWCAP_ISA_V
13+
Elf32_Rela
14+
Elf64_Rela
1315
KEYCTL_CAPABILITIES
1416
KEYCTL_CAPS0_BIG_KEY
1517
KEYCTL_CAPS0_CAPABILITIES

‎libc-test/semver/linux-x86_64.txt

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ CIBAUD
4141
CS
4242
DS
4343
ES
44+
Elf32_Rela
45+
Elf64_Rela
4446
FS
4547
GS
4648
MADV_SOFT_OFFLINE

‎libc-test/semver/linux.txt

+13
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@ EL2HLT
418418
EL2NSYNC
419419
EL3HLT
420420
EL3RST
421+
ELF32_R_INFO
422+
ELF32_R_SYM
423+
ELF32_R_TYPE
424+
ELF64_R_INFO
425+
ELF64_R_SYM
426+
ELF64_R_TYPE
421427
ELFCLASS32
422428
ELFCLASS64
423429
ELFCLASSNONE
@@ -697,17 +703,24 @@ Elf32_Ehdr
697703
Elf32_Half
698704
Elf32_Off
699705
Elf32_Phdr
706+
Elf32_Rel
707+
Elf32_Relr
700708
Elf32_Section
701709
Elf32_Shdr
710+
Elf32_Sword
702711
Elf32_Sym
703712
Elf32_Word
713+
Elf32_Xword
704714
Elf64_Addr
705715
Elf64_Ehdr
706716
Elf64_Half
707717
Elf64_Off
708718
Elf64_Phdr
719+
Elf64_Rel
720+
Elf64_Relr
709721
Elf64_Section
710722
Elf64_Shdr
723+
Elf64_Sword
711724
Elf64_Sxword
712725
Elf64_Sym
713726
Elf64_Word

‎src/unix/linux_like/linux/mod.rs

+57
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,32 @@ pub type Elf32_Half = u16;
2828
pub type Elf32_Word = u32;
2929
pub type Elf32_Off = u32;
3030
pub type Elf32_Addr = u32;
31+
pub type Elf32_Xword = u64;
32+
pub type Elf32_Sword = i32;
3133

3234
pub type Elf64_Half = u16;
3335
pub type Elf64_Word = u32;
3436
pub type Elf64_Off = u64;
3537
pub type Elf64_Addr = u64;
3638
pub type Elf64_Xword = u64;
3739
pub type Elf64_Sxword = i64;
40+
pub type Elf64_Sword = i32;
3841

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

45+
pub type Elf32_Relr = Elf32_Word;
46+
pub type Elf64_Relr = Elf32_Xword;
47+
pub type Elf32_Rel = __c_anonymous_elf32_rel;
48+
pub type Elf64_Rel = __c_anonymous_elf64_rel;
49+
50+
cfg_if! {
51+
if #[cfg(not(target_arch = "sparc64"))] {
52+
pub type Elf32_Rela = __c_anonymous_elf32_rela;
53+
pub type Elf64_Rela = __c_anonymous_elf64_rela;
54+
}
55+
}
56+
4257
// linux/can.h
4358
pub type canid_t = u32;
4459

@@ -980,6 +995,24 @@ s! {
980995
}
981996
}
982997

998+
cfg_if! {
999+
if #[cfg(not(target_arch = "sparc64"))] {
1000+
s!{
1001+
pub struct __c_anonymous_elf32_rela {
1002+
pub r_offset: Elf32_Addr,
1003+
pub r_info: Elf32_Word,
1004+
pub r_addend: Elf32_Sword,
1005+
}
1006+
1007+
pub struct __c_anonymous_elf64_rela {
1008+
pub r_offset: Elf64_Addr,
1009+
pub r_info: Elf64_Xword,
1010+
pub r_addend: Elf64_Sxword,
1011+
}
1012+
}
1013+
}
1014+
}
1015+
9831016
s_no_extra_traits! {
9841017
pub struct sockaddr_nl {
9851018
pub nl_family: ::sa_family_t,
@@ -5353,6 +5386,30 @@ f! {
53535386
pub fn BPF_JUMP(code: ::__u16, k: ::__u32, jt: ::__u8, jf: ::__u8) -> sock_filter {
53545387
sock_filter{code: code, jt: jt, jf: jf, k: k}
53555388
}
5389+
5390+
pub fn ELF32_R_SYM(val: Elf32_Word) -> Elf32_Word {
5391+
val >> 8
5392+
}
5393+
5394+
pub fn ELF32_R_TYPE(val: Elf32_Word) -> Elf32_Word {
5395+
val & 0xff
5396+
}
5397+
5398+
pub fn ELF32_R_INFO(sym: Elf32_Word, t: Elf32_Word) -> Elf32_Word {
5399+
sym << 8 + t & 0xff
5400+
}
5401+
5402+
pub fn ELF64_R_SYM(val: Elf64_Xword) -> Elf64_Xword {
5403+
val >> 32
5404+
}
5405+
5406+
pub fn ELF64_R_TYPE(val: Elf64_Xword) -> Elf64_Xword {
5407+
val & 0xffffffff
5408+
}
5409+
5410+
pub fn ELF64_R_INFO(sym: Elf64_Xword, t: Elf64_Xword) -> Elf64_Xword {
5411+
sym << 32 + t
5412+
}
53565413
}
53575414

53585415
safe_f! {

0 commit comments

Comments
 (0)