Merge pull request #290 from Geertiebear/features_fix

Replace bits/features.h and fix various issues around option disabling.
This commit is contained in:
Alexander van der Grinten 2021-10-24 17:52:28 +02:00 committed by GitHub
commit e062d60007
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 126 additions and 100 deletions

View file

@ -3,7 +3,6 @@
#include <stdint.h>
#include <time.h>
#include <bits/feature.h>
#include <abi-bits/pid_t.h>
#include <abi-bits/uid_t.h>
#include <bits/size_t.h>

View file

@ -1,8 +1,6 @@
#ifndef _ABIBITS_SIGNAL_H
#define _ABIBITS_SIGNAL_H
#include <bits/feature.h>
#include <abi-bits/pid_t.h>
#include <abi-bits/uid_t.h>
#include <bits/size_t.h>

View file

@ -124,6 +124,7 @@ packages:
- '--buildtype=debugoptimized'
- "-Dbuild_tests=true"
- "-Ddisable_posix_option=true"
- "-Ddisable_linux_option=true"
- '@THIS_SOURCE_DIR@'
environ:
C: 'gcc-10'

View file

@ -1,3 +1,4 @@
#pragma once
#mesondefine MLIBC_SYSTEM_NAME
#mesondefine MLIBC_MAP_DSO_SEGMENTS

View file

