From 11e85e42d2dba7c95817c1d39e98ca89c9747dc4 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Tue, 15 Oct 2024 02:46:42 +0200 Subject: [PATCH 01/18] options/posix: avoid redeclaring FILE --- meson.build | 1 + options/ansi/include/stdio.h | 2 +- options/ansi/include/wchar.h | 3 +-- options/internal/include/bits/file.h | 6 ++++++ options/posix/include/bits/posix/posix_stdio.h | 3 +-- 5 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 options/internal/include/bits/file.h diff --git a/meson.build b/meson.build index dfcb054846..e6f522aeaf 100644 --- a/meson.build +++ b/meson.build @@ -371,6 +371,7 @@ if not no_headers 'options/internal/include/bits/nl_item.h', 'options/internal/include/bits/null.h', 'options/internal/include/bits/off_t.h', + 'options/internal/include/bits/file.h', 'options/internal/include/bits/ssize_t.h', 'options/internal/include/bits/sigset_t.h', 'options/internal/include/bits/inline-definition.h', diff --git a/options/ansi/include/stdio.h b/options/ansi/include/stdio.h index 2ec9dcccd6..8b6de9f1c0 100644 --- a/options/ansi/include/stdio.h +++ b/options/ansi/include/stdio.h @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -56,7 +57,6 @@ struct __mlibc_file_base { int __status_bits; }; -typedef struct __mlibc_file_base FILE; typedef off_t fpos_t; /* [C11-7.21.1] I/O related macros */ diff --git a/options/ansi/include/wchar.h b/options/ansi/include/wchar.h index 8fe45d3415..b0d8e537e8 100644 --- a/options/ansi/include/wchar.h +++ b/options/ansi/include/wchar.h @@ -7,6 +7,7 @@ #include #include #include +#include #define WEOF 0xffffffffU @@ -14,8 +15,6 @@ extern "C" { #endif -typedef struct __mlibc_file_base FILE; - typedef struct __mlibc_mbstate mbstate_t; /* MISSING: struct tm */ diff --git a/options/internal/include/bits/file.h b/options/internal/include/bits/file.h new file mode 100644 index 0000000000..44566f7bde --- /dev/null +++ b/options/internal/include/bits/file.h @@ -0,0 +1,6 @@ +#ifndef MLIBC_FILE_T_H +#define MLIBC_FILE_T_H + +typedef struct __mlibc_file_base FILE; + +#endif /* MLIBC_FILE_T_H */ diff --git a/options/posix/include/bits/posix/posix_stdio.h b/options/posix/include/bits/posix/posix_stdio.h index 302b1a458a..360be7c626 100644 --- a/options/posix/include/bits/posix/posix_stdio.h +++ b/options/posix/include/bits/posix/posix_stdio.h @@ -5,6 +5,7 @@ #include #include #include +#include /* MISSING: var_list */ @@ -16,8 +17,6 @@ extern "C" { #ifndef __MLIBC_ABI_ONLY -typedef struct __mlibc_file_base FILE; - int fileno(FILE *__file); FILE *fdopen(int __fd, const char *__mode); From 4109e68432a523b03b535270d5268cec549fb161 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Fri, 18 Oct 2024 03:46:53 +0200 Subject: [PATCH 02/18] options/ansi: avoid redeclaring mbstate_t --- options/ansi/include/uchar.h | 2 -- options/ansi/include/wchar.h | 2 -- options/internal/include/bits/mbstate.h | 4 ++-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/options/ansi/include/uchar.h b/options/ansi/include/uchar.h index 7c3b7a7e6a..b430c6c6e6 100644 --- a/options/ansi/include/uchar.h +++ b/options/ansi/include/uchar.h @@ -13,8 +13,6 @@ typedef __CHAR16_TYPE__ char16_t; typedef __CHAR32_TYPE__ char32_t; #endif /* __cplusplus */ -typedef struct __mlibc_mbstate mbstate_t; - #ifndef __MLIBC_ABI_ONLY size_t c32rtomb(char *__pmb, char32_t __c32, mbstate_t *__ps); diff --git a/options/ansi/include/wchar.h b/options/ansi/include/wchar.h index b0d8e537e8..3921e5fa8e 100644 --- a/options/ansi/include/wchar.h +++ b/options/ansi/include/wchar.h @@ -15,8 +15,6 @@ extern "C" { #endif -typedef struct __mlibc_mbstate mbstate_t; - /* MISSING: struct tm */ #ifndef __MLIBC_ABI_ONLY diff --git a/options/internal/include/bits/mbstate.h b/options/internal/include/bits/mbstate.h index 31eb9f42da..e65604b860 100644 --- a/options/internal/include/bits/mbstate.h +++ b/options/internal/include/bits/mbstate.h @@ -1,11 +1,11 @@ #ifndef MLIBC_MBSTATE_H #define MLIBC_MBSTATE_H -struct __mlibc_mbstate { +typedef struct __mlibc_mbstate { short __progress; short __shift; unsigned int __cpoint; -}; +} mbstate_t; #define __MLIBC_MBSTATE_INITIALIZER {0, 0, 0} From 908a3b5ac43702a66bee94adb3fdf87ba1183c88 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Fri, 18 Oct 2024 03:43:39 +0200 Subject: [PATCH 03/18] options/ansi: avoid redeclaring wc{trans,type}_t --- meson.build | 2 ++ options/ansi/include/wctype.h | 5 ++--- options/internal/include/bits/wctrans_t.h | 6 ++++++ options/internal/include/bits/wctype_t.h | 7 +++++++ options/posix/include/bits/posix/posix_wctype.h | 5 ++--- 5 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 options/internal/include/bits/wctrans_t.h create mode 100644 options/internal/include/bits/wctype_t.h diff --git a/meson.build b/meson.build index e6f522aeaf..ab1fa1dfe2 100644 --- a/meson.build +++ b/meson.build @@ -363,6 +363,8 @@ if not no_headers 'options/internal/include/bits/wchar_t.h', 'options/internal/include/bits/wchar.h', 'options/internal/include/bits/wint_t.h', + 'options/internal/include/bits/wctrans_t.h', + 'options/internal/include/bits/wctype_t.h', 'options/internal/include/bits/size_t.h', 'options/internal/include/bits/types.h', 'options/internal/include/bits/ensure.h', diff --git a/options/ansi/include/wctype.h b/options/ansi/include/wctype.h index 4b12e5c696..ab66f15662 100644 --- a/options/ansi/include/wctype.h +++ b/options/ansi/include/wctype.h @@ -3,14 +3,13 @@ #include #include +#include +#include #ifdef __cplusplus extern "C" { #endif -typedef unsigned long wctype_t; -typedef unsigned long wctrans_t; - #ifndef __MLIBC_ABI_ONLY /* [C11/7.30.2.2] Extensible wide character classification functions. */ diff --git a/options/internal/include/bits/wctrans_t.h b/options/internal/include/bits/wctrans_t.h new file mode 100644 index 0000000000..acd58783c7 --- /dev/null +++ b/options/internal/include/bits/wctrans_t.h @@ -0,0 +1,6 @@ +#ifndef MLIBC_WCTRANS_T_H +#define MLIBC_WCTRANS_T_H + +typedef unsigned long wctrans_t; + +#endif /* MLIBC_WCTRANS_T_H */ diff --git a/options/internal/include/bits/wctype_t.h b/options/internal/include/bits/wctype_t.h new file mode 100644 index 0000000000..7cb6de42ea --- /dev/null +++ b/options/internal/include/bits/wctype_t.h @@ -0,0 +1,7 @@ +#ifndef MLIBC_WCTYPE_T_H +#define MLIBC_WCTYPE_T_H + +typedef unsigned long wctype_t; + +#endif /* MLIBC_WCTYPE_T_H */ + diff --git a/options/posix/include/bits/posix/posix_wctype.h b/options/posix/include/bits/posix/posix_wctype.h index ffc8d41b2c..3c4bd7aaf0 100644 --- a/options/posix/include/bits/posix/posix_wctype.h +++ b/options/posix/include/bits/posix/posix_wctype.h @@ -3,6 +3,8 @@ #include #include +#include +#include #ifdef __cplusplus extern "C" { @@ -10,9 +12,6 @@ extern "C" { #ifndef __MLIBC_ABI_ONLY -typedef unsigned long wctype_t; -typedef unsigned long wctrans_t; - int iswalnum_l(wint_t __wc, locale_t __loc); int iswblank_l(wint_t __wc, locale_t __loc); int iswcntrl_l(wint_t __wc, locale_t __loc); From 3e2192cd0e8c0e4e2bc606f563bc4c1731acecba Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Fri, 18 Oct 2024 03:02:46 +0200 Subject: [PATCH 04/18] options: remove trailing commas --- abis/linux/xattr.h | 2 +- options/ansi/include/threads.h | 4 ++-- options/elf/include/elf.h | 14 +++++++------- options/glibc/include/sys/personality.h | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/abis/linux/xattr.h b/abis/linux/xattr.h index c0e7fbebde..89450e3238 100644 --- a/abis/linux/xattr.h +++ b/abis/linux/xattr.h @@ -12,7 +12,7 @@ enum { XATTR_CREATE = 1, #define XATTR_CREATE XATTR_CREATE - XATTR_REPLACE = 2, + XATTR_REPLACE = 2 #define XATTR_REPLACE XATTR_REPLACE }; # define __UAPI_DEF_XATTR 0 diff --git a/options/ansi/include/threads.h b/options/ansi/include/threads.h index df9af59678..dab2c9b256 100644 --- a/options/ansi/include/threads.h +++ b/options/ansi/include/threads.h @@ -10,7 +10,7 @@ extern "C" { enum { mtx_plain, mtx_recursive, - mtx_timed, + mtx_timed }; enum { @@ -18,7 +18,7 @@ enum { thrd_timedout, thrd_busy, thrd_error, - thrd_nomem, + thrd_nomem }; typedef struct __mlibc_thread_data *thrd_t; diff --git a/options/elf/include/elf.h b/options/elf/include/elf.h index 0188702c38..0c89dacb68 100644 --- a/options/elf/include/elf.h +++ b/options/elf/include/elf.h @@ -148,7 +148,7 @@ enum { ET_REL = 1, ET_EXEC = 2, ET_DYN = 3, - ET_CORE = 4, + ET_CORE = 4 }; enum { @@ -157,7 +157,7 @@ enum { }; enum { - STN_UNDEF = 0, + STN_UNDEF = 0 }; typedef struct { @@ -239,7 +239,7 @@ enum { R_X86_64_PC64 = 24, R_X86_64_GOTPC32 = 26, R_X86_64_TLSDESC = 36, - R_X86_64_IRELATIVE = 37, + R_X86_64_IRELATIVE = 37 }; enum { @@ -254,7 +254,7 @@ enum { R_386_TLS_DTPMOD32 = 35, R_386_TLS_DTPOFF32 = 36, R_386_TLS_DESC = 41, - R_386_IRELATIVE = 42, + R_386_IRELATIVE = 42 }; enum { @@ -268,7 +268,7 @@ enum { R_AARCH64_TLS_DTPREL64 = 1029, R_AARCH64_TLS_TPREL64 = 1030, R_AARCH64_TLSDESC = 1031, - R_AARCH64_IRELATIVE = 1032, + R_AARCH64_IRELATIVE = 1032 }; #define R_AARCH64_TLS_DTPREL R_AARCH64_TLS_DTPREL64 @@ -303,7 +303,7 @@ enum { R_68K_TLS_DTPMOD32 = 40, R_68K_TLS_DTPREL32= 41, - R_68K_TLS_TPREL32= 42, + R_68K_TLS_TPREL32= 42 }; typedef struct { @@ -370,7 +370,7 @@ enum { PT_LOPROC = 0x70000000, PT_ARM_EXIDX = 0x70000001, PT_RISCV_ATTRIBUTES = 0x70000003, - PT_HIPROC = 0x7fffffff, + PT_HIPROC = 0x7fffffff }; enum { diff --git a/options/glibc/include/sys/personality.h b/options/glibc/include/sys/personality.h index cbaff129ee..f4173eee75 100644 --- a/options/glibc/include/sys/personality.h +++ b/options/glibc/include/sys/personality.h @@ -16,7 +16,7 @@ enum { SHORT_INODE = 0x1000000, WHOLE_SECONDS = 0x2000000, STICKY_TIMEOUTS = 0x4000000, - ADDR_LIMIT_3GB = 0x8000000, + ADDR_LIMIT_3GB = 0x8000000 }; enum { @@ -42,7 +42,7 @@ enum { PER_UW7 = 0x000e | STICKY_TIMEOUTS | MMAP_PAGE_ZERO, PER_OSF4 = 0x000f, PER_HPUX = 0x0010, - PER_MASK = 0x00ff, + PER_MASK = 0x00ff }; #ifndef __MLIBC_ABI_ONLY From 6b4edd65cb5f0fae03a320f28f3bb54b6cefd864 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Fri, 18 Oct 2024 03:10:50 +0200 Subject: [PATCH 05/18] options/internal: remove static asserts in c89 mode --- options/internal/include/bits/types.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/options/internal/include/bits/types.h b/options/internal/include/bits/types.h index 03004bc3c3..13936f5692 100644 --- a/options/internal/include/bits/types.h +++ b/options/internal/include/bits/types.h @@ -326,14 +326,13 @@ typedef __SIZE_TYPE__ __mlibc_size; #if defined(__cpp_static_assert) # define __MLIBC_STATIC_ASSERT(c, text) static_assert(c, text) -#elif !defined(__cplusplus) -# define __MLIBC_STATIC_ASSERT(c, text) _Static_assert(c, text) #else -# define __MLIBC_STATIC_ASSERT(c, text) +/* _Static_assert is an extension in C89/C99. */ +# define __MLIBC_STATIC_ASSERT(c, text) __extension__ _Static_assert(c, text) #endif #define __MLIBC_CHECK_TYPE(T1, T2) __MLIBC_STATIC_ASSERT(sizeof(T1) == sizeof(T2),\ - #T1 " != " #T2); + #T1 " != " #T2) /* Least-width. */ __MLIBC_CHECK_TYPE(__mlibc_int8, __INT_LEAST8_TYPE__); From acee69b7439d8d4f7ea5863686ef7b53b02261f6 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Fri, 18 Oct 2024 03:30:27 +0200 Subject: [PATCH 06/18] sysdeps/linux: suppress pedantic checks on syscall macro --- sysdeps/linux/include/bits/syscall.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sysdeps/linux/include/bits/syscall.h b/sysdeps/linux/include/bits/syscall.h index 34adfad141..680bb8c299 100644 --- a/sysdeps/linux/include/bits/syscall.h +++ b/sysdeps/linux/include/bits/syscall.h @@ -62,6 +62,15 @@ long syscall(long n, Arg0 a0, Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 } /* extern C++ */ #else +/* + * Variadic macros are not supported in C89. + * glibc implements syscall() as a variadic function, which we've ruled out. + * musl uses them without checking the C standard in use. So suppressing + * the check here seems reasonable. + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wvariadic-macros" + /* These syscall macros were copied from musl. */ #define __scc(x) ((__sc_word_t)(x)) #define __syscall0(n) __do_syscall0(n) @@ -80,6 +89,8 @@ long syscall(long n, Arg0 a0, Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 #define __syscall(...) __SYSCALL_DISP(__syscall,__VA_ARGS__) #define syscall(...) __do_syscall_ret(__syscall(__VA_ARGS__)) +#pragma GCC diagnostic pop + #endif #ifdef __cplusplus From f5296f7bf4029e7ed4650709f8144fd8fdfa17ab Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Sun, 20 Oct 2024 13:12:56 +0200 Subject: [PATCH 07/18] options/posix: avoid redeclaring intptr_t --- options/posix/include/unistd.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/options/posix/include/unistd.h b/options/posix/include/unistd.h index 907bad33d4..97bbaae63c 100644 --- a/options/posix/include/unistd.h +++ b/options/posix/include/unistd.h @@ -241,9 +241,14 @@ extern "C" { #define L_ctermid 20 -#ifndef intptr_t +/* + * Solving this likely requires us to 'factor out' the typedef into a new + * header file, or use a mechanism like musl's __NEED_intptr_t. + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" typedef __mlibc_intptr intptr_t; -#endif +#pragma GCC diagnostic pop #ifndef __MLIBC_ABI_ONLY From b34b5518fa7c05561fcfd770ff5cf739b5f891b2 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Sun, 20 Oct 2024 13:20:17 +0200 Subject: [PATCH 08/18] options/posix: avoid anonymous union in fd_set --- options/posix/generic/sys-select.cpp | 8 ++++---- options/posix/include/bits/posix/fd_set.h | 6 +----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/options/posix/generic/sys-select.cpp b/options/posix/generic/sys-select.cpp index 62e116ee92..8fbc468e10 100644 --- a/options/posix/generic/sys-select.cpp +++ b/options/posix/generic/sys-select.cpp @@ -11,18 +11,18 @@ void __FD_CLR(int fd, fd_set *set) { __ensure(fd < FD_SETSIZE); - set->__mlibc_elems[fd / 8] &= ~(1 << (fd % 8)); + set->fds_bits[fd / 8] &= ~(1 << (fd % 8)); } int __FD_ISSET(int fd, fd_set *set) { __ensure(fd < FD_SETSIZE); - return set->__mlibc_elems[fd / 8] & (1 << (fd % 8)); + return set->fds_bits[fd / 8] & (1 << (fd % 8)); } void __FD_SET(int fd, fd_set *set) { __ensure(fd < FD_SETSIZE); - set->__mlibc_elems[fd / 8] |= 1 << (fd % 8); + set->fds_bits[fd / 8] |= 1 << (fd % 8); } void __FD_ZERO(fd_set *set) { - memset(set->__mlibc_elems, 0, sizeof(fd_set)); + memset(set->fds_bits, 0, sizeof(fd_set)); } int select(int num_fds, fd_set *__restrict read_set, fd_set *__restrict write_set, diff --git a/options/posix/include/bits/posix/fd_set.h b/options/posix/include/bits/posix/fd_set.h index 6e5c13db06..5f4ea26fd9 100644 --- a/options/posix/include/bits/posix/fd_set.h +++ b/options/posix/include/bits/posix/fd_set.h @@ -4,11 +4,7 @@ #include typedef struct { - union { - __mlibc_uint8 __mlibc_elems[128]; - /* Some programs require the fds_bits field to be present */ - __mlibc_uint8 fds_bits[128]; - }; + __mlibc_uint8 fds_bits[128]; } fd_set; #endif /* MLIBC_FD_SET_H */ From 4d701995c916ff12045011d3056c5881c1830671 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Sun, 20 Oct 2024 18:51:14 +0200 Subject: [PATCH 09/18] options/posix: use __extension__ in tcp/udp headers --- options/posix/include/netinet/tcp.h | 2 +- options/posix/include/netinet/udp.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/options/posix/include/netinet/tcp.h b/options/posix/include/netinet/tcp.h index 0034aa22b6..bc1431e79c 100644 --- a/options/posix/include/netinet/tcp.h +++ b/options/posix/include/netinet/tcp.h @@ -54,7 +54,7 @@ struct tcp_info { uint8_t tcpi_probes; uint8_t tcpi_backoff; uint8_t tcpi_options; - uint8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4; + __extension__ uint8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4; uint32_t tcpi_rto; uint32_t tcpi_ato; diff --git a/options/posix/include/netinet/udp.h b/options/posix/include/netinet/udp.h index 1d107407db..1563f1c52a 100644 --- a/options/posix/include/netinet/udp.h +++ b/options/posix/include/netinet/udp.h @@ -7,8 +7,8 @@ extern "C" { #endif -struct udphdr { - union { +__extension__ struct udphdr { + __extension__ union { struct { uint16_t uh_sport; uint16_t uh_dport; From 34613cb38dda201d9d465ed384752b0d876f9095 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Sun, 20 Oct 2024 18:27:33 +0200 Subject: [PATCH 10/18] options/posix: gate zero size array behind _GNU_SOURCE --- options/posix/include/fcntl.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/options/posix/include/fcntl.h b/options/posix/include/fcntl.h index bb0f47d8a1..079a6820c7 100644 --- a/options/posix/include/fcntl.h +++ b/options/posix/include/fcntl.h @@ -49,17 +49,20 @@ int posix_fallocate(int __fd, off_t __offset, off_t __size); #endif /* !__MLIBC_ABI_ONLY */ /* This is a linux extension */ - +#ifdef _GNU_SOURCE struct file_handle { unsigned int handle_bytes; int handle_type; unsigned char f_handle[0]; }; +#endif #ifndef __MLIBC_ABI_ONLY +#ifdef _GNU_SOURCE int name_to_handle_at(int __dirfd, const char *__path, struct file_handle *__handle, int *__mount_id, int __flags); int open_by_handle_at(int __dirfd, struct file_handle *__handle, int __flags); +#endif ssize_t splice(int __fd_in, off_t *__off_in, int __fd_out, off_t *__off_out, size_t __len, unsigned int __flags); ssize_t vmsplice(int __fd, const struct iovec *__iov, size_t __nr_segs, unsigned int __flags); From 4cf41c162f00c299e6b776d62b6d0b3975b6146b Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Sun, 20 Oct 2024 18:48:51 +0200 Subject: [PATCH 11/18] abis/linux: remove repeated #defines These are defined in libc-compat.h too. --- abis/linux/in.h | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/abis/linux/in.h b/abis/linux/in.h index 53f4944c0a..39f7d88ccc 100644 --- a/abis/linux/in.h +++ b/abis/linux/in.h @@ -199,20 +199,4 @@ struct group_source_req { #define MCAST_JOIN_SOURCE_GROUP 46 #define MCAST_LEAVE_SOURCE_GROUP 47 -/* These defines are needed for compatibility with Linux kernel headers. */ -#define __UAPI_DEF_IN_ADDR 0 -#define __UAPI_DEF_IN_IPPROTO 0 -#define __UAPI_DEF_IN_PKTINFO 0 -#define __UAPI_DEF_IP_MREQ 0 -#define __UAPI_DEF_SOCKADDR_IN 0 -#define __UAPI_DEF_IN_CLASS 0 -#define __UAPI_DEF_IN6_ADDR 0 -#define __UAPI_DEF_IN6_ADDR_ALT 0 -#define __UAPI_DEF_SOCKADDR_IN6 0 -#define __UAPI_DEF_IPV6_MREQ 0 -#define __UAPI_DEF_IPPROTO_V6 0 -#define __UAPI_DEF_IPV6_OPTIONS 0 -#define __UAPI_DEF_IN6_PKTINFO 0 -#define __UAPI_DEF_IP6_MTUINFO 0 - #endif /* _ABITBITS_IN_H */ From b25bb49655cb605e229cd8a549143596cecf9412 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Sun, 20 Oct 2024 19:07:42 +0200 Subject: [PATCH 12/18] options/linux: suppress c89 pedantic warning on flexible array member --- options/linux/include/sys/inotify.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/options/linux/include/sys/inotify.h b/options/linux/include/sys/inotify.h index 02f4b36016..bf9c7c5fef 100644 --- a/options/linux/include/sys/inotify.h +++ b/options/linux/include/sys/inotify.h @@ -43,7 +43,15 @@ struct inotify_event { unsigned int mask; unsigned int cookie; unsigned int len; + +/* + * glibc uses a flexible array member here, but we get a warning and they don't: + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117241 + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" char name[]; +#pragma GCC diagnostic pop }; #ifndef __MLIBC_ABI_ONLY From 8f646b4f6368a7e043442a5d934e9f91a3388893 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Sun, 20 Oct 2024 20:13:59 +0200 Subject: [PATCH 13/18] options/glibc: fix elf_greg_t definition --- options/glibc/include/sys/procfs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/glibc/include/sys/procfs.h b/options/glibc/include/sys/procfs.h index b13a81d6c5..82fee9a666 100644 --- a/options/glibc/include/sys/procfs.h +++ b/options/glibc/include/sys/procfs.h @@ -9,7 +9,7 @@ extern "C" { #endif -typedef unsigned long long elf_greg_t; +typedef unsigned long elf_greg_t; #define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof (elf_greg_t)) typedef elf_greg_t elf_gregset_t[ELF_NGREG]; From 879225a5f69c53fbc95c14391e521a21f92ca716 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Sun, 20 Oct 2024 20:12:27 +0200 Subject: [PATCH 14/18] options/glibc: avoid redeclaring elf_fpregset_t --- options/glibc/include/sys/user.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/options/glibc/include/sys/user.h b/options/glibc/include/sys/user.h index 9a07ac6146..7963e68341 100644 --- a/options/glibc/include/sys/user.h +++ b/options/glibc/include/sys/user.h @@ -7,12 +7,14 @@ extern "C" { #endif -typedef struct user_fpregs_struct { +/* TODO: This assumes x86-64. */ + +struct user_fpregs_struct { uint16_t cwd, swd, ftw, fop; uint64_t rip, rdp; uint32_t mxcsr, mxcr_mask; uint32_t st_space[32], xmm_space[64], padding[24]; -} elf_fpregset_t; +}; struct user_regs_struct { unsigned long r15, r14, r13, r12, rbp, rbx, r11, r10, r9, r8; From c7ea8a53caac7c01e1eba06123c78f759104a808 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Sun, 20 Oct 2024 20:18:52 +0200 Subject: [PATCH 15/18] options/linux: suppress warning in struct sysinfo --- options/linux/include/sys/sysinfo.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/options/linux/include/sys/sysinfo.h b/options/linux/include/sys/sysinfo.h index 6d4b203494..9f20461ffe 100644 --- a/options/linux/include/sys/sysinfo.h +++ b/options/linux/include/sys/sysinfo.h @@ -5,6 +5,8 @@ extern "C" { #endif +/* TODO: This is from the Linux ABI. Make this an abi-bit. */ + struct sysinfo { long uptime; unsigned long loads[3]; @@ -18,7 +20,12 @@ struct sysinfo { unsigned long totalhigh; unsigned long freehigh; unsigned int mem_unit; + + /* This is how the kernel header defines it, so suppress the warning. */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" char _f[20 - 2 * sizeof(long) - sizeof(int)]; /* Padding to 64 bytes according to my man page */ +#pragma GCC diagnostic pop }; #ifndef __MLIBC_ABI_ONLY From 4ebd671c9d0f0bf2bdd5df3f0d8b9fe95d81bf82 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Sun, 20 Oct 2024 22:22:53 +0200 Subject: [PATCH 16/18] abis/linux: fix struct stat on m68k --- abis/linux/stat.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/abis/linux/stat.h b/abis/linux/stat.h index 7f4df9f90d..c4b50abc38 100644 --- a/abis/linux/stat.h +++ b/abis/linux/stat.h @@ -119,25 +119,24 @@ struct stat { #elif defined (__m68k__) struct stat { - unsigned long long st_dev; + dev_t st_dev; unsigned char __st_dev_padding[2]; unsigned long __st_ino; - unsigned int st_mode; - unsigned int st_nlink; - unsigned long st_uid; - unsigned long st_gid; - unsigned long long st_rdev; + mode_t st_mode; + nlink_t st_nlink; + uid_t st_uid; + gid_t st_gid; + dev_t st_rdev; unsigned char __st_rdev_padding; - long long st_size; - unsigned long st_blksize; - unsigned long long st_blocks; + long long st_size; /* TODO: off64_t? */ + blksize_t st_blksize; + blkcnt_t st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; - unsigned long long st_ino; + ino_t st_ino; }; - #endif #define stat64 stat From 091620b16e6668e4cfe773c54657b225250237a6 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Sun, 20 Oct 2024 23:59:36 +0200 Subject: [PATCH 17/18] abis/linux: remove zero size array --- abis/linux/signal.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/abis/linux/signal.h b/abis/linux/signal.h index 76339af9e7..65e575b895 100644 --- a/abis/linux/signal.h +++ b/abis/linux/signal.h @@ -362,7 +362,7 @@ enum { #define REG_TP REG_TP REG_S0 = 8, #define REG_S0 REG_S0 - REG_A0 = 10, + REG_A0 = 10 #define REG_A0 REG_A0 }; @@ -400,7 +400,10 @@ typedef struct __ucontext { struct ucontext *uc_link; stack_t uc_stack; sigset_t uc_sigmask; - uint8_t __unused[1024 / 8 - sizeof(sigset_t)]; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" + uint8_t __unused[1024 / 8 - sizeof(sigset_t)]; +#pragma GCC diagnostic pop mcontext_t uc_mcontext; } ucontext_t; From 44380b9592596a62de2b2714c13da979d70afa01 Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Tue, 15 Oct 2024 02:14:41 +0200 Subject: [PATCH 18/18] ci: check public headers compile with c89 pedantic errors --- .github/workflows/ci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2aed69db9d..b564bffc0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,6 +53,23 @@ jobs: - name: Build mlibc run: 'xbstrap install ${{matrix.builds}}' working-directory: build/ + - name: Check public headers conform to C89/C99/C11 + if: ${{matrix.builds == 'mlibc-headers-only'}} + working-directory: build/ + run: | + GCC_ARCH="${{matrix.arch}}" + case "$GCC_ARCH" in + "x86") + GCC_ARCH="i686" + ;; + esac + ALL_HDRS="packages/${{matrix.builds}}/usr/include/**.h" + GCC_ARGS="$GCC_ARCH-linux-mlibc-gcc -x c -S /dev/null -o /dev/null -I packages/${{matrix.builds}}/usr/include -I packages/linux-headers/usr/include -nostdlib -Werror -Wpedantic -Wsystem-headers" + + # For C89, exclude complex.h, and -Wlong-long + printf -- '-include\0%s\0' $ALL_HDRS | sed 's/complex.h/stdio.h/' | xargs -0 $GCC_ARGS -std=c89 -Wno-long-long + printf -- '-include\0%s\0' $ALL_HDRS | xargs -0 $GCC_ARGS -std=c99 + printf -- '-include\0%s\0' $ALL_HDRS | xargs -0 $GCC_ARGS -std=c11 - name: Test mlibc run: 'meson test -v -C pkg-builds/${{matrix.builds}}' working-directory: build/