Skip to content

Commit

Permalink
Merge pull request #1159 from 64/c89-headers
Browse files Browse the repository at this point in the history
treewide: make public headers compile with c89/c99/c11 pedantic errors
  • Loading branch information
Dennisbonke authored Oct 24, 2024
2 parents c8f64b9 + 44380b9 commit 5f6579a
Show file tree
Hide file tree
Showing 31 changed files with 128 additions and 80 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
16 changes: 0 additions & 16 deletions abis/linux/in.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
7 changes: 5 additions & 2 deletions abis/linux/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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;

Expand Down
21 changes: 10 additions & 11 deletions abis/linux/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion abis/linux/xattr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -371,6 +373,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',
Expand Down
2 changes: 1 addition & 1 deletion options/ansi/include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <abi-bits/seek-whence.h>
#include <bits/null.h>
#include <bits/file.h>
#include <bits/size_t.h>
#include <mlibc-config.h>

Expand Down Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions options/ansi/include/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ extern "C" {
enum {
mtx_plain,
mtx_recursive,
mtx_timed,
mtx_timed
};

enum {
thrd_success,
thrd_timedout,
thrd_busy,
thrd_error,
thrd_nomem,
thrd_nomem
};

typedef struct __mlibc_thread_data *thrd_t;
Expand Down
2 changes: 0 additions & 2 deletions options/ansi/include/uchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions options/ansi/include/wchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
#include <bits/wchar.h>
#include <bits/wint_t.h>
#include <bits/mbstate.h>
#include <bits/file.h>

#define WEOF 0xffffffffU

#ifdef __cplusplus
extern "C" {
#endif

typedef struct __mlibc_file_base FILE;

typedef struct __mlibc_mbstate mbstate_t;

/* MISSING: struct tm */

#ifndef __MLIBC_ABI_ONLY
Expand Down
5 changes: 2 additions & 3 deletions options/ansi/include/wctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

#include <mlibc-config.h>
#include <bits/wint_t.h>
#include <bits/wctype_t.h>
#include <bits/wctrans_t.h>

#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. */
Expand Down
14 changes: 7 additions & 7 deletions options/elf/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ enum {
ET_REL = 1,
ET_EXEC = 2,
ET_DYN = 3,
ET_CORE = 4,
ET_CORE = 4
};

enum {
Expand All @@ -157,7 +157,7 @@ enum {
};

enum {
STN_UNDEF = 0,
STN_UNDEF = 0
};

typedef struct {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -370,7 +370,7 @@ enum {
PT_LOPROC = 0x70000000,
PT_ARM_EXIDX = 0x70000001,
PT_RISCV_ATTRIBUTES = 0x70000003,
PT_HIPROC = 0x7fffffff,
PT_HIPROC = 0x7fffffff
};

enum {
Expand Down
4 changes: 2 additions & 2 deletions options/glibc/include/sys/personality.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum {
SHORT_INODE = 0x1000000,
WHOLE_SECONDS = 0x2000000,
STICKY_TIMEOUTS = 0x4000000,
ADDR_LIMIT_3GB = 0x8000000,
ADDR_LIMIT_3GB = 0x8000000
};

enum {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion options/glibc/include/sys/procfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 4 additions & 2 deletions options/glibc/include/sys/user.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions options/internal/include/bits/file.h
Original file line number Diff line number Diff line change
@@ -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 */
4 changes: 2 additions & 2 deletions options/internal/include/bits/mbstate.h
Original file line number Diff line number Diff line change
@@ -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}

Expand Down
7 changes: 3 additions & 4 deletions options/internal/include/bits/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down
6 changes: 6 additions & 0 deletions options/internal/include/bits/wctrans_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef MLIBC_WCTRANS_T_H
#define MLIBC_WCTRANS_T_H

typedef unsigned long wctrans_t;

#endif /* MLIBC_WCTRANS_T_H */
7 changes: 7 additions & 0 deletions options/internal/include/bits/wctype_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef MLIBC_WCTYPE_T_H
#define MLIBC_WCTYPE_T_H

typedef unsigned long wctype_t;

#endif /* MLIBC_WCTYPE_T_H */

8 changes: 8 additions & 0 deletions options/linux/include/sys/inotify.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 5f6579a

Please sign in to comment.