@ -10,7 +10,6 @@ libc_include_dirs = [
include_directories('options/internal/include'),
include_directories('options/elf/include'),
include_directories('options/lsb/include'),
include_directories('options/glibc/include'),
include_directories('options/internal' / host_machine.cpu_family() + '-include')
]
@ -30,7 +29,9 @@ disable_posix_option = get_option('disable_posix_option')
disable_linux_option = get_option('disable_linux_option')
disable_iconv_option = get_option('disable_iconv_option')
disable_intl_option = get_option('disable_intl_option')
disable_glibc_option = get_option('disable_glibc_option')
internal_conf = configuration_data()
mlibc_conf = configuration_data()
if not headers_only
cxxshim_dep = subproject('cxxshim').get_variable('cxxshim_dep')
@ -87,7 +88,7 @@ internal_conf.set('MLIBC_STATIC_BUILD', static)
# Process sysdeps first, as sysdeps might want to disable unsupported options.
if host_machine.system() == 'linux'
disable_linux_option = true
disable_linux_headers = true
rtdl_include_dirs += include_directories('sysdeps/linux/include')
libc_include_dirs += include_directories('sysdeps/linux/include')
subdir('sysdeps/linux')
@ -128,6 +129,13 @@ endif
# Configuration based on enabled options.
#----------------------------------------------------------------------------------------
mlibc_conf.set('__MLIBC_ANSI_OPTION', not disable_ansi_option)
mlibc_conf.set('__MLIBC_POSIX_OPTION', not disable_posix_option)
mlibc_conf.set('__MLIBC_LINUX_OPTION', not disable_linux_option)
mlibc_conf.set('__MLIBC_INTL_OPTION', not disable_intl_option)
mlibc_conf.set('__MLIBC_ICONV_OPTION', not disable_iconv_option)
mlibc_conf.set('__MLIBC_GLIBC_OPTION', not disable_glibc_option)
if not disable_ansi_option
rtdl_include_dirs += include_directories('options/ansi/include')
libc_include_dirs += include_directories('options/ansi/include')
@ -147,10 +155,21 @@ if not disable_intl_option
libc_include_dirs += include_directories('options/intl/include')
endif
if not disable_linux_option
rtdl_include_dirs += include_directories('options/linux/include')
libc_include_dirs += include_directories('options/linux/include')
endif
if not disable_glibc_option
rtdl_include_dirs += include_directories('options/glibc/include')
libc_include_dirs += include_directories('options/glibc/include')
endif
rtdl_include_dirs += include_directories('options/linux-headers/include')
libc_include_dirs += include_directories('options/linux-headers/include')
rtdl_include_dirs += include_directories('options/elf/include')
rtdl_include_dirs += include_directories('options/linux/include')
libc_include_dirs += include_directories('options/elf/include')
libc_include_dirs += include_directories('options/linux/include')
libc_include_dirs += include_directories('.')
#----------------------------------------------------------------------------------------
@ -158,6 +177,12 @@ configure_file(input: 'internal-config.h.in',
output: 'internal-config.h',
configuration: internal_conf)
configure_file(input: 'mlibc-config.h.in',
output: 'mlibc-config.h',
configuration: mlibc_conf,
install: true,
install_dir: get_option('includedir'))
internal_sources = [
'options/internal/generic/allocator.cpp',
'options/internal/generic/charcode.cpp',
@ -190,7 +215,6 @@ 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/feature.h',
'options/internal/include/bits/size_t.h',
'options/internal/include/bits/types.h',
'options/internal/include/bits/ensure.h',

View file

@ -7,3 +7,4 @@ option('disable_posix_option', type: 'boolean', value : false)
option('disable_linux_option', type: 'boolean', value : false)
option('disable_iconv_option', type: 'boolean', value : false)
option('disable_intl_option', type: 'boolean', value : false)
option('disable_glibc_option', type: 'boolean', value : false)

11
mlibc-config.h.in Normal file
View file

@ -0,0 +1,11 @@
#ifndef _MLIBC_CONFIG_H
#define _MLIBC_CONFIG_H
#mesondefine __MLIBC_ANSI_OPTION
#mesondefine __MLIBC_POSIX_OPTION
#mesondefine __MLIBC_LINUX_OPTION
#mesondefine __MLIBC_INTL_OPTION
#mesondefine __MLIBC_ICONV_OPTION
#mesondefine __MLIBC_GLIBC_OPTION
#endif // _MLIBC_CONFIG_H

View file

@ -121,7 +121,7 @@ int putenv(char *string) {
} // namespace mlibc
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
int putenv(char *string) {
return mlibc::putenv(string);

View file

@ -4,7 +4,6 @@
#include <string.h>
#include <bits/ensure.h>
#include <bits/feature.h>
#include <mlibc/debug.hpp>
#include <frg/optional.hpp>

View file

@ -6,7 +6,6 @@
#include <stdlib.h>
#include <wchar.h>
#include <ctype.h>
#include <unistd.h>
#include <bits/ensure.h>

View file

@ -20,7 +20,7 @@
#include <mlibc/ansi-sysdeps.hpp>
#include <mlibc/strtofp.hpp>
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
#include <pthread.h>
#endif // __MLIBC_POSIX_OPTION
@ -275,7 +275,7 @@ int system(const char *command) {
return -1;
}
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
pthread_testcancel();
#endif // __MLIBC_POSIX_OPTION

View file

@ -1,7 +1,7 @@
#ifndef _CTYPE_H
#define _CTYPE_H
#include <bits/feature.h>
#include <mlibc-config.h>
#ifdef __cplusplus
extern "C" {
@ -35,7 +35,7 @@ int toupper(int c);
}
#endif
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_ctype.h>
#endif

View file

@ -1,7 +1,6 @@
#ifndef _ERRNO_H
#define _ERRNO_H
#include <bits/feature.h>
#include <abi-bits/errno.h>
// Some programs define their own errno as an "extern int" if it is not a macro.

View file

@ -2,7 +2,7 @@
#ifndef _LOCALE_H
#define _LOCALE_H
#include <bits/feature.h>
#include <mlibc-config.h>
#include <bits/null.h>
@ -65,7 +65,7 @@ struct lconv *localeconv(void);
// posix extension
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_locale.h>
#endif // __MLIBC_POSIX_OPTION

View file

@ -2,7 +2,7 @@
#ifndef _SETJMP_H
#define _SETJMP_H
#include <bits/feature.h>
#include <mlibc-config.h>
#include <bits/machine.h>
#include <abi-bits/signal.h>
@ -27,7 +27,7 @@ typedef struct {
sigset_t sigset;
} sigjmp_buf[1];
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
__attribute__ (( returns_twice )) int sigsetjmp(sigjmp_buf buffer, int savesigs);
__attribute__ (( noreturn )) void siglongjmp(sigjmp_buf buffer, int value);
#endif // __MLIBC_POSIX_OPTION

View file

@ -2,7 +2,7 @@
#define _SIGNAL_H
#include <abi-bits/signal.h>
#include <bits/feature.h>
#include <mlibc-config.h>
#ifdef __cplusplus
extern "C" {
@ -34,7 +34,7 @@ int raise(int sig);
}
#endif
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_signal.h>
#endif

View file

@ -3,9 +3,9 @@
#define _STDIO_H
#include <abi-bits/seek-whence.h>
#include <bits/feature.h>
#include <bits/null.h>
#include <bits/size_t.h>
#include <mlibc-config.h>
// Glibc extensions require ssize_t.
#include <bits/ssize_t.h>
@ -186,7 +186,7 @@ int fputs_unlocked(const char *, FILE *);
}
#endif
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_stdio.h>
#endif

View file

@ -2,7 +2,7 @@
#define _STDLIB_H
#include <alloca.h>
#include <bits/feature.h>
#include <mlibc-config.h>
#include <bits/null.h>
#include <bits/size_t.h>
#include <bits/wchar_t.h>
@ -109,7 +109,7 @@ size_t wcstombs(char *mb_string, const wchar_t *__restrict wc_string, size_t max
}
#endif
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_stdlib.h>
#endif

View file

@ -1,7 +1,7 @@
#ifndef _STRING_H
#define _STRING_H
#include <bits/feature.h>
#include <mlibc-config.h>
#include <bits/null.h>
#include <bits/size_t.h>
@ -64,7 +64,7 @@ int ffsll(long long i);
}
#endif
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_string.h>
#endif

