3 Nothing is defined before this file except target machine, target os
4 and the few things related to option settings in tccpp.c:tcc_predefs().
6 This file is either included at runtime as is, or converted and
7 included as C-strings at compile-time (depending on CONFIG_TCC_PREDEFS).
9 Note that line indent matters:
11 - in lines starting at column 1, platform macros are replaced by
12 corresponding TCC target compile-time macros. See conftest.c for
13 the list of platform macros supported in lines starting at column 1.
15 - only lines indented >= 4 are actually included into the executable,
19 #if __SIZEOF_POINTER__ == 4
21 #if defined TARGETOS_OpenBSD
22 #define __SIZE_TYPE__ unsigned long
23 #define __PTRDIFF_TYPE__ long
25 #define __SIZE_TYPE__ unsigned int
26 #define __PTRDIFF_TYPE__ int
29 #define __INT64_TYPE__ long long
30 #elif __SIZEOF_LONG__ == 4
32 #define __SIZE_TYPE__ unsigned long long
33 #define __PTRDIFF_TYPE__ long long
35 #define __INT64_TYPE__ long long
37 /* Other 64bit systems. */
38 #define __SIZE_TYPE__ unsigned long
39 #define __PTRDIFF_TYPE__ long
41 # if defined __linux__
42 #define __INT64_TYPE__ long
43 # else /* APPLE, BSD */
44 #define __INT64_TYPE__ long long
47 #define __SIZEOF_INT__ 4
48 #define __INT_MAX__ 0x7fffffff
49 #if __SIZEOF_LONG__ == 4
50 #define __LONG_MAX__ 0x7fffffffL
52 #define __LONG_MAX__ 0x7fffffffffffffffL
54 #define __SIZEOF_LONG_LONG__ 8
55 #define __LONG_LONG_MAX__ 0x7fffffffffffffffLL
56 #define __CHAR_BIT__ 8
57 #define __ORDER_LITTLE_ENDIAN__ 1234
58 #define __ORDER_BIG_ENDIAN__ 4321
59 #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
61 #define __WCHAR_TYPE__ unsigned short
62 #define __WINT_TYPE__ unsigned short
63 #elif defined __linux__
64 #define __WCHAR_TYPE__ int
65 #define __WINT_TYPE__ unsigned int
67 #define __WCHAR_TYPE__ int
68 #define __WINT_TYPE__ int
71 #if __STDC_VERSION__ == 201112L
72 # define __STDC_NO_ATOMICS__ 1
73 # define __STDC_NO_COMPLEX__ 1
74 # define __STDC_NO_THREADS__ 1
76 # define __STDC_UTF_16__ 1
77 # define __STDC_UTF_32__ 1
82 #define __declspec(x) __attribute__((x))
85 #elif defined __FreeBSD__
87 #define __GNUC_MINOR__ 3
88 #define __GNUC_PATCHLEVEL__ 0
89 #define __GNUC_STDC_INLINE__ 1
91 # if __SIZEOF_POINTER__ == 8
92 /* FIXME, __int128_t is used by setjump */
93 #define __int128_t struct { unsigned char _dummy[16] __attribute((aligned(16))); }
96 #elif defined __FreeBSD_kernel__
98 #elif defined __NetBSD__
100 #define __GNUC_MINOR__ 1
101 #define __GNUC_PATCHLEVEL__ 0
104 #if defined __aarch64__
105 #define _LOCORE /* avoids usage of __asm */
108 #elif defined __OpenBSD__
110 #define _ANSI_LIBRARY 1
112 #elif defined __APPLE__
113 /* emulate APPLE-GCC to make libc's headerfiles compile: */
114 #define __GNUC__ 4 /* darwin emits warning on GCC<4 */
115 #define __APPLE_CC__ 1 /* for <TargetConditionals.h> */
116 #define _DONT_USE_CTYPE_INLINE_ 1
117 /* avoids usage of GCC/clang specific builtins in libc-headerfiles: */
118 #define __FINITE_MATH_ONLY__ 1
119 #define _FORTIFY_SOURCE 0
125 /* Some derived integer types needed to get stdint.h to compile correctly on some platforms */
127 #define __UINTPTR_TYPE__ unsigned __PTRDIFF_TYPE__
128 #define __INTPTR_TYPE__ __PTRDIFF_TYPE__
130 #define __INT32_TYPE__ int
134 #define __REDIRECT(name, proto, alias) name proto __asm__ (#alias)
135 #define __REDIRECT_NTH(name, proto, alias) name proto __asm__ (#alias) __THROW
138 /* skip __builtin... with -E */
141 #define __builtin_offsetof(type, field) ((__SIZE_TYPE__)&((type*)0)->field)
142 #define __builtin_extract_return_addr(x) x
143 #if !defined __linux__ && !defined _WIN32
145 #define __builtin_huge_val() 1e500
146 #define __builtin_huge_valf() 1e50f
147 #define __builtin_huge_vall() 1e5000L
148 # if defined __APPLE__
149 #define __builtin_nanf(ignored_string) __nan()
150 /* used by floats.h to implement FLT_ROUNDS C99 macro. 1 == to nearest */
151 #define __builtin_flt_rounds() 1
152 /* used by _fd_def.h */
153 #define __builtin_bzero(p, ignored_size) bzero(p, sizeof(*(p)))
155 #define __builtin_nanf(ignored_string) (0.0F/0.0F)
159 /* __builtin_va_list */
160 #if defined __x86_64__
162 /* GCC compatible definition of va_list. */
163 /* This should be in sync with the declaration in our lib/libtcc1.c */
165 unsigned gp_offset
, fp_offset
;
167 unsigned overflow_offset
;
168 char *overflow_arg_area
;
171 } __builtin_va_list
[1];
173 void *__va_arg(__builtin_va_list ap
, int arg_type
, int size
, int align
);
174 #define __builtin_va_start(ap, last) \
175 (*(ap) = *(__builtin_va_list)((char*)__builtin_frame_address(0) - 24))
176 #define __builtin_va_arg(ap, t) \
177 (*(t *)(__va_arg(ap, __builtin_va_arg_types(t), sizeof(t), __alignof__(t))))
178 #define __builtin_va_copy(dest, src) (*(dest) = *(src))
181 typedef char *__builtin_va_list
;
182 #define __builtin_va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \
183 ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8))
186 #elif defined __arm__
187 typedef char *__builtin_va_list
;
188 #define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x)
189 #define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \
190 & ~(_tcc_alignof(type) - 1))
191 #define __builtin_va_start(ap,last) (ap = ((char *)&(last)) + ((sizeof(last)+3)&~3))
192 #define __builtin_va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \
193 &~3), *(type *)(ap - ((sizeof(type)+3)&~3)))
195 #elif defined __aarch64__
197 void *__stack
, *__gr_top
, *__vr_top
;
198 int __gr_offs
, __vr_offs
;
201 #elif defined __riscv
202 typedef char *__builtin_va_list
;
203 #define __va_reg_size (__riscv_xlen >> 3)
204 #define _tcc_align(addr,type) (((unsigned long)addr + __alignof__(type) - 1) \
205 & -(__alignof__(type)))
206 #define __builtin_va_arg(ap,type) (*(sizeof(type) > (2*__va_reg_size) ? *(type **)((ap += __va_reg_size) - __va_reg_size) : (ap = (va_list)(_tcc_align(ap,type) + (sizeof(type)+__va_reg_size - 1)& -__va_reg_size), (type *)(ap - ((sizeof(type)+ __va_reg_size - 1)& -__va_reg_size)))))
209 typedef char *__builtin_va_list
;
210 #define __builtin_va_start(ap,last) (ap = ((char *)&(last)) + ((sizeof(last)+3)&~3))
211 #define __builtin_va_arg(ap,t) (*(t*)((ap+=(sizeof(t)+3)&~3)-((sizeof(t)+3)&~3)))
214 #define __builtin_va_end(ap) (void)(ap)
215 #ifndef __builtin_va_copy
216 # define __builtin_va_copy(dest, src) (dest) = (src)
219 /* TCC BBUILTIN AND BOUNDS ALIASES */
220 #ifdef __leading_underscore
221 # define __RENAME(X) __asm__("_"X)
223 # define __RENAME(X) __asm__(X)
226 #ifdef __BOUNDS_CHECKING_ON
227 # define __BUILTINBC(ret,name,params) ret __builtin_##name params __RENAME("__bound_"#name);
228 # define __BOUND(ret,name,params) ret name params __RENAME("__bound_"#name);
230 # define __BUILTINBC(ret,name,params) ret __builtin_##name params __RENAME(#name);
231 # define __BOUND(ret,name,params)
234 #define __BOTH __BOUND
235 #define __BUILTIN(ret,name,params)
237 #define __BOTH(ret,name,params) __BUILTINBC(ret,name,params)__BOUND(ret,name,params)
238 #define __BUILTIN(ret,name,params) ret __builtin_##name params __RENAME(#name);
241 __BOTH(void*, memcpy
, (void *, const void*, __SIZE_TYPE__
))
242 __BOTH(void*, memmove
, (void *, const void*, __SIZE_TYPE__
))
243 __BOTH(void*, memset
, (void *, int, __SIZE_TYPE__
))
244 __BOTH(int, memcmp
, (const void *, const void*, __SIZE_TYPE__
))
245 __BOTH(__SIZE_TYPE__
, strlen
, (const char *))
246 __BOTH(char*, strcpy
, (char *, const char *))
247 __BOTH(char*, strncpy
, (char *, const char*, __SIZE_TYPE__
))
248 __BOTH(int, strcmp
, (const char*, const char*))
249 __BOTH(int, strncmp
, (const char*, const char*, __SIZE_TYPE__
))
250 __BOTH(char*, strcat
, (char*, const char*))
251 __BOTH(char*, strchr
, (const char*, int))
252 __BOTH(char*, strdup
, (const char*))
253 #if defined __ARM_EABI__
254 __BOUND(void*,__aeabi_memcpy
,(void*,const void*,__SIZE_TYPE__
))
255 __BOUND(void*,__aeabi_memmove
,(void*,const void*,__SIZE_TYPE__
))
256 __BOUND(void*,__aeabi_memmove4
,(void*,const void*,__SIZE_TYPE__
))
257 __BOUND(void*,__aeabi_memmove8
,(void*,const void*,__SIZE_TYPE__
))
258 __BOUND(void*,__aeabi_memset
,(void*,int,__SIZE_TYPE__
))
261 #if defined __linux__ || defined __APPLE__ // HAVE MALLOC_REDIR
262 #define __MAYBE_REDIR __BUILTIN
264 #define __MAYBE_REDIR __BOTH
266 __MAYBE_REDIR(void*, malloc
, (__SIZE_TYPE__
))
267 __MAYBE_REDIR(void*, realloc
, (void *, __SIZE_TYPE__
))
268 __MAYBE_REDIR(void*, calloc
, (__SIZE_TYPE__
, __SIZE_TYPE__
))
269 __MAYBE_REDIR(void*, memalign
, (__SIZE_TYPE__
, __SIZE_TYPE__
))
270 __MAYBE_REDIR(void, free
, (void*))
271 #if defined __i386__ || defined __x86_64__
272 __BOTH(void*, alloca
, (__SIZE_TYPE__
))
274 __BUILTIN(void*, alloca
, (__SIZE_TYPE__
))
276 __BUILTIN(void, abort
, (void))
277 __BOUND(void, longjmp
, ())
279 __BOUND(void*, mmap
, ())
280 __BOUND(int, munmap
, ())
289 #endif /* ndef __TCC_PP__ */