Skip to content

Commit f7ae33e

Browse files
committed
build: add -nostdinc and copy remaining headers from llvm
1 parent 8736a00 commit f7ae33e

20 files changed

+838
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ add_compile_options(
8888
-ffreestanding
8989
-fstrict-aliasing
9090
-nostdlib
91+
-nostdinc
9192
-Wno-unused-variable
9293
-Wno-unused-parameter
9394
-Wno-sign-compare
@@ -103,7 +104,6 @@ add_compile_definitions(
103104
set(CMAKE_EXE_LINKER_FLAGS "-static")
104105

105106
include_directories(${system_include_dir})
106-
include_directories(include)
107107

108108
add_subdirectory(kernel)
109109
add_subdirectory(libc)

include/__stdarg___gnuc_va_list.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*===---- __stdarg___gnuc_va_list.h - Definition of __gnuc_va_list ---------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef __GNUC_VA_LIST
11+
#define __GNUC_VA_LIST
12+
typedef __builtin_va_list __gnuc_va_list;
13+
#endif

include/__stdarg___va_copy.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*===---- __stdarg___va_copy.h - Definition of __va_copy -------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef __va_copy
11+
#define __va_copy(d, s) __builtin_va_copy(d, s)
12+
#endif

include/__stdarg_va_arg.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*===---- __stdarg_va_arg.h - Definitions of va_start, va_arg, va_end-------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef va_arg
11+
12+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
13+
/* C23 does not require the second parameter for va_start. */
14+
#define va_start(ap, ...) __builtin_va_start(ap, 0)
15+
#else
16+
/* Versions before C23 do require the second parameter. */
17+
#define va_start(ap, param) __builtin_va_start(ap, param)
18+
#endif
19+
#define va_end(ap) __builtin_va_end(ap)
20+
#define va_arg(ap, type) __builtin_va_arg(ap, type)
21+
22+
#endif

include/__stdarg_va_copy.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*===---- __stdarg_va_copy.h - Definition of va_copy------------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef va_copy
11+
#define va_copy(dest, src) __builtin_va_copy(dest, src)
12+
#endif

include/__stdarg_va_list.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*===---- __stdarg_va_list.h - Definition of va_list -----------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef _VA_LIST
11+
#define _VA_LIST
12+
typedef __builtin_va_list va_list;
13+
#endif

include/__stddef_max_align_t.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*===---- __stddef_max_align_t.h - Definition of max_align_t ---------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef __CLANG_MAX_ALIGN_T_DEFINED
11+
#define __CLANG_MAX_ALIGN_T_DEFINED
12+
13+
#if defined(_MSC_VER)
14+
typedef double max_align_t;
15+
#elif defined(__APPLE__)
16+
typedef long double max_align_t;
17+
#else
18+
// Define 'max_align_t' to match the GCC definition.
19+
typedef struct {
20+
long long __clang_max_align_nonce1
21+
__attribute__((__aligned__(__alignof__(long long))));
22+
long double __clang_max_align_nonce2
23+
__attribute__((__aligned__(__alignof__(long double))));
24+
} max_align_t;
25+
#endif
26+
27+
#endif

include/__stddef_null.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*===---- __stddef_null.h - Definition of NULL -----------------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#if !defined(NULL) || !__building_module(_Builtin_stddef)
11+
12+
/* linux/stddef.h will define NULL to 0. glibc (and other) headers then define
13+
* __need_NULL and rely on stddef.h to redefine NULL to the correct value again.
14+
* Modules don't support redefining macros like that, but support that pattern
15+
* in the non-modules case.
16+
*/
17+
#undef NULL
18+
19+
#ifdef __cplusplus
20+
#if !defined(__MINGW32__) && !defined(_MSC_VER)
21+
#define NULL __null
22+
#else
23+
#define NULL 0
24+
#endif
25+
#else
26+
#define NULL ((void *)0)
27+
#endif
28+
29+
#endif

include/__stddef_nullptr_t.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*===---- __stddef_nullptr_t.h - Definition of nullptr_t -------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
/*
11+
* When -fbuiltin-headers-in-system-modules is set this is a non-modular header
12+
* and needs to behave as if it was textual.
13+
*/
14+
#if !defined(_NULLPTR_T) \
15+
|| (__has_feature(modules) && !__building_module(_Builtin_stddef))
16+
#define _NULLPTR_T
17+
18+
#ifdef __cplusplus
19+
#if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
20+
namespace std {
21+
typedef decltype(nullptr) nullptr_t;
22+
}
23+
using ::std::nullptr_t;
24+
#endif
25+
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
26+
typedef typeof(nullptr) nullptr_t;
27+
#endif
28+
29+
#endif

include/__stddef_offsetof.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*===---- __stddef_offsetof.h - Definition of offsetof ---------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
/*
11+
* When -fbuiltin-headers-in-system-modules is set this is a non-modular header
12+
* and needs to behave as if it was textual.
13+
*/
14+
#if !defined(offsetof) \
15+
|| (__has_feature(modules) && !__building_module(_Builtin_stddef))
16+
#define offsetof(t, d) __builtin_offsetof(t, d)
17+
#endif

include/__stddef_ptrdiff_t.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*===---- __stddef_ptrdiff_t.h - Definition of ptrdiff_t -------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
/*
11+
* When -fbuiltin-headers-in-system-modules is set this is a non-modular header
12+
* and needs to behave as if it was textual.
13+
*/
14+
#if !defined(_PTRDIFF_T) \
15+
|| (__has_feature(modules) && !__building_module(_Builtin_stddef))
16+
#define _PTRDIFF_T
17+
18+
typedef __PTRDIFF_TYPE__ ptrdiff_t;
19+
20+
#endif

include/__stddef_rsize_t.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*===---- __stddef_rsize_t.h - Definition of rsize_t -----------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
/*
11+
* When -fbuiltin-headers-in-system-modules is set this is a non-modular header
12+
* and needs to behave as if it was textual.
13+
*/
14+
#if !defined(_RSIZE_T) \
15+
|| (__has_feature(modules) && !__building_module(_Builtin_stddef))
16+
#define _RSIZE_T
17+
18+
typedef __SIZE_TYPE__ rsize_t;
19+
20+
#endif

include/__stddef_size_t.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*===---- __stddef_size_t.h - Definition of size_t -------------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
/*
11+
* When -fbuiltin-headers-in-system-modules is set this is a non-modular header
12+
* and needs to behave as if it was textual.
13+
*/
14+
#if !defined(_SIZE_T) \
15+
|| (__has_feature(modules) && !__building_module(_Builtin_stddef))
16+
#define _SIZE_T
17+
18+
typedef __SIZE_TYPE__ size_t;
19+
20+
#endif

include/__stddef_unreachable.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*===---- __stddef_unreachable.h - Definition of unreachable ---------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef __cplusplus
11+
12+
/*
13+
* When -fbuiltin-headers-in-system-modules is set this is a non-modular header
14+
* and needs to behave as if it was textual.
15+
*/
16+
#if !defined(unreachable) \
17+
|| (__has_feature(modules) && !__building_module(_Builtin_stddef))
18+
#define unreachable() __builtin_unreachable()
19+
#endif
20+
21+
#endif

include/__stddef_wchar_t.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*===---- __stddef_wchar.h - Definition of wchar_t -------------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#if !defined(__cplusplus) || (defined(_MSC_VER) && !_NATIVE_WCHAR_T_DEFINED)
11+
12+
/*
13+
* When -fbuiltin-headers-in-system-modules is set this is a non-modular header
14+
* and needs to behave as if it was textual.
15+
*/
16+
#if !defined(_WCHAR_T) \
17+
|| (__has_feature(modules) && !__building_module(_Builtin_stddef))
18+
#define _WCHAR_T
19+
20+
#ifdef _MSC_EXTENSIONS
21+
#define _WCHAR_T_DEFINED
22+
#endif
23+
24+
typedef __WCHAR_TYPE__ wchar_t;
25+
26+
#endif
27+
28+
#endif

include/__stddef_wint_t.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*===---- __stddef_wint.h - Definition of wint_t ---------------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef _WINT_T
11+
#define _WINT_T
12+
13+
typedef __WINT_TYPE__ wint_t;
14+
15+
#endif

0 commit comments

Comments
 (0)