View file

@ -1,11 +1,11 @@
#ifndef _TIME_H
#define _TIME_H
#include <bits/feature.h>
#include <bits/null.h>
#include <bits/size_t.h>
#include <bits/ansi/time_t.h>
#include <bits/ansi/timespec.h>
#include <mlibc-config.h>
// [7.27.1] Components of time
@ -72,7 +72,7 @@ void tzset(void);
// POSIX extensions.
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_time.h>
#endif // __MLIBC_POSIX_OPTION

View file

@ -1,7 +1,7 @@
#ifndef _WCTYPE_H
#define _WCTYPE_H
#include <bits/feature.h>
#include <mlibc-config.h>
#include <bits/wint_t.h>
#ifdef __cplusplus
@ -41,7 +41,7 @@ wint_t towctrans(wint_t, wctrans_t);
}
#endif
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_wctype.h>
#endif

View file

@ -1,10 +1,10 @@
#ifndef _SYS_IOCTL_H
#define _SYS_IOCTL_H
#include <bits/feature.h>
#include <mlibc-config.h>
// On Linux, sys/ioctl.h includes the termios ioctls.
#if __MLIBC_LINUX_OPTION
#ifdef __MLIBC_LINUX_OPTION
# include <asm/ioctls.h>
#endif

View file

@ -1,10 +0,0 @@
#ifndef _BITS_FEATURE_H
#define _BITS_FEATURE_H
// TODO: The files for this macro are chosen somewhat arbitrarily.
// TODO: Choose canonical files (like a bits/posix/alltypes.h)
#define __MLIBC_ANSI_OPTION __has_include(<stdlib.h>)
#define __MLIBC_POSIX_OPTION __has_include(<unistd.h>)
#define __MLIBC_LINUX_OPTION __has_include(<linux/types.h>)
#endif // _BITS_FEATURE_H

View file

@ -1,31 +1,29 @@
#ifndef MLIBC_ALL_SYSDEPS
#define MLIBC_ALL_SYSDEPS
#include <bits/feature.h>
#include <mlibc-config.h>
#include <internal-config.h>
#if __MLIBC_ANSI_OPTION
#ifdef __MLIBC_ANSI_OPTION
# include <mlibc/ansi-sysdeps.hpp>
#endif // __MLIBC_ANSI_OPTION
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <mlibc/posix-sysdeps.hpp>
#endif // __MLIBC_POSIX_OPTION
#if __MLIBC_LINUX_OPTION
#ifdef __MLIBC_LINUX_OPTION
# include <mlibc/linux-sysdeps.hpp>
#endif // __MLIBC_LINUX_OPTION
#ifdef __MLIBC_GLIBC_OPTION
# include <mlibc/glibc-sysdeps.hpp>
#endif // __MLIBC_GLIBC_OPTION
#ifdef MLIBC_BUILDING_RTDL
# include <mlibc/rtdl-sysdeps.hpp>
#endif // MLIBC_BUILDING_RTDL
// TODO(geert): Make glibc optional
// Fixes this hack which works around rtdl not
// including the glibc option
#ifndef MLIBC_BUILDING_RTDL
# include <mlibc/glibc-sysdeps.hpp>
#endif // !MLIBC_BUILDING_RTDL
#include <mlibc/internal-sysdeps.hpp>
#endif // MLIBC_ALL_SYSDEPS

View file

@ -0,0 +1,42 @@
if disable_linux_headers
subdir_done()
endif
if not no_headers
install_headers(
'include/asm/ioctl.h',
'include/asm/ioctls.h',
subdir: 'asm'
)
install_headers(
'include/linux/bpf_common.h',
'include/linux/bsg.h',
'include/linux/cdrom.h',
'include/linux/filter.h',
'include/linux/fs.h',
'include/linux/hdreg.h',
'include/linux/input-event-codes.h',
'include/linux/input.h',
'include/linux/ioctl.h',
'include/linux/kd.h',
'include/linux/magic.h',
'include/linux/major.h',
'include/linux/netlink.h',
'include/linux/pci_regs.h',
'include/linux/route.h',
'include/linux/sched.h',
'include/linux/sockios.h',
'include/linux/types.h',
'include/linux/videodev2.h',
'include/linux/vt.h',
'include/linux/rtnetlink.h',
subdir: 'linux'
)
install_headers(
'include/scsi/scsi.h',
'include/scsi/scsi_ioctl.h',
'include/scsi/sg.h',
subdir: 'scsi'
)
endif

