Skip to content

Commit 3df6ed4

Browse files
committed
Auto merge of #1961 - JohnTitor:rollup-kddq6xl, r=JohnTitor
Rollup of 2 pull requests Successful merges: - #1953 (Add dl_iterate_phdr to some BSD OSs) - #1960 (Disable `sparc-unknown-linux-gnu` for now) Failed merges: r? `@ghost`
2 parents ba4dfc2 + ab7c561 commit 3df6ed4

File tree

6 files changed

+269
-4
lines changed

6 files changed

+269
-4
lines changed

ci/build.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ for TARGET in $TARGETS; do
201201
fi
202202
done
203203

204+
# Disable the below because of LLVM on `compiler_builtins` 0.1.36:
205+
# sparc-unknown-linux-gnu
204206
RUST_LINUX_NO_CORE_TARGETS="\
205207
aarch64-pc-windows-msvc \
206208
aarch64-unknown-cloudabi \
@@ -241,7 +243,6 @@ riscv32imc-unknown-none-elf \
241243
riscv32gc-unknown-linux-gnu \
242244
riscv64gc-unknown-none-elf \
243245
riscv64imac-unknown-none-elf \
244-
sparc-unknown-linux-gnu \
245246
sparc64-unknown-netbsd \
246247
247248
thumbv6m-none-eabi \

libc-test/build.rs

