Skip to content

Commit ab1472e

Browse files
committed
Update dl_phdr_info definition to more closely match header files
Also, update tests to skip conflicts
1 parent 970fec9 commit ab1472e

File tree

2 files changed

+41
-24
lines changed

2 files changed

+41
-24
lines changed

libc-test/build.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,7 @@ fn test_android(target: &str) {
14711471
"asm/mman.h",
14721472
"linux/auxvec.h",
14731473
"linux/dccp.h",
1474+
"linux/elf.h",
14741475
"linux/errqueue.h",
14751476
"linux/falloc.h",
14761477
"linux/futex.h",
@@ -1612,7 +1613,12 @@ fn test_android(target: &str) {
16121613
// This is a weird union, don't check the type.
16131614
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
16141615
// sigval is actually a union, but we pretend it's a struct
1615-
(struct_ == "sigevent" && field == "sigev_value")
1616+
(struct_ == "sigevent" && field == "sigev_value") ||
1617+
// FIXME: `sa_sigaction` has type `sighandler_t` but that type is
1618+
// incorrect, see: https://github.com/rust-lang/libc/issues/1359
1619+
(struct_ == "sigaction" && field == "sa_sigaction") ||
1620+
// signalfd had SIGSYS fields added in Android 4.19, but CI does not have that version yet.
1621+
(struct_ == "signalfd_siginfo" && field == "ssi_call_addr")
16161622
});
16171623

16181624
cfg.skip_field(move |struct_, field| {
@@ -1630,6 +1636,20 @@ fn test_android(target: &str) {
16301636
field == "ssi_arch"))
16311637
});
16321638

1639+
cfg.skip_field(|struct_, field| {
1640+
match (struct_, field) {
1641+
// conflicting with `p_type` macro from <resolve.h>.
1642+
("Elf32_Phdr", "p_type") => true,
1643+
("Elf64_Phdr", "p_type") => true,
1644+
1645+
// this is actually a union on linux, so we can't represent it well and
1646+
// just insert some padding.
1647+
("siginfo_t", "_pad") => true,
1648+
1649+
_ => false,
1650+
}
1651+
});
1652+
16331653
cfg.generate("../src/lib.rs", "main.rs");
16341654

16351655
test_linux_like_apis(target);

src/unix/linux_like/android/mod.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,19 @@ pub type loff_t = ::c_longlong;
2626
pub type __kernel_loff_t = ::c_longlong;
2727
pub type __kernel_pid_t = ::c_int;
2828

29-
// elf.h
29+
// linux/elf.h
3030

3131
pub type Elf32_Addr = u32;
3232
pub type Elf32_Half = u16;
33-
pub type Elf32_Lword = u64;
3433
pub type Elf32_Off = u32;
35-
pub type Elf32_Sword = i32;
3634
pub type Elf32_Word = u32;
3735

3836
pub type Elf64_Addr = u64;
3937
pub type Elf64_Half = u16;
40-
pub type Elf64_Lword = u64;
4138
pub type Elf64_Off = u64;
42-
pub type Elf64_Sword = i32;
43-
pub type Elf64_Sxword = i64;
4439
pub type Elf64_Word = u32;
4540
pub type Elf64_Xword = u64;
4641

47-
cfg_if! {
48-
if #[cfg(target_pointer_width = "64")] {
49-
type Elf_Addr = Elf64_Addr;
50-
type Elf_Half = Elf64_Half;
51-
type Elf_Phdr = Elf64_Phdr;
52-
} else if #[cfg(target_pointer_width = "32")] {
53-
type Elf_Addr = Elf32_Addr;
54-
type Elf_Half = Elf32_Half;
55-
type Elf_Phdr = Elf32_Phdr;
56-
}
57-
}
58-
5942
s! {
6043
pub struct stack_t {
6144
pub ss_sp: *mut ::c_void,
@@ -275,7 +258,7 @@ s! {
275258
pub svm_zero: [u8; 4]
276259
}
277260

278-
// elf.h
261+
// linux/elf.h
279262

280263
pub struct Elf32_Phdr {
281264
pub p_type: Elf32_Word,
@@ -302,13 +285,27 @@ s! {
302285
// link.h
303286

304287
pub struct dl_phdr_info {
305-
pub dlpi_addr: Elf_Addr,
288+
#[cfg(target_pointer_width = "64")]
289+
pub dlpi_addr: Elf64_Addr,
290+
#[cfg(target_pointer_width = "32")]
291+
pub dlpi_addr: Elf32_Addr,
292+
306293
pub dlpi_name: *const ::c_char,
307-
pub dlpi_phdr: *const Elf_Phdr,
308-
pub dlpi_phnum: Elf_Half,
294+
295+
#[cfg(target_pointer_width = "64")]
296+
pub dlpi_phdr: *const Elf64_Phdr,
297+
#[cfg(target_pointer_width = "32")]
298+
pub dlpi_phdr: *const Elf32_Phdr,
299+
300+
#[cfg(target_pointer_width = "64")]
301+
pub dlpi_phnum: Elf64_Half,
302+
#[cfg(target_pointer_width = "32")]
303+
pub dlpi_phnum: Elf32_Half,
304+
305+
// These fields were added in Android R
309306
pub dlpi_adds: ::c_ulonglong,
310307
pub dlpi_subs: ::c_ulonglong,
311-
pub dlpi_tls_modid: usize,
308+
pub dlpi_tls_modid: ::size_t,
312309
pub dlpi_tls_data: *mut ::c_void,
313310
}
314311
}

0 commit comments

Comments
 (0)