View file

@ -29,56 +29,20 @@ if not no_headers
'include/malloc.h',
'include/memory.h',
'include/mntent.h',
'include/poll.h',
'include/pty.h',
'include/utmp.h',
'include/utmpx.h',
'include/values.h',
'include/lastlog.h',
)
install_headers(
'include/asm/ioctl.h',
'include/asm/ioctls.h',
subdir: 'asm'
)
install_headers(
'include/bits/linux/linux_unistd.h',
subdir: 'bits/linux'
)
install_headers(
'include/linux/bpf_common.h',
'include/linux/bsg.h',
'include/linux/cdrom.h',
'include/linux/filter.h',
'include/linux/fs.h',
'include/linux/hdreg.h',
'include/linux/input-event-codes.h',
'include/linux/input.h',
'include/linux/ioctl.h',
'include/linux/kd.h',
'include/linux/magic.h',
'include/linux/major.h',
'include/linux/netlink.h',
'include/linux/pci_regs.h',
'include/linux/route.h',
'include/linux/sched.h',
'include/linux/sockios.h',
'include/linux/types.h',
'include/linux/videodev2.h',
'include/linux/vt.h',
'include/linux/rtnetlink.h',
subdir: 'linux'
)
install_headers(
'include/net/if_arp.h',
subdir: 'net'
)
install_headers(
'include/scsi/scsi.h',
'include/scsi/scsi_ioctl.h',
'include/scsi/sg.h',
subdir: 'scsi'
)
install_headers(
'include/sys/epoll.h',
'include/sys/inotify.h',
@ -93,7 +57,6 @@ if not no_headers
'include/sys/timerfd.h',
'include/sys/eventfd.h',
'include/sys/reboot.h',
'include/sys/poll.h',
subdir: 'sys'
)
endif

View file

@ -10,6 +10,7 @@
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <asm/ioctls.h>
#include <frg/small_vector.hpp>
#include <mlibc/allocator.hpp>

View file

@ -1,13 +1,11 @@
#include <string.h>
#include <sys/epoll.h>
#include <sys/select.h>
#include <unistd.h>
#include <errno.h>
#include <mlibc/debug.hpp>
#include <bits/ensure.h>
#include <bits/feature.h>
#include <mlibc-config.h>
#include <mlibc/posix-sysdeps.hpp>

View file

@ -2,7 +2,7 @@
#ifndef _UNISTD_H
#define _UNISTD_H
#include <bits/feature.h>
#include <mlibc-config.h>
#include <bits/types.h>
#include <bits/size_t.h>
#include <bits/ssize_t.h>
@ -241,7 +241,7 @@ int pipe2(int *pipefd, int flags);
}
#endif
#if __MLIBC_LINUX_OPTION
#ifdef __MLIBC_LINUX_OPTION
# include <bits/linux/linux_unistd.h>
#endif

View file

@ -74,6 +74,7 @@ if not no_headers
'include/nl_types.h',
'include/pthread.h',
'include/pwd.h',
'include/poll.h',
'include/regex.h',
'include/sched.h',
'include/search.h',
@ -107,6 +108,7 @@ if not no_headers
'include/sys/mman.h',
'include/sys/msg.h',
'include/sys/param.h',
'include/sys/poll.h',
'include/sys/resource.h',
'include/sys/select.h',
'include/sys/sem.h',

View file

@ -1,7 +1,7 @@
#include <errno.h>
#include <mlibc/tcb.hpp>
#include <mlibc/thread.hpp>
#include <bits/feature.h>
#include <mlibc-config.h>
#include <utility>
// GCC allows register + asm placement in extern "C" mode, but not in C++ mode.
@ -159,7 +159,7 @@ namespace mlibc {
template<typename... T>
sc_result_t do_cp_syscall(int sc, T... args) {
#if __MLIBC_POSIX_OPTION && !defined(MLIBC_BUILDING_RTDL)
#if defined(__MLIBC_POSIX_OPTION) && !defined(MLIBC_BUILDING_RTDL)
auto result = static_cast<sc_result_t>(do_nargs_cp_syscall(sc, sc_cast(args)...));
if (int e = sc_error(result); e) {
auto tcb = reinterpret_cast<Tcb*>(get_current_tcb());

View file

@ -1,7 +1,7 @@
#include <errno.h>
#include <type_traits>
#include <bits/feature.h>
#include <mlibc-config.h>
#include <bits/ensure.h>
#include <abi-bits/fcntl.h>
#include <mlibc/debug.hpp>
@ -271,7 +271,7 @@ int sys_sleep(time_t *secs, long *nanos) {
return 0;
}
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
#include <sys/ioctl.h>
#include <sched.h>