+33-2
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,11 @@ fn test_openbsd(target: &str) {
287287
cfg.flag("-Wno-deprecated-declarations");
288288

289289
headers! { cfg:
290+
"elf.h",
290291
"errno.h",
291292
"fcntl.h",
292293
"limits.h",
294+
"link.h",
293295
"locale.h",
294296
"stddef.h",
295297
"stdint.h",
@@ -387,7 +389,9 @@ fn test_openbsd(target: &str) {
387389
cfg.type_name(move |ty, is_struct, is_union| {
388390
match ty {
389391
// Just pass all these through, no need for a "struct" prefix
390-
"FILE" | "DIR" | "Dl_info" => ty.to_string(),
392+
"FILE" | "DIR" | "Dl_info" | "Elf32_Phdr" | "Elf64_Phdr" => {
393+
ty.to_string()
394+
}
391395

392396
// OSX calls this something else
393397
"sighandler_t" => "sig_t".to_string(),
@@ -418,6 +422,15 @@ fn test_openbsd(target: &str) {
418422
struct_ == "siginfo_t" && field == "si_addr"
419423
});
420424

425+
cfg.skip_field(|struct_, field| {
426+
match (struct_, field) {
427+
// conflicting with `p_type` macro from <resolve.h>.
428+
("Elf32_Phdr", "p_type") => true,
429+
("Elf64_Phdr", "p_type") => true,
430+
_ => false,
431+
}
432+
});
433+
421434
cfg.generate("../src/lib.rs", "main.rs");
422435
}
423436

@@ -870,9 +883,11 @@ fn test_netbsd(target: &str) {
870883

871884
headers! {
872885
cfg:
886+
"elf.h",
873887
"errno.h",
874888
"fcntl.h",
875889
"limits.h",
890+
"link.h",
876891
"locale.h",
877892
"stddef.h",
878893
"stdint.h",
@@ -1061,6 +1076,15 @@ fn test_netbsd(target: &str) {
10611076
(struct_ == "aiocb" && field == "aio_buf")
10621077
});
10631078

1079+
cfg.skip_field(|struct_, field| {
1080+
match (struct_, field) {
1081+
// conflicting with `p_type` macro from <resolve.h>.
1082+
("Elf32_Phdr", "p_type") => true,
1083+
("Elf64_Phdr", "p_type") => true,
1084+
_ => false,
1085+
}
1086+
});
1087+
10641088
cfg.generate("../src/lib.rs", "main.rs");
10651089
}
10661090

@@ -1633,6 +1657,7 @@ fn test_freebsd(target: &str) {
16331657
"ctype.h",
16341658
"dirent.h",
16351659
"dlfcn.h",
1660+
"elf.h",
16361661
"errno.h",
16371662
"fcntl.h",
16381663
"glob.h",
@@ -1641,6 +1666,7 @@ fn test_freebsd(target: &str) {
16411666
"langinfo.h",
16421667
"libutil.h",
16431668
"limits.h",
1669+
"link.h",
16441670
"locale.h",
16451671
"machine/reg.h",
16461672
"mqueue.h",
@@ -1709,7 +1735,8 @@ fn test_freebsd(target: &str) {
17091735
cfg.type_name(move |ty, is_struct, is_union| {
17101736
match ty {
17111737
// Just pass all these through, no need for a "struct" prefix
1712-
"FILE" | "fd_set" | "Dl_info" | "DIR" => ty.to_string(),
1738+
"FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr"
1739+
| "Elf64_Phdr" => ty.to_string(),
17131740

17141741
// FIXME: https://github.com/rust-lang/libc/issues/1273
17151742
"sighandler_t" => "sig_t".to_string(),
@@ -1909,6 +1936,10 @@ fn test_freebsd(target: &str) {
19091936
// `void*`:
19101937
("stack_t", "ss_sp") if Some(10) == freebsd_ver => true,
19111938

1939+
// conflicting with `p_type` macro from <resolve.h>.
1940+
("Elf32_Phdr", "p_type") => true,
1941+
("Elf64_Phdr", "p_type") => true,
1942+
19121943
_ => false,
19131944
}
19141945
});

src/unix/bsd/freebsdlike/freebsd/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ extern "C" {
15021502
pub fn nmount(
15031503
iov: *mut ::iovec,
15041504
niov: ::c_uint,
1505-
flags: ::c_int
1505+
flags: ::c_int,
15061506
) -> ::c_int;
15071507
}
15081508

src/unix/bsd/freebsdlike/mod.rs

+81
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,38 @@ pub type nl_item = ::c_int;
1414
pub type id_t = i64;
1515
pub type vm_size_t = ::uintptr_t;
1616

17+
// elf.h
18+
19+
pub type Elf32_Addr = u32;
20+
pub type Elf32_Half = u16;
21+
pub type Elf32_Lword = u64;
22+
pub type Elf32_Off = u32;
23+
pub type Elf32_Sword = i32;
24+
pub type Elf32_Word = u32;
25+
26+
pub type Elf64_Addr = u64;
27+
pub type Elf64_Half = u16;
28+
pub type Elf64_Lword = u64;
29+
pub type Elf64_Off = u64;
30+
pub type Elf64_Sword = i32;
31+
pub type Elf64_Sxword = i64;
32+
pub type Elf64_Word = u32;
33+
pub type Elf64_Xword = u64;
34+
35+
cfg_if! {
36+
if #[cfg(target_pointer_width = "64")] {
37+
type Elf_Addr = Elf64_Addr;
38+
type Elf_Half = Elf64_Half;
39+
type Elf_Phdr = Elf64_Phdr;
40+
} else if #[cfg(target_pointer_width = "32")] {
41+
type Elf_Addr = Elf32_Addr;
42+
type Elf_Half = Elf32_Half;
43+
type Elf_Phdr = Elf32_Phdr;
44+
}
45+
}
46+
47+
// link.h
48+
1749
#[cfg_attr(feature = "extra_traits", derive(Debug))]
1850
pub enum timezone {}
1951
impl ::Copy for timezone {}
@@ -233,6 +265,43 @@ s! {
233265
pub piod_addr: *mut ::c_void,
234266
pub piod_len: ::size_t,
235267
}
268+
269+
// elf.h
270+
271+
pub struct Elf32_Phdr {
272+
pub p_type: Elf32_Word,
273+
pub p_offset: Elf32_Off,
274+
pub p_vaddr: Elf32_Addr,
275+
pub p_paddr: Elf32_Addr,
276+
pub p_filesz: Elf32_Word,
277+
pub p_memsz: Elf32_Word,
278+
pub p_flags: Elf32_Word,
279+
pub p_align: Elf32_Word,
280+
}
281+
282+
pub struct Elf64_Phdr {
283+
pub p_type: Elf64_Word,
284+
pub p_flags: Elf64_Word,
285+
pub p_offset: Elf64_Off,
286+
pub p_vaddr: Elf64_Addr,
287+
pub p_paddr: Elf64_Addr,
288+
pub p_filesz: Elf64_Xword,
289+
pub p_memsz: Elf64_Xword,
290+
pub p_align: Elf64_Xword,
291+
}
292+
293+
// link.h
294+
295+
pub struct dl_phdr_info {
296+
pub dlpi_addr: Elf_Addr,
297+
pub dlpi_name: *const ::c_char,
298+
pub dlpi_phdr: *const Elf_Phdr,
299+
pub dlpi_phnum: Elf_Half,
300+
pub dlpi_adds: ::c_ulonglong,
301+
pub dlpi_subs: ::c_ulonglong,
302+
pub dlpi_tls_modid: usize,
303+
pub dlpi_tls_data: *mut ::c_void,
304+
}
236305
}
237306

238307
s_no_extra_traits! {
@@ -1514,6 +1583,18 @@ extern "C" {
15141583

15151584
pub fn ntp_adjtime(buf: *mut timex) -> ::c_int;
15161585
pub fn ntp_gettime(buf: *mut ntptimeval) -> ::c_int;
1586+
1587+
// #include <link.h>
1588+
pub fn dl_iterate_phdr(
1589+
callback: ::Option<
1590+
unsafe extern "C" fn(
1591+
info: *mut dl_phdr_info,
1592+
size: usize,
1593+
data: *mut ::c_void,
1594+
) -> ::c_int,
1595+
>,
1596+
data: *mut ::c_void,
1597+
) -> ::c_int;
15171598
}
15181599

15191600
#[link(name = "rt")]

src/unix/bsd/netbsdlike/netbsd/mod.rs

+79
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,36 @@ pub type vm_size_t = ::uintptr_t;
1111
pub type lwpid_t = ::c_uint;
1212
pub type shmatt_t = ::c_uint;
1313

14+
// elf.h
15+
16+
pub type Elf32_Addr = u32;
17+
pub type Elf32_Half = u16;
18+
pub type Elf32_Lword = u64;
19+
pub type Elf32_Off = u32;
20+
pub type Elf32_Sword = i32;
21+
pub type Elf32_Word = u32;
22+
23+
pub type Elf64_Addr = u64;
24+
pub type Elf64_Half = u16;
25+
pub type Elf64_Lword = u64;
26+
pub type Elf64_Off = u64;
27+
pub type Elf64_Sword = i32;
28+
pub type Elf64_Sxword = i64;
29+
pub type Elf64_Word = u32;
30+
pub type Elf64_Xword = u64;
31+
32+
cfg_if! {
33+
if #[cfg(target_pointer_width = "64")] {
34+
type Elf_Addr = Elf64_Addr;
35+
type Elf_Half = Elf64_Half;
36+
type Elf_Phdr = Elf64_Phdr;
37+
} else if #[cfg(target_pointer_width = "32")] {
38+
type Elf_Addr = Elf32_Addr;
39+
type Elf_Half = Elf32_Half;
40+
type Elf_Phdr = Elf32_Phdr;
41+
}
42+
}
43+
1444
impl siginfo_t {
1545
pub unsafe fn si_value(&self) -> ::sigval {
1646
#[repr(C)]
@@ -341,6 +371,42 @@ s! {
341371
pub time_state: ::c_int,
342372
}
343373

374+
// elf.h
375+
376+
pub struct Elf32_Phdr {
377+
pub p_type: Elf32_Word,
378+
pub p_offset: Elf32_Off,
379+
pub p_vaddr: Elf32_Addr,
380+
pub p_paddr: Elf32_Addr,
381+
pub p_filesz: Elf32_Word,
382+
pub p_memsz: Elf32_Word,
383+
pub p_flags: Elf32_Word,
384+
pub p_align: Elf32_Word,
385+
}
386+
387+
pub struct Elf64_Phdr {
388+
pub p_type: Elf64_Word,
389+
pub p_flags: Elf64_Word,
390+
pub p_offset: Elf64_Off,
391+
pub p_vaddr: Elf64_Addr,
392+
pub p_paddr: Elf64_Addr,
393+
pub p_filesz: Elf64_Xword,
394+
pub p_memsz: Elf64_Xword,
395+
pub p_align: Elf64_Xword,
396+
}
397+
398+
// link.h
399+
400+
pub struct dl_phdr_info {
401+
pub dlpi_addr: Elf_Addr,
402+
pub dlpi_name: *const ::c_char,
403+
pub dlpi_phdr: *const Elf_Phdr,
404+
pub dlpi_phnum: Elf_Half,
405+
pub dlpi_adds: ::c_ulonglong,
406+
pub dlpi_subs: ::c_ulonglong,
407+
pub dlpi_tls_modid: usize,
408+
pub dlpi_tls_data: *mut ::c_void,
409+
}
344410
}
345411

346412
s_no_extra_traits! {
@@ -2002,6 +2068,19 @@ extern "C" {
20022068
needle: *const ::c_void,
20032069
needlelen: ::size_t,
20042070
) -> *mut ::c_void;
2071+
2072+
// link.h
2073+
2074+
pub fn dl_iterate_phdr(
2075+
callback: ::Option<
2076+
unsafe extern "C" fn(
2077+
info: *mut dl_phdr_info,
2078+
size: usize,
2079+
data: *mut ::c_void,
2080+
) -> ::c_int,
2081+
>,
2082+
data: *mut ::c_void,
2083+
) -> ::c_int;
20052084
}
20062085

20072086
#[link(name = "util")]

0 commit comments

Comments
 (0)