2009-05-06 02:17:11 +08:00
|
|
|
/*
|
|
|
|
* TCC - Tiny C Compiler
|
2017-09-26 13:16:23 +08:00
|
|
|
*
|
2009-05-06 02:17:11 +08:00
|
|
|
* Copyright (c) 2001-2004 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
#ifndef _TCC_H
|
|
|
|
#define _TCC_H
|
|
|
|
|
2009-05-06 02:17:26 +08:00
|
|
|
#define _GNU_SOURCE
|
2020-05-22 11:27:30 +08:00
|
|
|
#define _DARWIN_C_SOURCE
|
2009-05-06 02:17:26 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2020-04-15 10:13:05 +08:00
|
|
|
#include <stdarg.h>
|
2009-05-06 02:17:26 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2020-12-20 03:33:36 +08:00
|
|
|
/* gnu headers use to #define __attribute__ to empty for non-gcc compilers */
|
|
|
|
#ifdef __TINYC__
|
|
|
|
# undef __attribute__
|
|
|
|
#endif
|
2009-05-06 02:17:26 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
2013-02-04 23:08:06 +08:00
|
|
|
# include <unistd.h>
|
|
|
|
# include <sys/time.h>
|
2013-02-07 02:01:07 +08:00
|
|
|
# ifndef CONFIG_TCC_STATIC
|
|
|
|
# include <dlfcn.h>
|
|
|
|
# endif
|
2014-04-05 02:18:39 +08:00
|
|
|
/* XXX: need to define this to use them in non ISOC99 context */
|
2017-07-09 18:07:40 +08:00
|
|
|
extern float strtof (const char *__nptr, char **__endptr);
|
|
|
|
extern long double strtold (const char *__nptr, char **__endptr);
|
|
|
|
#endif
|
2016-10-18 05:24:01 +08:00
|
|
|
|
2017-07-09 18:07:40 +08:00
|
|
|
#ifdef _WIN32
|
2020-12-18 07:33:44 +08:00
|
|
|
# define WIN32_LEAN_AND_MEAN 1
|
2013-02-04 23:08:06 +08:00
|
|
|
# include <windows.h>
|
|
|
|
# include <io.h> /* open, close etc. */
|
|
|
|
# include <direct.h> /* getcwd */
|
2021-08-02 02:04:46 +08:00
|
|
|
# include <malloc.h> /* alloca */
|
2013-02-04 23:08:06 +08:00
|
|
|
# ifdef __GNUC__
|
|
|
|
# include <stdint.h>
|
|
|
|
# endif
|
|
|
|
# define inline __inline
|
2014-04-05 02:18:39 +08:00
|
|
|
# define snprintf _snprintf
|
|
|
|
# define vsnprintf _vsnprintf
|
|
|
|
# ifndef __GNUC__
|
|
|
|
# define strtold (long double)strtod
|
|
|
|
# define strtof (float)strtod
|
2020-12-18 07:33:44 +08:00
|
|
|
# ifdef _WIN64
|
|
|
|
# define strtoll _strtoi64
|
|
|
|
# define strtoull _strtoui64
|
|
|
|
# else
|
|
|
|
# define strtoll strtol
|
|
|
|
# define strtoull strtoul
|
|
|
|
# endif
|
2014-04-05 02:18:39 +08:00
|
|
|
# endif
|
2013-02-04 23:08:06 +08:00
|
|
|
# ifdef LIBTCC_AS_DLL
|
|
|
|
# define LIBTCCAPI __declspec(dllexport)
|
|
|
|
# define PUB_FUNC LIBTCCAPI
|
|
|
|
# endif
|
2017-07-09 18:07:40 +08:00
|
|
|
# define inp next_inp /* inp is an intrinsic on msvc/mingw */
|
2016-04-13 11:29:24 +08:00
|
|
|
# ifdef _MSC_VER
|
|
|
|
# pragma warning (disable : 4244) // conversion from 'uint64_t' to 'int', possible loss of data
|
|
|
|
# pragma warning (disable : 4267) // conversion from 'size_t' to 'int', possible loss of data
|
|
|
|
# pragma warning (disable : 4996) // The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name
|
|
|
|
# pragma warning (disable : 4018) // signed/unsigned mismatch
|
|
|
|
# pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
|
2016-12-19 05:05:42 +08:00
|
|
|
# define ssize_t intptr_t
|
2018-06-08 21:31:40 +08:00
|
|
|
# ifdef _X86_
|
|
|
|
# define __i386__ 1
|
|
|
|
# endif
|
|
|
|
# ifdef _AMD64_
|
|
|
|
# define __x86_64__ 1
|
|
|
|
# endif
|
2016-04-13 11:29:24 +08:00
|
|
|
# endif
|
2021-08-02 02:04:46 +08:00
|
|
|
# ifndef va_copy
|
|
|
|
# define va_copy(a,b) a = b
|
|
|
|
# endif
|
2016-10-06 00:34:17 +08:00
|
|
|
# undef CONFIG_TCC_STATIC
|
2009-05-06 02:17:26 +08:00
|
|
|
#endif
|
|
|
|
|
2021-01-16 14:01:59 +08:00
|
|
|
#ifndef PAGESIZE
|
|
|
|
# ifdef _SC_PAGESIZE
|
|
|
|
# define PAGESIZE sysconf(_SC_PAGESIZE)
|
|
|
|
# else
|
|
|
|
# define PAGESIZE 4096
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2009-05-06 02:17:26 +08:00
|
|
|
#ifndef O_BINARY
|
2013-02-13 02:13:28 +08:00
|
|
|
# define O_BINARY 0
|
2010-09-11 02:55:54 +08:00
|
|
|
#endif
|
|
|
|
|
2017-07-24 03:24:11 +08:00
|
|
|
#ifndef offsetof
|
|
|
|
#define offsetof(type, field) ((size_t) &((type *)0)->field)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef countof
|
|
|
|
#define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
|
|
|
|
#endif
|
|
|
|
|
2017-07-09 18:07:40 +08:00
|
|
|
#ifdef _MSC_VER
|
2014-04-05 02:18:39 +08:00
|
|
|
# define NORETURN __declspec(noreturn)
|
2017-07-09 18:07:40 +08:00
|
|
|
# define ALIGNED(x) __declspec(align(x))
|
2020-05-05 15:00:24 +08:00
|
|
|
# define PRINTF_LIKE(x,y)
|
2014-04-05 02:18:39 +08:00
|
|
|
#else
|
2017-07-09 18:07:40 +08:00
|
|
|
# define NORETURN __attribute__((noreturn))
|
|
|
|
# define ALIGNED(x) __attribute__((aligned(x)))
|
2020-05-05 15:00:24 +08:00
|
|
|
# define PRINTF_LIKE(x,y) __attribute__ ((format (printf, (x), (y))))
|
2014-04-05 02:18:39 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
# define IS_DIRSEP(c) (c == '/' || c == '\\')
|
|
|
|
# define IS_ABSPATH(p) (IS_DIRSEP(p[0]) || (p[0] && p[1] == ':' && IS_DIRSEP(p[2])))
|
|
|
|
# define PATHCMP stricmp
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-12 00:13:43 +08:00
|
|
|
# define PATHSEP ";"
|
2014-04-05 02:18:39 +08:00
|
|
|
#else
|
|
|
|
# define IS_DIRSEP(c) (c == '/')
|
|
|
|
# define IS_ABSPATH(p) IS_DIRSEP(p[0])
|
|
|
|
# define PATHCMP strcmp
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-12 00:13:43 +08:00
|
|
|
# define PATHSEP ":"
|
2014-04-05 02:18:39 +08:00
|
|
|
#endif
|
|
|
|
|
2016-10-18 05:24:01 +08:00
|
|
|
/* -------------------------------------------- */
|
2009-05-06 02:17:26 +08:00
|
|
|
|
|
|
|
/* parser debug */
|
2013-02-17 07:48:51 +08:00
|
|
|
/* #define PARSE_DEBUG */
|
2009-05-06 02:17:26 +08:00
|
|
|
/* preprocessor debug */
|
2013-02-17 07:48:51 +08:00
|
|
|
/* #define PP_DEBUG */
|
2009-05-06 02:17:26 +08:00
|
|
|
/* include file debug */
|
2013-02-17 07:48:51 +08:00
|
|
|
/* #define INC_DEBUG */
|
2019-12-14 19:31:03 +08:00
|
|
|
/* memory leak debug (only for single threaded usage) */
|
2013-02-17 07:48:51 +08:00
|
|
|
/* #define MEM_DEBUG */
|
2009-05-06 02:17:26 +08:00
|
|
|
/* assembler debug */
|
2013-02-17 07:48:51 +08:00
|
|
|
/* #define ASM_DEBUG */
|
2009-05-06 02:17:26 +08:00
|
|
|
|
|
|
|
/* target selection */
|
2013-02-17 07:48:51 +08:00
|
|
|
/* #define TCC_TARGET_I386 *//* i386 code generator */
|
2017-05-13 14:59:06 +08:00
|
|
|
/* #define TCC_TARGET_X86_64 *//* x86-64 code generator */
|
2013-02-17 07:48:51 +08:00
|
|
|
/* #define TCC_TARGET_ARM *//* ARMv4 code generator */
|
2015-02-14 02:58:31 +08:00
|
|
|
/* #define TCC_TARGET_ARM64 *//* ARMv8 code generator */
|
2013-02-17 07:48:51 +08:00
|
|
|
/* #define TCC_TARGET_C67 *//* TMS320C67xx code generator */
|
2019-06-22 12:13:10 +08:00
|
|
|
/* #define TCC_TARGET_RISCV64 *//* risc-v code generator */
|
2009-05-06 02:17:26 +08:00
|
|
|
|
|
|
|
/* default target is I386 */
|
|
|
|
#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
|
2015-02-14 02:58:31 +08:00
|
|
|
!defined(TCC_TARGET_ARM64) && !defined(TCC_TARGET_C67) && \
|
2019-06-22 12:13:10 +08:00
|
|
|
!defined(TCC_TARGET_X86_64) && !defined(TCC_TARGET_RISCV64)
|
2018-06-08 21:31:40 +08:00
|
|
|
# if defined __x86_64__
|
2017-07-24 03:24:11 +08:00
|
|
|
# define TCC_TARGET_X86_64
|
|
|
|
# elif defined __arm__
|
|
|
|
# define TCC_TARGET_ARM
|
|
|
|
# define TCC_ARM_EABI
|
2020-01-18 08:22:28 +08:00
|
|
|
# define TCC_ARM_VFP
|
2017-07-24 03:24:11 +08:00
|
|
|
# define TCC_ARM_HARDFLOAT
|
|
|
|
# elif defined __aarch64__
|
|
|
|
# define TCC_TARGET_ARM64
|
2020-01-18 08:22:28 +08:00
|
|
|
# elif defined __riscv
|
|
|
|
# define TCC_TARGET_RISCV64
|
2017-07-24 03:24:11 +08:00
|
|
|
# else
|
|
|
|
# define TCC_TARGET_I386
|
|
|
|
# endif
|
|
|
|
# ifdef _WIN32
|
|
|
|
# define TCC_TARGET_PE 1
|
|
|
|
# endif
|
2021-08-02 02:04:46 +08:00
|
|
|
# ifdef __APPLE__
|
|
|
|
# define TCC_TARGET_MACHO 1
|
|
|
|
# endif
|
2009-05-06 02:17:26 +08:00
|
|
|
#endif
|
|
|
|
|
2012-03-06 03:15:56 +08:00
|
|
|
/* only native compiler supports -run */
|
2021-07-26 02:39:11 +08:00
|
|
|
#if defined _WIN32 == defined TCC_TARGET_PE \
|
|
|
|
&& defined __APPLE__ == defined TCC_TARGET_MACHO
|
2018-06-08 21:31:40 +08:00
|
|
|
# if defined __i386__ && defined TCC_TARGET_I386
|
2012-03-06 03:15:56 +08:00
|
|
|
# define TCC_IS_NATIVE
|
2018-06-08 21:31:40 +08:00
|
|
|
# elif defined __x86_64__ && defined TCC_TARGET_X86_64
|
2012-03-06 03:15:56 +08:00
|
|
|
# define TCC_IS_NATIVE
|
|
|
|
# elif defined __arm__ && defined TCC_TARGET_ARM
|
|
|
|
# define TCC_IS_NATIVE
|
2015-02-14 02:58:31 +08:00
|
|
|
# elif defined __aarch64__ && defined TCC_TARGET_ARM64
|
|
|
|
# define TCC_IS_NATIVE
|
2019-06-22 12:13:10 +08:00
|
|
|
# elif defined __riscv && defined __LP64__ && defined TCC_TARGET_RISCV64
|
|
|
|
# define TCC_IS_NATIVE
|
2012-03-06 03:15:56 +08:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2020-12-17 03:08:43 +08:00
|
|
|
#if !defined TCC_IS_NATIVE \
|
|
|
|
|| (defined CONFIG_TCC_BACKTRACE && CONFIG_TCC_BACKTRACE==0)
|
|
|
|
# undef CONFIG_TCC_BACKTRACE
|
|
|
|
#else
|
2021-01-09 22:04:46 +08:00
|
|
|
# define CONFIG_TCC_BACKTRACE 1 /* enable builtin stack backtraces */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined CONFIG_TCC_BCHECK && CONFIG_TCC_BCHECK==0
|
2020-12-17 03:08:43 +08:00
|
|
|
# undef CONFIG_TCC_BCHECK
|
2021-01-09 22:04:46 +08:00
|
|
|
#else
|
2020-12-17 03:08:43 +08:00
|
|
|
# define CONFIG_TCC_BCHECK 1 /* enable bound checking code */
|
2012-03-06 03:15:56 +08:00
|
|
|
#endif
|
|
|
|
|
2021-01-05 21:16:02 +08:00
|
|
|
#if defined TARGETOS_OpenBSD \
|
|
|
|
|| defined TARGETOS_FreeBSD \
|
|
|
|
|| defined TARGETOS_NetBSD \
|
|
|
|
|| defined TARGETOS_FreeBSD_kernel
|
2020-12-18 07:33:44 +08:00
|
|
|
# define TARGETOS_BSD 1
|
2021-01-05 21:16:02 +08:00
|
|
|
#elif !(defined TCC_TARGET_PE || defined TCC_TARGET_MACHO)
|
2020-12-18 07:33:44 +08:00
|
|
|
# define TARGETOS_Linux 1
|
|
|
|
#endif
|
|
|
|
|
2020-06-27 23:15:06 +08:00
|
|
|
#if defined TCC_TARGET_PE || defined TCC_TARGET_MACHO
|
|
|
|
# define ELF_OBJ_ONLY /* create elf .o but native executables */
|
|
|
|
#endif
|
|
|
|
|
2021-07-26 02:39:11 +08:00
|
|
|
/* No ten-byte long doubles on window and macos except in
|
|
|
|
cross-compilers made by a mingw-GCC */
|
|
|
|
#if defined TCC_TARGET_PE \
|
2021-08-02 02:04:46 +08:00
|
|
|
|| (defined TCC_TARGET_MACHO && defined TCC_TARGET_ARM64) \
|
2021-07-26 02:39:11 +08:00
|
|
|
|| (defined _WIN32 && !defined __GNUC__)
|
2020-12-23 04:10:22 +08:00
|
|
|
# define TCC_USING_DOUBLE_FOR_LDOUBLE 1
|
|
|
|
#endif
|
|
|
|
|
2011-08-06 22:11:12 +08:00
|
|
|
/* ------------ path configuration ------------ */
|
2009-05-06 02:17:26 +08:00
|
|
|
|
2011-08-11 22:55:30 +08:00
|
|
|
#ifndef CONFIG_SYSROOT
|
|
|
|
# define CONFIG_SYSROOT ""
|
|
|
|
#endif
|
2021-08-02 02:04:46 +08:00
|
|
|
#if !defined CONFIG_TCCDIR && !defined _WIN32
|
2017-07-24 03:24:11 +08:00
|
|
|
# define CONFIG_TCCDIR "/usr/local/lib/tcc"
|
2013-02-14 13:53:07 +08:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_LDDIR
|
2016-10-18 05:22:21 +08:00
|
|
|
# define CONFIG_LDDIR "lib"
|
2013-02-14 13:53:07 +08:00
|
|
|
#endif
|
2016-10-18 05:22:21 +08:00
|
|
|
#ifdef CONFIG_TRIPLET
|
|
|
|
# define USE_TRIPLET(s) s "/" CONFIG_TRIPLET
|
|
|
|
# define ALSO_TRIPLET(s) USE_TRIPLET(s) ":" s
|
2014-01-07 02:56:26 +08:00
|
|
|
#else
|
2016-10-18 05:22:21 +08:00
|
|
|
# define USE_TRIPLET(s) s
|
|
|
|
# define ALSO_TRIPLET(s) s
|
2013-09-08 01:26:36 +08:00
|
|
|
#endif
|
2011-08-11 22:55:30 +08:00
|
|
|
|
2011-08-04 04:26:39 +08:00
|
|
|
/* path to find crt1.o, crti.o and crtn.o */
|
2011-08-06 22:11:12 +08:00
|
|
|
#ifndef CONFIG_TCC_CRTPREFIX
|
2022-05-08 05:16:13 +08:00
|
|
|
# define CONFIG_TCC_CRTPREFIX USE_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR)
|
2011-08-04 04:26:39 +08:00
|
|
|
#endif
|
|
|
|
|
2020-05-22 11:27:30 +08:00
|
|
|
#ifndef CONFIG_USR_INCLUDE
|
|
|
|
# define CONFIG_USR_INCLUDE "/usr/include"
|
|
|
|
#endif
|
|
|
|
|
2011-08-11 22:55:30 +08:00
|
|
|
/* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */
|
|
|
|
|
2011-08-06 22:11:12 +08:00
|
|
|
/* system include paths */
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-12 00:13:43 +08:00
|
|
|
#ifndef CONFIG_TCC_SYSINCLUDEPATHS
|
2020-06-02 00:10:58 +08:00
|
|
|
# if defined TCC_TARGET_PE || defined _WIN32
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-12 00:13:43 +08:00
|
|
|
# define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include"PATHSEP"{B}/include/winapi"
|
2013-09-08 01:26:36 +08:00
|
|
|
# else
|
2012-04-19 00:44:39 +08:00
|
|
|
# define CONFIG_TCC_SYSINCLUDEPATHS \
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-12 00:13:43 +08:00
|
|
|
"{B}/include" \
|
|
|
|
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \
|
2020-05-22 11:27:30 +08:00
|
|
|
":" ALSO_TRIPLET(CONFIG_SYSROOT CONFIG_USR_INCLUDE)
|
2011-08-04 04:26:39 +08:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2011-08-06 22:11:12 +08:00
|
|
|
/* library search paths */
|
|
|
|
#ifndef CONFIG_TCC_LIBPATHS
|
2011-08-04 04:26:39 +08:00
|
|
|
# ifdef TCC_TARGET_PE
|
2014-01-07 02:56:26 +08:00
|
|
|
# define CONFIG_TCC_LIBPATHS "{B}/lib"
|
2011-08-04 04:26:39 +08:00
|
|
|
# else
|
2021-07-07 04:48:38 +08:00
|
|
|
# define CONFIG_TCC_LIBPATHS \
|
2016-10-18 05:22:21 +08:00
|
|
|
ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
|
|
|
|
":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \
|
|
|
|
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR)
|
2011-08-04 04:26:39 +08:00
|
|
|
# endif
|
|
|
|
#endif
|
2009-05-06 02:17:26 +08:00
|
|
|
|
2011-08-06 22:11:12 +08:00
|
|
|
/* name of ELF interpreter */
|
|
|
|
#ifndef CONFIG_TCC_ELFINTERP
|
2020-12-17 03:08:43 +08:00
|
|
|
# if TARGETOS_FreeBSD
|
2011-08-06 22:11:12 +08:00
|
|
|
# define CONFIG_TCC_ELFINTERP "/libexec/ld-elf.so.1"
|
2020-12-17 03:08:43 +08:00
|
|
|
# elif TARGETOS_FreeBSD_kernel
|
2013-02-18 18:41:34 +08:00
|
|
|
# if defined(TCC_TARGET_X86_64)
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld-kfreebsd-x86-64.so.1"
|
|
|
|
# else
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld.so.1"
|
|
|
|
# endif
|
2020-12-18 07:33:44 +08:00
|
|
|
# elif TARGETOS_DragonFly
|
2014-04-12 13:10:12 +08:00
|
|
|
# define CONFIG_TCC_ELFINTERP "/usr/libexec/ld-elf.so.2"
|
2020-12-17 03:08:43 +08:00
|
|
|
# elif TARGETOS_NetBSD
|
2015-10-11 18:22:41 +08:00
|
|
|
# define CONFIG_TCC_ELFINTERP "/usr/libexec/ld.elf_so"
|
2021-01-10 14:23:03 +08:00
|
|
|
# elif TARGETOS_OpenBSD
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/usr/libexec/ld.so"
|
2013-02-18 18:53:00 +08:00
|
|
|
# elif defined __GNU__
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld.so"
|
2015-03-03 22:05:44 +08:00
|
|
|
# elif defined(TCC_TARGET_PE)
|
|
|
|
# define CONFIG_TCC_ELFINTERP "-"
|
|
|
|
# elif defined(TCC_UCLIBC)
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld-uClibc.so.0" /* is there a uClibc for x86_64 ? */
|
2015-02-14 02:58:31 +08:00
|
|
|
# elif defined TCC_TARGET_ARM64
|
2017-04-21 04:01:50 +08:00
|
|
|
# if defined(TCC_MUSL)
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld-musl-aarch64.so.1"
|
|
|
|
# else
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld-linux-aarch64.so.1"
|
|
|
|
# endif
|
2011-08-06 22:11:12 +08:00
|
|
|
# elif defined(TCC_TARGET_X86_64)
|
2017-04-21 04:01:50 +08:00
|
|
|
# if defined(TCC_MUSL)
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld-musl-x86_64.so.1"
|
|
|
|
# else
|
2021-01-10 14:23:03 +08:00
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib64/ld-linux-x86-64.so.2"
|
2017-04-21 04:01:50 +08:00
|
|
|
# endif
|
2019-06-23 08:10:10 +08:00
|
|
|
# elif defined(TCC_TARGET_RISCV64)
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld-linux-riscv64-lp64d.so.1"
|
2014-01-07 15:23:54 +08:00
|
|
|
# elif !defined(TCC_ARM_EABI)
|
2017-04-21 04:01:50 +08:00
|
|
|
# if defined(TCC_MUSL)
|
2018-12-22 12:26:27 +08:00
|
|
|
# if defined(TCC_TARGET_I386)
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld-musl-i386.so.1"
|
|
|
|
# else
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld-musl-arm.so.1"
|
|
|
|
# endif
|
2017-04-21 04:01:50 +08:00
|
|
|
# else
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.2"
|
|
|
|
# endif
|
2011-08-06 22:11:12 +08:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2014-01-07 15:23:54 +08:00
|
|
|
/* var elf_interp dans *-gen.c */
|
|
|
|
#ifdef CONFIG_TCC_ELFINTERP
|
|
|
|
# define DEFAULT_ELFINTERP(s) CONFIG_TCC_ELFINTERP
|
|
|
|
#else
|
|
|
|
# define DEFAULT_ELFINTERP(s) default_elfinterp(s)
|
|
|
|
#endif
|
|
|
|
|
2017-02-23 15:41:57 +08:00
|
|
|
/* (target specific) libtcc1.a */
|
|
|
|
#ifndef TCC_LIBTCC1
|
|
|
|
# define TCC_LIBTCC1 "libtcc1.a"
|
2016-10-02 03:06:33 +08:00
|
|
|
#endif
|
|
|
|
|
2011-08-06 22:11:12 +08:00
|
|
|
/* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */
|
2017-02-23 15:41:57 +08:00
|
|
|
#if defined CONFIG_USE_LIBGCC && !defined TCC_LIBGCC
|
2016-10-18 05:22:21 +08:00
|
|
|
#define TCC_LIBGCC USE_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1"
|
2017-02-23 15:41:57 +08:00
|
|
|
#endif
|
2011-08-06 22:11:12 +08:00
|
|
|
|
2016-10-18 05:24:01 +08:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
#include "libtcc.h"
|
|
|
|
#include "elf.h"
|
|
|
|
#include "stab.h"
|
Add dwarf support
The new gcc12 release does not support stabs any more.
This was a good reason to add support for dwarf.
The stabs code still works and is used if configure option --dwarf
is not used.
Tested on x86_64, i386, arm, arm64, riscv64 with dwarf-5.
Some debuggers may not support dwarf-5. Try using older dwarf versions
i that case.
The tccmacho.c code probably need some support for dwarf.
arm-gen.c, arm64-gen.c, i386-gen.c, riscv64-gen.c, x86_64-gen.
- fix get_sym_ref symbol size
arm-link.c, arm64-link.c, i386-link.c, riscv64-link.c, x86_64-link.c
- add R_DATA_32U
libtcc.c:
- parse -gdwarf option
tcc.c:
- add dwarf option
tcc.h:
- add dwarf option and sections
tccelf.c:
- init dwarf sections
- avoid adding sh_addr for dwarf sections
- remove dwarf relocs for output dll
- add dwarf sections for tccrun
tccgen.c:
- add dwarf defines + global data
- add dwarf_* functions
- mix dwarf code with stabs code
- a trick is used to emit function name in .debug_line section so
only this section has to be parsed instead of .debug_info and
.debug_abbrev.
- fix init debug_modes
tccrun.c:
- add dwarf sections in rt_context
- init them in tcc_run
- add new dwarf code rt_printline_dwarf to find file/function
dwarf.h:
- New file
tcc-doc.texi:
- document dwarf
configure:
- add dwarf option
lib/Makefile
- change -gstabs into -gdwarf
lib/bt-exe.c, tests/tests2/Makefile, tests/tests2/126_bound_global:
- Add __bound_init call
- Add new testcase to test it
2022-05-05 15:10:37 +08:00
|
|
|
#include "dwarf.h"
|
2016-10-18 05:24:01 +08:00
|
|
|
|
2017-02-23 15:41:57 +08:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
#ifndef PUB_FUNC /* functions used by tcc.c but not in libtcc.h */
|
|
|
|
# define PUB_FUNC
|
|
|
|
#endif
|
|
|
|
|
2017-07-24 03:24:11 +08:00
|
|
|
#ifndef ONE_SOURCE
|
|
|
|
# define ONE_SOURCE 1
|
|
|
|
#endif
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
/* support using libtcc from threads */
|
2020-12-18 07:33:44 +08:00
|
|
|
#ifndef CONFIG_TCC_SEMLOCK
|
|
|
|
# define CONFIG_TCC_SEMLOCK 1
|
|
|
|
#endif
|
2019-12-11 07:37:18 +08:00
|
|
|
|
2017-07-24 03:24:11 +08:00
|
|
|
#if ONE_SOURCE
|
2017-02-23 15:41:57 +08:00
|
|
|
#define ST_INLN static inline
|
|
|
|
#define ST_FUNC static
|
|
|
|
#define ST_DATA static
|
|
|
|
#else
|
|
|
|
#define ST_INLN
|
|
|
|
#define ST_FUNC
|
|
|
|
#define ST_DATA extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TCC_PROFILE /* profile all functions */
|
|
|
|
# define static
|
|
|
|
#endif
|
|
|
|
|
2013-02-09 02:07:11 +08:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
/* include the target specific definitions */
|
|
|
|
|
|
|
|
#define TARGET_DEFS_ONLY
|
|
|
|
#ifdef TCC_TARGET_I386
|
2015-07-30 04:53:57 +08:00
|
|
|
# include "i386-gen.c"
|
2016-12-06 04:40:59 +08:00
|
|
|
# include "i386-link.c"
|
2019-06-22 12:13:10 +08:00
|
|
|
#elif defined TCC_TARGET_X86_64
|
2015-07-30 04:53:57 +08:00
|
|
|
# include "x86_64-gen.c"
|
2016-12-06 04:40:59 +08:00
|
|
|
# include "x86_64-link.c"
|
2019-06-22 12:13:10 +08:00
|
|
|
#elif defined TCC_TARGET_ARM
|
2015-07-30 04:53:57 +08:00
|
|
|
# include "arm-gen.c"
|
2016-12-06 04:40:59 +08:00
|
|
|
# include "arm-link.c"
|
2017-05-13 14:59:06 +08:00
|
|
|
# include "arm-asm.c"
|
2019-06-22 12:13:10 +08:00
|
|
|
#elif defined TCC_TARGET_ARM64
|
2015-07-30 04:53:57 +08:00
|
|
|
# include "arm64-gen.c"
|
2016-12-06 04:40:59 +08:00
|
|
|
# include "arm64-link.c"
|
2020-06-16 13:39:48 +08:00
|
|
|
# include "arm-asm.c"
|
2019-06-22 12:13:10 +08:00
|
|
|
#elif defined TCC_TARGET_C67
|
2017-07-24 03:24:11 +08:00
|
|
|
# define TCC_TARGET_COFF
|
2013-02-09 02:07:11 +08:00
|
|
|
# include "coff.h"
|
2015-07-30 04:53:57 +08:00
|
|
|
# include "c67-gen.c"
|
2016-12-06 04:40:59 +08:00
|
|
|
# include "c67-link.c"
|
2019-06-22 12:13:10 +08:00
|
|
|
#elif defined(TCC_TARGET_RISCV64)
|
|
|
|
# include "riscv64-gen.c"
|
|
|
|
# include "riscv64-link.c"
|
2020-06-16 13:39:48 +08:00
|
|
|
# include "riscv64-asm.c"
|
2019-06-22 12:13:10 +08:00
|
|
|
#else
|
|
|
|
#error unknown target
|
2013-02-09 02:07:11 +08:00
|
|
|
#endif
|
|
|
|
#undef TARGET_DEFS_ONLY
|
|
|
|
|
2011-08-06 22:11:12 +08:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
2017-05-13 14:59:06 +08:00
|
|
|
#if PTR_SIZE == 8
|
|
|
|
# define ELFCLASSW ELFCLASS64
|
|
|
|
# define ElfW(type) Elf##64##_##type
|
|
|
|
# define ELFW(type) ELF##64##_##type
|
|
|
|
# define ElfW_Rel ElfW(Rela)
|
|
|
|
# define SHT_RELX SHT_RELA
|
|
|
|
# define REL_SECTION_FMT ".rela%s"
|
|
|
|
#else
|
|
|
|
# define ELFCLASSW ELFCLASS32
|
|
|
|
# define ElfW(type) Elf##32##_##type
|
|
|
|
# define ELFW(type) ELF##32##_##type
|
|
|
|
# define ElfW_Rel ElfW(Rel)
|
|
|
|
# define SHT_RELX SHT_REL
|
|
|
|
# define REL_SECTION_FMT ".rel%s"
|
|
|
|
#endif
|
|
|
|
/* target address type */
|
|
|
|
#define addr_t ElfW(Addr)
|
2017-11-27 11:03:03 +08:00
|
|
|
#define ElfSym ElfW(Sym)
|
2017-05-13 14:59:06 +08:00
|
|
|
|
2017-09-25 00:57:48 +08:00
|
|
|
#if PTR_SIZE == 8 && !defined TCC_TARGET_PE
|
|
|
|
# define LONG_SIZE 8
|
|
|
|
#else
|
|
|
|
# define LONG_SIZE 4
|
|
|
|
#endif
|
|
|
|
|
2017-05-13 14:59:06 +08:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
2009-05-06 02:17:26 +08:00
|
|
|
#define INCLUDE_STACK_SIZE 32
|
|
|
|
#define IFDEF_STACK_SIZE 64
|
|
|
|
#define VSTACK_SIZE 256
|
|
|
|
#define STRING_MAX_SIZE 1024
|
2016-04-17 21:37:23 +08:00
|
|
|
#define TOKSTR_MAX_SIZE 256
|
2009-05-06 02:17:26 +08:00
|
|
|
#define PACK_STACK_SIZE 8
|
|
|
|
|
2016-04-17 21:37:23 +08:00
|
|
|
#define TOK_HASH_SIZE 16384 /* must be a power of two */
|
2009-05-06 02:17:26 +08:00
|
|
|
#define TOK_ALLOC_INCR 512 /* must be a power of two */
|
|
|
|
#define TOK_MAX_SIZE 4 /* token max size in int unit when stored in string */
|
|
|
|
|
|
|
|
/* token symbol management */
|
|
|
|
typedef struct TokenSym {
|
|
|
|
struct TokenSym *hash_next;
|
|
|
|
struct Sym *sym_define; /* direct pointer to define */
|
|
|
|
struct Sym *sym_label; /* direct pointer to label */
|
|
|
|
struct Sym *sym_struct; /* direct pointer to structure */
|
|
|
|
struct Sym *sym_identifier; /* direct pointer to identifier */
|
|
|
|
int tok; /* token number */
|
|
|
|
int len;
|
|
|
|
char str[1];
|
|
|
|
} TokenSym;
|
|
|
|
|
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
typedef unsigned short nwchar_t;
|
|
|
|
#else
|
|
|
|
typedef int nwchar_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct CString {
|
|
|
|
int size; /* size in bytes */
|
|
|
|
void *data; /* either 'char *' or 'nwchar_t *' */
|
|
|
|
int size_allocated;
|
|
|
|
} CString;
|
|
|
|
|
|
|
|
/* type definition */
|
|
|
|
typedef struct CType {
|
|
|
|
int t;
|
|
|
|
struct Sym *ref;
|
|
|
|
} CType;
|
|
|
|
|
|
|
|
/* constant value */
|
|
|
|
typedef union CValue {
|
|
|
|
long double ld;
|
|
|
|
double d;
|
|
|
|
float f;
|
2015-11-18 03:09:35 +08:00
|
|
|
uint64_t i;
|
2015-11-21 19:23:53 +08:00
|
|
|
struct {
|
|
|
|
const void *data;
|
2020-06-21 03:56:53 +08:00
|
|
|
int size;
|
2015-11-21 19:23:53 +08:00
|
|
|
} str;
|
2013-02-09 02:07:11 +08:00
|
|
|
int tab[LDOUBLE_SIZE/4];
|
2009-05-06 02:17:26 +08:00
|
|
|
} CValue;
|
|
|
|
|
|
|
|
/* value on stack */
|
|
|
|
typedef struct SValue {
|
|
|
|
CType type; /* type */
|
|
|
|
unsigned short r; /* register + flags */
|
|
|
|
unsigned short r2; /* second register, used for 'long long'
|
|
|
|
type. If not used, set to VT_CONST */
|
jump optimizations
This unifies VT_CMP with VT_JMP(i) by using mostly VT_CMP
with both a positive and a negative jump target list.
Such we can delay putting the non-inverted or inverted jump
until we can see which one is nore suitable (in most cases).
example:
if (a && b || c && d)
e = 0;
before this patch:
a: 8b 45 fc mov 0xfffffffc(%ebp),%eax
d: 83 f8 00 cmp $0x0,%eax
10: 0f 84 11 00 00 00 je 27 <main+0x27>
16: 8b 45 f8 mov 0xfffffff8(%ebp),%eax
19: 83 f8 00 cmp $0x0,%eax
1c: 0f 84 05 00 00 00 je 27 <main+0x27>
22: e9 22 00 00 00 jmp 49 <main+0x49>
27: 8b 45 f4 mov 0xfffffff4(%ebp),%eax
2a: 83 f8 00 cmp $0x0,%eax
2d: 0f 84 11 00 00 00 je 44 <main+0x44>
33: 8b 45 f0 mov 0xfffffff0(%ebp),%eax
36: 83 f8 00 cmp $0x0,%eax
39: 0f 84 05 00 00 00 je 44 <main+0x44>
3f: e9 05 00 00 00 jmp 49 <main+0x49>
44: e9 08 00 00 00 jmp 51 <main+0x51>
49: b8 00 00 00 00 mov $0x0,%eax
4e: 89 45 ec mov %eax,0xffffffec(%ebp)
51: ...
with this patch:
a: 8b 45 fc mov 0xfffffffc(%ebp),%eax
d: 83 f8 00 cmp $0x0,%eax
10: 0f 84 0c 00 00 00 je 22 <main+0x22>
16: 8b 45 f8 mov 0xfffffff8(%ebp),%eax
19: 83 f8 00 cmp $0x0,%eax
1c: 0f 85 18 00 00 00 jne 3a <main+0x3a>
22: 8b 45 f4 mov 0xfffffff4(%ebp),%eax
25: 83 f8 00 cmp $0x0,%eax
28: 0f 84 14 00 00 00 je 42 <main+0x42>
2e: 8b 45 f0 mov 0xfffffff0(%ebp),%eax
31: 83 f8 00 cmp $0x0,%eax
34: 0f 84 08 00 00 00 je 42 <main+0x42>
3a: b8 00 00 00 00 mov $0x0,%eax
3f: 89 45 ec mov %eax,0xffffffec(%ebp)
42: ...
2019-06-22 17:45:35 +08:00
|
|
|
union {
|
|
|
|
struct { int jtrue, jfalse; }; /* forward jmps */
|
|
|
|
CValue c; /* constant, if VT_CONST */
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
struct { unsigned short cmp_op, cmp_r; }; /* VT_CMP operation */
|
|
|
|
struct Sym *sym; /* symbol, if (VT_SYM | VT_CONST), or if */
|
|
|
|
}; /* result of unary() for an identifier. */
|
|
|
|
|
2009-05-06 02:17:26 +08:00
|
|
|
} SValue;
|
|
|
|
|
2017-07-09 18:34:11 +08:00
|
|
|
/* symbol attributes */
|
|
|
|
struct SymAttr {
|
|
|
|
unsigned short
|
|
|
|
aligned : 5, /* alignment as log2+1 (0 == unspecified) */
|
|
|
|
packed : 1,
|
|
|
|
weak : 1,
|
|
|
|
visibility : 2,
|
|
|
|
dllexport : 1,
|
2018-07-22 07:54:01 +08:00
|
|
|
nodecorate : 1,
|
2017-07-09 18:34:11 +08:00
|
|
|
dllimport : 1,
|
2020-01-16 08:19:59 +08:00
|
|
|
addrtaken : 1,
|
2020-01-18 05:58:39 +08:00
|
|
|
xxxx : 3; /* not used */
|
2017-07-09 18:34:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* function attributes or temporary attributes for parsing */
|
|
|
|
struct FuncAttr {
|
2014-01-07 21:57:07 +08:00
|
|
|
unsigned
|
2017-07-09 18:34:11 +08:00
|
|
|
func_call : 3, /* calling convention (0..5), see below */
|
|
|
|
func_type : 2, /* FUNC_OLD/NEW/ELLIPSIS */
|
2019-04-29 19:53:07 +08:00
|
|
|
func_noreturn : 1, /* attribute((noreturn)) */
|
2020-01-18 05:58:39 +08:00
|
|
|
func_ctor : 1, /* attribute((constructor)) */
|
|
|
|
func_dtor : 1, /* attribute((destructor)) */
|
2020-05-22 11:17:02 +08:00
|
|
|
func_args : 8, /* PE __stdcall args */
|
|
|
|
func_alwinl : 1, /* always_inline */
|
2020-08-14 21:00:29 +08:00
|
|
|
xxxx : 15;
|
2014-01-07 21:57:07 +08:00
|
|
|
};
|
|
|
|
|
2009-05-06 02:17:26 +08:00
|
|
|
/* symbol management */
|
|
|
|
typedef struct Sym {
|
2017-07-09 18:34:11 +08:00
|
|
|
int v; /* symbol token */
|
|
|
|
unsigned short r; /* associated register or VT_CONST/VT_LOCAL and LVAL type */
|
|
|
|
struct SymAttr a; /* symbol attributes */
|
2014-01-07 21:57:07 +08:00
|
|
|
union {
|
2017-07-09 18:34:11 +08:00
|
|
|
struct {
|
|
|
|
int c; /* associated number or Elf symbol index */
|
|
|
|
union {
|
|
|
|
int sym_scope; /* scope level for locals */
|
2019-12-03 02:20:56 +08:00
|
|
|
int jnext; /* next jump label */
|
2017-07-09 18:34:11 +08:00
|
|
|
struct FuncAttr f; /* function attributes */
|
2017-07-09 18:38:59 +08:00
|
|
|
int auxtype; /* bitfield access type */
|
2017-07-09 18:34:11 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
long long enum_val; /* enum constant if IS_ENUM_VAL */
|
|
|
|
int *d; /* define token stream */
|
2019-12-03 02:20:56 +08:00
|
|
|
struct Sym *ncl; /* next cleanup */
|
2014-01-07 21:57:07 +08:00
|
|
|
};
|
2017-07-09 18:34:11 +08:00
|
|
|
CType type; /* associated type */
|
2009-07-19 04:05:58 +08:00
|
|
|
union {
|
2022-03-21 18:40:43 +08:00
|
|
|
int *vla_array_str; /* vla array code */
|
2016-10-06 10:05:30 +08:00
|
|
|
struct Sym *next; /* next related symbol (for fields and anoms) */
|
2019-12-03 02:20:56 +08:00
|
|
|
struct Sym *cleanupstate; /* in defined labels */
|
2017-07-09 18:34:11 +08:00
|
|
|
int asm_label; /* associated asm label */
|
2009-07-19 04:05:58 +08:00
|
|
|
};
|
2009-05-06 02:17:26 +08:00
|
|
|
struct Sym *prev; /* prev symbol in stack */
|
|
|
|
struct Sym *prev_tok; /* previous symbol for this token */
|
|
|
|
} Sym;
|
|
|
|
|
|
|
|
/* section definition */
|
|
|
|
typedef struct Section {
|
|
|
|
unsigned long data_offset; /* current data offset */
|
|
|
|
unsigned char *data; /* section data */
|
|
|
|
unsigned long data_allocated; /* used for realloc() handling */
|
2021-10-22 13:39:54 +08:00
|
|
|
TCCState *s1;
|
2009-05-06 02:17:26 +08:00
|
|
|
int sh_name; /* elf section name (only used during output) */
|
|
|
|
int sh_num; /* elf section number */
|
|
|
|
int sh_type; /* elf section type */
|
|
|
|
int sh_flags; /* elf section flags */
|
|
|
|
int sh_info; /* elf section info */
|
|
|
|
int sh_addralign; /* elf section alignment */
|
|
|
|
int sh_entsize; /* elf entry size */
|
|
|
|
unsigned long sh_size; /* section size (only used during output) */
|
2013-02-04 23:08:06 +08:00
|
|
|
addr_t sh_addr; /* address at which the section is relocated */
|
2012-03-04 01:10:15 +08:00
|
|
|
unsigned long sh_offset; /* file offset */
|
2009-05-06 02:17:26 +08:00
|
|
|
int nb_hashed_syms; /* used to resize the hash table */
|
|
|
|
struct Section *link; /* link to another section */
|
|
|
|
struct Section *reloc; /* corresponding section for relocation, if any */
|
2016-06-28 21:11:06 +08:00
|
|
|
struct Section *hash; /* hash table for symbols */
|
|
|
|
struct Section *prev; /* previous section on section stack */
|
2009-05-06 02:17:26 +08:00
|
|
|
char name[1]; /* section name */
|
|
|
|
} Section;
|
|
|
|
|
|
|
|
typedef struct DLLReference {
|
|
|
|
int level;
|
|
|
|
void *handle;
|
2022-05-29 02:47:48 +08:00
|
|
|
unsigned char found, index;
|
2009-05-06 02:17:26 +08:00
|
|
|
char name[1];
|
|
|
|
} DLLReference;
|
|
|
|
|
|
|
|
/* -------------------------------------------------- */
|
|
|
|
|
|
|
|
#define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
|
|
|
|
#define SYM_FIELD 0x20000000 /* struct/union field symbol space */
|
|
|
|
#define SYM_FIRST_ANOM 0x10000000 /* first anonymous sym */
|
|
|
|
|
2017-07-09 18:34:11 +08:00
|
|
|
/* stored in 'Sym->f.func_type' field */
|
2009-05-06 02:17:26 +08:00
|
|
|
#define FUNC_NEW 1 /* ansi function prototype */
|
|
|
|
#define FUNC_OLD 2 /* old function prototype */
|
|
|
|
#define FUNC_ELLIPSIS 3 /* ansi function prototype with ... */
|
|
|
|
|
2017-07-09 18:34:11 +08:00
|
|
|
/* stored in 'Sym->f.func_call' field */
|
2009-05-06 02:17:26 +08:00
|
|
|
#define FUNC_CDECL 0 /* standard c call */
|
|
|
|
#define FUNC_STDCALL 1 /* pascal c call */
|
|
|
|
#define FUNC_FASTCALL1 2 /* first param in %eax */
|
|
|
|
#define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */
|
|
|
|
#define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */
|
|
|
|
#define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */
|
|
|
|
|
|
|
|
/* field 'Sym.t' for macros */
|
|
|
|
#define MACRO_OBJ 0 /* object like macro */
|
|
|
|
#define MACRO_FUNC 1 /* function like macro */
|
|
|
|
|
|
|
|
/* field 'Sym.r' for C labels */
|
|
|
|
#define LABEL_DEFINED 0 /* label is defined */
|
|
|
|
#define LABEL_FORWARD 1 /* label is forward defined */
|
|
|
|
#define LABEL_DECLARED 2 /* label is declared but never used */
|
2020-04-15 04:35:58 +08:00
|
|
|
#define LABEL_GONE 3 /* label isn't in scope, but not yet popped
|
|
|
|
from local_label_stack (stmt exprs) */
|
2009-05-06 02:17:26 +08:00
|
|
|
|
|
|
|
/* type_decl() types */
|
|
|
|
#define TYPE_ABSTRACT 1 /* type without variable */
|
|
|
|
#define TYPE_DIRECT 2 /* type with variable */
|
2022-03-02 05:00:42 +08:00
|
|
|
#define TYPE_PARAM 4 /* type declares function parameter */
|
2022-03-24 17:16:37 +08:00
|
|
|
#define TYPE_NEST 8 /* nested call to post_type */
|
2009-05-06 02:17:26 +08:00
|
|
|
|
|
|
|
#define IO_BUF_SIZE 8192
|
|
|
|
|
|
|
|
typedef struct BufferedFile {
|
|
|
|
uint8_t *buf_ptr;
|
|
|
|
uint8_t *buf_end;
|
2013-01-15 00:34:07 +08:00
|
|
|
int fd;
|
2010-11-25 20:29:15 +08:00
|
|
|
struct BufferedFile *prev;
|
2009-05-06 02:17:26 +08:00
|
|
|
int line_num; /* current line number - here to simplify code */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 20:29:39 +08:00
|
|
|
int line_ref; /* tcc -E: last printed line */
|
2009-05-06 02:17:26 +08:00
|
|
|
int ifndef_macro; /* #ifndef macro / #endif search */
|
|
|
|
int ifndef_macro_saved; /* saved ifndef_macro */
|
|
|
|
int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */
|
2015-11-20 19:05:55 +08:00
|
|
|
int include_next_index; /* next search path */
|
2013-01-07 00:20:44 +08:00
|
|
|
char filename[1024]; /* filename */
|
2017-07-09 18:07:40 +08:00
|
|
|
char *true_filename; /* filename not modified by # line directive */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 20:29:39 +08:00
|
|
|
unsigned char unget[4];
|
2014-12-11 09:58:53 +08:00
|
|
|
unsigned char buffer[1]; /* extra size for CH_EOB char */
|
2009-05-06 02:17:26 +08:00
|
|
|
} BufferedFile;
|
|
|
|
|
|
|
|
#define CH_EOB '\\' /* end of buffer or '\0' char in file */
|
|
|
|
#define CH_EOF (-1) /* end of file */
|
|
|
|
|
|
|
|
/* used to record tokens */
|
|
|
|
typedef struct TokenString {
|
|
|
|
int *str;
|
|
|
|
int len;
|
2017-06-05 19:21:39 +08:00
|
|
|
int lastlen;
|
2009-05-06 02:17:26 +08:00
|
|
|
int allocated_len;
|
|
|
|
int last_line_num;
|
2017-07-21 04:21:27 +08:00
|
|
|
int save_line_num;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 20:29:39 +08:00
|
|
|
/* used to chain token-strings with begin/end_macro() */
|
|
|
|
struct TokenString *prev;
|
|
|
|
const int *prev_ptr;
|
|
|
|
char alloc;
|
2009-05-06 02:17:26 +08:00
|
|
|
} TokenString;
|
|
|
|
|
2018-12-20 17:55:22 +08:00
|
|
|
/* GNUC attribute definition */
|
|
|
|
typedef struct AttributeDef {
|
|
|
|
struct SymAttr a;
|
|
|
|
struct FuncAttr f;
|
|
|
|
struct Section *section;
|
|
|
|
Sym *cleanup_func;
|
Reinstate attribute alias handling
commit 2a0167a merged alias and asm symbol renaming, but broke
semantics of aliases, see testcase. Basically the difference between
the two is that an asm rename doesn't generate a new symbol, i.e. with
int foo __asm__("bar");
all source reference to 'foo' will be to 'bar', nothing of the name
'foo' will remain in the object file, and for instance reference to
'foo' from other compilation units won't be resolved to this one.
Aliases OTOH create an additional symbol. With:
void target (void) { return; }
void afunc (void) __attribute__((alias("target")));
reference to 'afunc' will remain 'afunc' in the object file. It will
generate two symbols, 'afunc' and 'target' referring to the same entity.
This difference matters if other compilation units make references to
'afunc'.
A side requirement of this is that for alias to work that the target
symbol needs to be defined in the same unit. For TCC we even require a
stricter variant: it must be defined before the alias is created.
Now, with this I merely re-instated the old flow of events before above
commit. It didn't seem useful anymore to place both names in the
asm_label member of attributes, and the asm_label member of Sym now
again only needs the hold the __asm__ rename.
It also follows that tcc_predefs.h can't make use of attribute alias to
e.g. map __builtin_memcpy to __bound_memcpy (simply because the latter
isn't defined in all units), but rather must use __asm__ renaming, which
in turn means that the underscore handling needs to be done by hand.
2020-09-30 23:46:01 +08:00
|
|
|
int alias_target; /* token */
|
2018-12-20 17:55:22 +08:00
|
|
|
int asm_label; /* associated asm label */
|
|
|
|
char attr_mode; /* __attribute__((__mode__(...))) */
|
|
|
|
} AttributeDef;
|
|
|
|
|
2009-06-30 03:14:53 +08:00
|
|
|
/* inline functions */
|
|
|
|
typedef struct InlineFunc {
|
2016-11-12 01:29:45 +08:00
|
|
|
TokenString *func_str;
|
2009-06-30 03:14:53 +08:00
|
|
|
Sym *sym;
|
|
|
|
char filename[1];
|
|
|
|
} InlineFunc;
|
|
|
|
|
2009-05-06 02:17:26 +08:00
|
|
|
/* include file cache, used to find files faster and also to eliminate
|
|
|
|
inclusion if the include file is protected by #ifndef ... #endif */
|
|
|
|
typedef struct CachedInclude {
|
|
|
|
int ifndef_macro;
|
2016-10-02 02:03:48 +08:00
|
|
|
int once;
|
2009-05-06 02:17:26 +08:00
|
|
|
int hash_next; /* -1 if none */
|
|
|
|
char filename[1]; /* path specified in #include */
|
|
|
|
} CachedInclude;
|
|
|
|
|
2016-10-02 02:03:48 +08:00
|
|
|
#define CACHED_INCLUDES_HASH_SIZE 32
|
2009-05-06 02:17:26 +08:00
|
|
|
|
2009-05-12 00:45:56 +08:00
|
|
|
#ifdef CONFIG_TCC_ASM
|
|
|
|
typedef struct ExprValue {
|
2016-05-12 05:47:02 +08:00
|
|
|
uint64_t v;
|
2009-05-12 00:45:56 +08:00
|
|
|
Sym *sym;
|
2016-06-29 21:57:32 +08:00
|
|
|
int pcrel;
|
2009-05-12 00:45:56 +08:00
|
|
|
} ExprValue;
|
|
|
|
|
|
|
|
#define MAX_ASM_OPERANDS 30
|
|
|
|
typedef struct ASMOperand {
|
2017-05-08 12:38:09 +08:00
|
|
|
int id; /* GCC 3 optional identifier (0 if number only supported */
|
2009-05-12 00:45:56 +08:00
|
|
|
char *constraint;
|
|
|
|
char asm_str[16]; /* computed asm string for operand */
|
|
|
|
SValue *vt; /* C value of the expression */
|
|
|
|
int ref_index; /* if >= 0, gives reference to a output constraint */
|
|
|
|
int input_index; /* if >= 0, gives reference to an input constraint */
|
|
|
|
int priority; /* priority, used to assign registers */
|
|
|
|
int reg; /* if >= 0, register number used for this operand */
|
|
|
|
int is_llong; /* true if double register value */
|
|
|
|
int is_memory; /* true if memory operand */
|
|
|
|
int is_rw; /* for '+' modifier */
|
|
|
|
} ASMOperand;
|
|
|
|
#endif
|
|
|
|
|
2016-11-12 23:16:07 +08:00
|
|
|
/* extra symbol attributes (not in symbol table) */
|
2012-11-04 07:40:05 +08:00
|
|
|
struct sym_attr {
|
2016-12-16 00:01:22 +08:00
|
|
|
unsigned got_offset;
|
|
|
|
unsigned plt_offset;
|
|
|
|
int plt_sym;
|
|
|
|
int dyn_index;
|
2012-11-04 07:40:05 +08:00
|
|
|
#ifdef TCC_TARGET_ARM
|
|
|
|
unsigned char plt_thumb_stub:1;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2009-05-06 02:17:26 +08:00
|
|
|
struct TCCState {
|
2019-12-02 04:22:57 +08:00
|
|
|
unsigned char verbose; /* if true, display some information during compilation */
|
|
|
|
unsigned char nostdinc; /* if true, no standard headers are added */
|
|
|
|
unsigned char nostdlib; /* if true, no standard libraries are added */
|
|
|
|
unsigned char nocommon; /* if true, do not use common symbols for .bss data */
|
|
|
|
unsigned char static_link; /* if true, static linking is performed */
|
|
|
|
unsigned char rdynamic; /* if true, all symbols are exported */
|
|
|
|
unsigned char symbolic; /* if true, resolve symbols in the current module first */
|
|
|
|
unsigned char filetype; /* file type for compilation (NONE,C,ASM) */
|
2020-06-02 00:10:58 +08:00
|
|
|
unsigned char optimize; /* only to #define __OPTIMIZE__ */
|
|
|
|
unsigned char option_pthread; /* -pthread option */
|
|
|
|
unsigned char enable_new_dtags; /* -Wl,--enable-new-dtags */
|
2019-12-02 04:22:57 +08:00
|
|
|
unsigned int cversion; /* supported C ISO version, 199901 (the default), 201112, ... */
|
2009-05-06 02:17:26 +08:00
|
|
|
|
|
|
|
/* C language options */
|
2019-12-02 04:22:57 +08:00
|
|
|
unsigned char char_is_unsigned;
|
|
|
|
unsigned char leading_underscore;
|
|
|
|
unsigned char ms_extensions; /* allow nested named struct w/o identifier behave like unnamed */
|
|
|
|
unsigned char dollars_in_identifiers; /* allows '$' char in identifiers */
|
|
|
|
unsigned char ms_bitfields; /* if true, emulate MS algorithm for aligning bitfields */
|
2016-04-03 16:42:15 +08:00
|
|
|
|
2021-08-01 02:44:51 +08:00
|
|
|
/* warning switches */
|
|
|
|
unsigned char warn_none;
|
|
|
|
unsigned char warn_all;
|
|
|
|
unsigned char warn_error;
|
|
|
|
unsigned char warn_write_strings;
|
|
|
|
unsigned char warn_unsupported;
|
|
|
|
unsigned char warn_implicit_function_declaration;
|
|
|
|
unsigned char warn_discarded_qualifiers;
|
|
|
|
#define WARN_ON 1 /* warning is on (-Woption) */
|
|
|
|
unsigned char warn_num; /* temp var for tcc_warning_c() */
|
2009-05-06 02:17:26 +08:00
|
|
|
|
2021-08-02 02:04:46 +08:00
|
|
|
unsigned char option_r; /* option -r */
|
|
|
|
unsigned char do_bench; /* option -bench */
|
|
|
|
unsigned char just_deps; /* option -M */
|
|
|
|
unsigned char gen_deps; /* option -MD */
|
|
|
|
unsigned char include_sys_deps; /* option -MD */
|
|
|
|
|
2009-05-12 00:45:44 +08:00
|
|
|
/* compile with debug symbol (and use them if error during execution) */
|
2019-12-02 04:22:57 +08:00
|
|
|
unsigned char do_debug;
|
Add dwarf support
The new gcc12 release does not support stabs any more.
This was a good reason to add support for dwarf.
The stabs code still works and is used if configure option --dwarf
is not used.
Tested on x86_64, i386, arm, arm64, riscv64 with dwarf-5.
Some debuggers may not support dwarf-5. Try using older dwarf versions
i that case.
The tccmacho.c code probably need some support for dwarf.
arm-gen.c, arm64-gen.c, i386-gen.c, riscv64-gen.c, x86_64-gen.
- fix get_sym_ref symbol size
arm-link.c, arm64-link.c, i386-link.c, riscv64-link.c, x86_64-link.c
- add R_DATA_32U
libtcc.c:
- parse -gdwarf option
tcc.c:
- add dwarf option
tcc.h:
- add dwarf option and sections
tccelf.c:
- init dwarf sections
- avoid adding sh_addr for dwarf sections
- remove dwarf relocs for output dll
- add dwarf sections for tccrun
tccgen.c:
- add dwarf defines + global data
- add dwarf_* functions
- mix dwarf code with stabs code
- a trick is used to emit function name in .debug_line section so
only this section has to be parsed instead of .debug_info and
.debug_abbrev.
- fix init debug_modes
tccrun.c:
- add dwarf sections in rt_context
- init them in tcc_run
- add new dwarf code rt_printline_dwarf to find file/function
dwarf.h:
- New file
tcc-doc.texi:
- document dwarf
configure:
- add dwarf option
lib/Makefile
- change -gstabs into -gdwarf
lib/bt-exe.c, tests/tests2/Makefile, tests/tests2/126_bound_global:
- Add __bound_init call
- Add new testcase to test it
2022-05-05 15:10:37 +08:00
|
|
|
unsigned char dwarf;
|
2020-01-18 05:58:39 +08:00
|
|
|
unsigned char do_backtrace;
|
2009-12-20 05:22:43 +08:00
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
2009-05-12 00:45:44 +08:00
|
|
|
/* compile with built-in memory and bounds checker */
|
2019-12-02 04:22:57 +08:00
|
|
|
unsigned char do_bounds_check;
|
2009-12-20 05:22:43 +08:00
|
|
|
#endif
|
2021-01-24 23:20:48 +08:00
|
|
|
unsigned char test_coverage; /* generate test coverage code */
|
|
|
|
|
2021-08-02 02:04:46 +08:00
|
|
|
/* use GNU C extensions */
|
|
|
|
unsigned char gnu_ext;
|
|
|
|
/* use TinyCC extensions */
|
|
|
|
unsigned char tcc_ext;
|
|
|
|
|
|
|
|
unsigned char dflag; /* -dX value */
|
|
|
|
unsigned char Pflag; /* -P switch (LINE_MACRO_OUTPUT_FORMAT) */
|
|
|
|
|
|
|
|
#ifdef TCC_TARGET_X86_64
|
|
|
|
unsigned char nosse; /* For -mno-sse support. */
|
|
|
|
#endif
|
2014-01-07 15:23:54 +08:00
|
|
|
#ifdef TCC_TARGET_ARM
|
2021-08-02 02:04:46 +08:00
|
|
|
unsigned char float_abi; /* float ABI of the generated code*/
|
2014-01-07 15:23:54 +08:00
|
|
|
#endif
|
2013-02-13 02:13:28 +08:00
|
|
|
|
2019-12-02 04:22:57 +08:00
|
|
|
unsigned char has_text_addr;
|
2021-08-02 02:04:46 +08:00
|
|
|
addr_t text_addr; /* address of text section */
|
2016-12-16 00:01:22 +08:00
|
|
|
unsigned section_align; /* section alignment */
|
2021-08-02 02:04:46 +08:00
|
|
|
#ifdef TCC_TARGET_I386
|
|
|
|
int seg_size; /* 32. Can be 16 with i386 assembler (.code16) */
|
|
|
|
#endif
|
2013-02-13 02:13:28 +08:00
|
|
|
|
2021-08-02 02:04:46 +08:00
|
|
|
char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */
|
|
|
|
char *soname; /* as specified on the command line (-soname) */
|
|
|
|
char *rpath; /* as specified on the command line (-Wl,-rpath=) */
|
2022-05-08 05:16:13 +08:00
|
|
|
char *elf_entryname; /* "_start" unless set */
|
2013-02-13 02:13:28 +08:00
|
|
|
char *init_symbol; /* symbols to call at load-time (not used currently) */
|
|
|
|
char *fini_symbol; /* symbols to call at unload-time (not used currently) */
|
2017-09-26 13:16:23 +08:00
|
|
|
|
2021-08-02 02:04:46 +08:00
|
|
|
/* output type, see TCC_OUTPUT_XXX */
|
|
|
|
int output_type;
|
|
|
|
/* output format, see TCC_OUTPUT_FORMAT_xxx */
|
|
|
|
int output_format;
|
|
|
|
/* nth test to run with -dt -run */
|
|
|
|
int run_test;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
|
|
|
/* array of all loaded dlls (including those referenced by loaded dlls) */
|
|
|
|
DLLReference **loaded_dlls;
|
|
|
|
int nb_loaded_dlls;
|
|
|
|
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-12 00:13:43 +08:00
|
|
|
/* include paths */
|
2013-02-13 02:13:28 +08:00
|
|
|
char **include_paths;
|
|
|
|
int nb_include_paths;
|
|
|
|
|
|
|
|
char **sysinclude_paths;
|
|
|
|
int nb_sysinclude_paths;
|
|
|
|
|
|
|
|
/* library paths */
|
|
|
|
char **library_paths;
|
|
|
|
int nb_library_paths;
|
|
|
|
|
|
|
|
/* crt?.o object path */
|
|
|
|
char **crt_paths;
|
|
|
|
int nb_crt_paths;
|
2009-05-12 00:45:44 +08:00
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
/* -D / -U options */
|
|
|
|
CString cmdline_defs;
|
|
|
|
/* -include options */
|
|
|
|
CString cmdline_incl;
|
2016-06-27 22:40:00 +08:00
|
|
|
|
2009-05-06 02:17:26 +08:00
|
|
|
/* error handling */
|
|
|
|
void *error_opaque;
|
|
|
|
void (*error_func)(void *opaque, const char *msg);
|
|
|
|
int error_set_jmp_enabled;
|
|
|
|
jmp_buf error_jmp_buf;
|
|
|
|
int nb_errors;
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
/* output file for preprocessing (-E) */
|
|
|
|
FILE *ppfp;
|
2009-05-06 02:17:26 +08:00
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
/* for -MD/-MF: collected dependencies for this compilation */
|
|
|
|
char **target_deps;
|
|
|
|
int nb_target_deps;
|
|
|
|
|
|
|
|
/* compilation */
|
2009-05-06 02:17:26 +08:00
|
|
|
BufferedFile *include_stack[INCLUDE_STACK_SIZE];
|
2013-02-13 02:13:28 +08:00
|
|
|
BufferedFile **include_stack_ptr;
|
2009-05-06 02:17:26 +08:00
|
|
|
|
|
|
|
int ifdef_stack[IFDEF_STACK_SIZE];
|
2013-02-13 02:13:28 +08:00
|
|
|
int *ifdef_stack_ptr;
|
2009-05-06 02:17:26 +08:00
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
/* included files enclosed with #ifndef MACRO */
|
2009-05-06 02:17:26 +08:00
|
|
|
int cached_includes_hash[CACHED_INCLUDES_HASH_SIZE];
|
2013-02-13 02:13:28 +08:00
|
|
|
CachedInclude **cached_includes;
|
|
|
|
int nb_cached_includes;
|
2009-05-06 02:17:26 +08:00
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
/* #pragma pack stack */
|
2009-05-06 02:17:26 +08:00
|
|
|
int pack_stack[PACK_STACK_SIZE];
|
|
|
|
int *pack_stack_ptr;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 20:29:39 +08:00
|
|
|
char **pragma_libs;
|
|
|
|
int nb_pragma_libs;
|
2009-05-06 02:17:26 +08:00
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
/* inline functions are stored as token lists and compiled last
|
|
|
|
only if referenced */
|
2009-06-30 03:14:53 +08:00
|
|
|
struct InlineFunc **inline_fns;
|
|
|
|
int nb_inline_fns;
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
/* sections */
|
|
|
|
Section **sections;
|
|
|
|
int nb_sections; /* number of sections, including first dummy section */
|
|
|
|
|
|
|
|
Section **priv_sections;
|
|
|
|
int nb_priv_sections; /* number of private sections */
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
/* predefined sections */
|
2021-02-01 22:10:58 +08:00
|
|
|
Section *text_section, *data_section, *rodata_section, *bss_section;
|
2019-12-11 07:37:18 +08:00
|
|
|
Section *common_section;
|
|
|
|
Section *cur_text_section; /* current section where function code is generated */
|
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
|
|
|
/* bound check related sections */
|
|
|
|
Section *bounds_section; /* contains global data bound description */
|
|
|
|
Section *lbounds_section; /* contains local data bound description */
|
|
|
|
#endif
|
2022-05-09 23:02:09 +08:00
|
|
|
/* symbol section */
|
2019-12-11 07:37:18 +08:00
|
|
|
Section *symtab_section;
|
2022-05-09 23:02:09 +08:00
|
|
|
/* temporary dynamic symbol sections (for dll loading) */
|
|
|
|
Section *dynsymtab_section;
|
|
|
|
/* exported dynamic symbol section */
|
|
|
|
Section *dynsym;
|
|
|
|
/* copy of the global symtab_section variable */
|
|
|
|
Section *symtab;
|
|
|
|
/* got & plt handling */
|
|
|
|
Section *got, *plt;
|
2019-12-11 07:37:18 +08:00
|
|
|
/* debug sections */
|
|
|
|
Section *stab_section;
|
Add dwarf support
The new gcc12 release does not support stabs any more.
This was a good reason to add support for dwarf.
The stabs code still works and is used if configure option --dwarf
is not used.
Tested on x86_64, i386, arm, arm64, riscv64 with dwarf-5.
Some debuggers may not support dwarf-5. Try using older dwarf versions
i that case.
The tccmacho.c code probably need some support for dwarf.
arm-gen.c, arm64-gen.c, i386-gen.c, riscv64-gen.c, x86_64-gen.
- fix get_sym_ref symbol size
arm-link.c, arm64-link.c, i386-link.c, riscv64-link.c, x86_64-link.c
- add R_DATA_32U
libtcc.c:
- parse -gdwarf option
tcc.c:
- add dwarf option
tcc.h:
- add dwarf option and sections
tccelf.c:
- init dwarf sections
- avoid adding sh_addr for dwarf sections
- remove dwarf relocs for output dll
- add dwarf sections for tccrun
tccgen.c:
- add dwarf defines + global data
- add dwarf_* functions
- mix dwarf code with stabs code
- a trick is used to emit function name in .debug_line section so
only this section has to be parsed instead of .debug_info and
.debug_abbrev.
- fix init debug_modes
tccrun.c:
- add dwarf sections in rt_context
- init them in tcc_run
- add new dwarf code rt_printline_dwarf to find file/function
dwarf.h:
- New file
tcc-doc.texi:
- document dwarf
configure:
- add dwarf option
lib/Makefile
- change -gstabs into -gdwarf
lib/bt-exe.c, tests/tests2/Makefile, tests/tests2/126_bound_global:
- Add __bound_init call
- Add new testcase to test it
2022-05-05 15:10:37 +08:00
|
|
|
Section *dwarf_info_section;
|
|
|
|
Section *dwarf_abbrev_section;
|
|
|
|
Section *dwarf_line_section;
|
|
|
|
Section *dwarf_aranges_section;
|
|
|
|
Section *dwarf_str_section;
|
|
|
|
Section *dwarf_line_str_section;
|
2022-05-09 23:02:09 +08:00
|
|
|
int dwlo, dwhi; /* dwarf section range */
|
|
|
|
/* test coverage */
|
|
|
|
Section *tcov_section;
|
|
|
|
/* debug state */
|
|
|
|
struct _tccdbg *dState;
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
/* Is there a new undefined sym since last new_undef_sym() */
|
|
|
|
int new_undef_sym;
|
2016-11-12 23:16:07 +08:00
|
|
|
/* extra attributes (eg. GOT/PLT value) for symtab symbols */
|
|
|
|
struct sym_attr *sym_attrs;
|
|
|
|
int nb_sym_attrs;
|
2019-12-10 03:32:13 +08:00
|
|
|
/* ptr to next reloc entry reused */
|
|
|
|
ElfW_Rel *qrel;
|
2021-10-22 13:39:54 +08:00
|
|
|
#define qrel s1->qrel
|
2017-11-30 22:15:22 +08:00
|
|
|
|
2020-12-08 02:02:42 +08:00
|
|
|
#ifdef TCC_TARGET_RISCV64
|
|
|
|
struct pcrel_hi { addr_t addr, val; } last_hi;
|
2021-10-22 13:39:54 +08:00
|
|
|
#define last_hi s1->last_hi
|
2020-12-08 02:02:42 +08:00
|
|
|
#endif
|
|
|
|
|
2009-08-27 16:12:13 +08:00
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
/* PE info */
|
|
|
|
int pe_subsystem;
|
2016-12-12 22:52:45 +08:00
|
|
|
unsigned pe_characteristics;
|
2013-02-13 02:13:28 +08:00
|
|
|
unsigned pe_file_align;
|
|
|
|
unsigned pe_stack_size;
|
2017-12-13 00:57:20 +08:00
|
|
|
addr_t pe_imagebase;
|
2013-02-13 02:13:28 +08:00
|
|
|
# ifdef TCC_TARGET_X86_64
|
2011-07-15 01:09:49 +08:00
|
|
|
Section *uw_pdata;
|
|
|
|
int uw_sym;
|
|
|
|
unsigned uw_offs;
|
2013-02-13 02:13:28 +08:00
|
|
|
# endif
|
2020-05-09 07:40:36 +08:00
|
|
|
#endif
|
|
|
|
|
2019-12-10 03:32:13 +08:00
|
|
|
#ifndef ELF_OBJ_ONLY
|
|
|
|
int nb_sym_versions;
|
|
|
|
struct sym_version *sym_versions;
|
|
|
|
int nb_sym_to_version;
|
|
|
|
int *sym_to_version;
|
|
|
|
int dt_verneednum;
|
|
|
|
Section *versym_section;
|
|
|
|
Section *verneed_section;
|
2009-08-27 16:12:13 +08:00
|
|
|
#endif
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
#ifdef TCC_IS_NATIVE
|
2013-08-29 04:55:05 +08:00
|
|
|
const char *runtime_main;
|
2016-10-20 01:21:27 +08:00
|
|
|
void **runtime_mem;
|
|
|
|
int nb_runtime_mem;
|
2020-01-19 18:15:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_TCC_BACKTRACE
|
2019-12-11 07:37:18 +08:00
|
|
|
int rt_num_callers;
|
2009-07-19 04:05:27 +08:00
|
|
|
#endif
|
2013-02-13 02:13:28 +08:00
|
|
|
|
2019-12-14 19:31:03 +08:00
|
|
|
/* benchmark info */
|
|
|
|
int total_idents;
|
|
|
|
int total_lines;
|
|
|
|
int total_bytes;
|
2021-02-01 22:10:58 +08:00
|
|
|
int total_output[4];
|
2019-12-14 19:31:03 +08:00
|
|
|
|
|
|
|
/* option -dnum (for general development purposes) */
|
|
|
|
int g_debug;
|
|
|
|
|
2021-08-02 02:04:46 +08:00
|
|
|
/* used by tcc_load_ldscript */
|
|
|
|
int fd, cc;
|
|
|
|
|
|
|
|
/* for warnings/errors for object files */
|
2020-06-17 14:21:37 +08:00
|
|
|
const char *current_filename;
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
/* used by main and tcc_parse_args only */
|
2016-10-02 02:04:58 +08:00
|
|
|
struct filespec **files; /* files seen on command line */
|
2013-02-13 02:13:28 +08:00
|
|
|
int nb_files; /* number thereof */
|
|
|
|
int nb_libraries; /* number of libs thereof */
|
|
|
|
char *outfile; /* output filename */
|
|
|
|
char *deps_outfile; /* option -MF */
|
2017-02-18 16:55:34 +08:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
2009-05-06 02:17:26 +08:00
|
|
|
};
|
|
|
|
|
2016-10-02 02:04:58 +08:00
|
|
|
struct filespec {
|
2017-02-18 16:55:34 +08:00
|
|
|
char type;
|
|
|
|
char name[1];
|
2016-10-02 02:04:58 +08:00
|
|
|
};
|
|
|
|
|
2009-05-06 02:17:26 +08:00
|
|
|
/* The current value can be: */
|
2013-02-13 02:13:28 +08:00
|
|
|
#define VT_VALMASK 0x003f /* mask for value location, register or: */
|
|
|
|
#define VT_CONST 0x0030 /* constant in vc (must be first non register value) */
|
2011-08-06 22:08:03 +08:00
|
|
|
#define VT_LLOCAL 0x0031 /* lvalue, offset on stack */
|
|
|
|
#define VT_LOCAL 0x0032 /* offset on stack */
|
|
|
|
#define VT_CMP 0x0033 /* the value is stored in processor flags (in vc) */
|
|
|
|
#define VT_JMP 0x0034 /* value is the consequence of jmp true (even) */
|
|
|
|
#define VT_JMPI 0x0035 /* value is the consequence of jmp false (odd) */
|
2009-05-06 02:17:26 +08:00
|
|
|
#define VT_LVAL 0x0100 /* var is an lvalue */
|
|
|
|
#define VT_SYM 0x0200 /* a symbol value is added */
|
2019-12-17 01:51:28 +08:00
|
|
|
#define VT_MUSTCAST 0x0C00 /* value must be casted to be correct (used for
|
2009-05-06 02:17:26 +08:00
|
|
|
char/short stored in integer registers) */
|
2019-12-17 01:51:28 +08:00
|
|
|
#define VT_MUSTBOUND 0x4000 /* bound checking must be done before
|
2009-05-06 02:17:26 +08:00
|
|
|
dereferencing value */
|
|
|
|
#define VT_BOUNDED 0x8000 /* value is bounded. The address of the
|
|
|
|
bounding function call point is in vc */
|
|
|
|
/* types */
|
2013-02-13 02:13:28 +08:00
|
|
|
#define VT_BTYPE 0x000f /* mask for basic type */
|
2017-07-09 18:34:11 +08:00
|
|
|
#define VT_VOID 0 /* void type */
|
2013-02-13 02:13:28 +08:00
|
|
|
#define VT_BYTE 1 /* signed byte type */
|
|
|
|
#define VT_SHORT 2 /* short type */
|
2017-07-09 18:34:11 +08:00
|
|
|
#define VT_INT 3 /* integer type */
|
|
|
|
#define VT_LLONG 4 /* 64 bit integer */
|
|
|
|
#define VT_PTR 5 /* pointer */
|
2013-02-13 02:13:28 +08:00
|
|
|
#define VT_FUNC 6 /* function type */
|
|
|
|
#define VT_STRUCT 7 /* struct/union definition */
|
2017-07-09 18:38:25 +08:00
|
|
|
#define VT_FLOAT 8 /* IEEE float */
|
|
|
|
#define VT_DOUBLE 9 /* IEEE double */
|
|
|
|
#define VT_LDOUBLE 10 /* IEEE long double */
|
|
|
|
#define VT_BOOL 11 /* ISOC99 boolean type */
|
|
|
|
#define VT_QLONG 13 /* 128-bit integer. Only used for x86-64 ABI */
|
|
|
|
#define VT_QFLOAT 14 /* 128-bit float. Only used for x86-64 ABI */
|
2017-07-09 18:34:11 +08:00
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
#define VT_UNSIGNED 0x0010 /* unsigned type */
|
2017-07-09 18:34:11 +08:00
|
|
|
#define VT_DEFSIGN 0x0020 /* explicitly signed or unsigned */
|
|
|
|
#define VT_ARRAY 0x0040 /* array type (also has VT_PTR) */
|
|
|
|
#define VT_BITFIELD 0x0080 /* bitfield modifier */
|
|
|
|
#define VT_CONSTANT 0x0100 /* const modifier */
|
|
|
|
#define VT_VOLATILE 0x0200 /* volatile modifier */
|
|
|
|
#define VT_VLA 0x0400 /* VLA type (also has VT_PTR and VT_ARRAY) */
|
2017-09-25 00:57:48 +08:00
|
|
|
#define VT_LONG 0x0800 /* long type (also has VT_INT rsp. VT_LLONG) */
|
2009-05-06 02:17:26 +08:00
|
|
|
|
|
|
|
/* storage */
|
2017-07-09 18:34:11 +08:00
|
|
|
#define VT_EXTERN 0x00001000 /* extern definition */
|
|
|
|
#define VT_STATIC 0x00002000 /* static variable */
|
|
|
|
#define VT_TYPEDEF 0x00004000 /* typedef definition */
|
|
|
|
#define VT_INLINE 0x00008000 /* inline definition */
|
2019-06-17 09:34:03 +08:00
|
|
|
/* currently unused: 0x000[1248]0000 */
|
2009-05-06 02:17:26 +08:00
|
|
|
|
2017-07-09 18:34:11 +08:00
|
|
|
#define VT_STRUCT_SHIFT 20 /* shift for bitfield shift values (32 - 2*6) */
|
2019-06-22 06:42:24 +08:00
|
|
|
#define VT_STRUCT_MASK (((1U << (6+6)) - 1) << VT_STRUCT_SHIFT | VT_BITFIELD)
|
2017-07-09 18:34:11 +08:00
|
|
|
#define BIT_POS(t) (((t) >> VT_STRUCT_SHIFT) & 0x3f)
|
|
|
|
#define BIT_SIZE(t) (((t) >> (VT_STRUCT_SHIFT + 6)) & 0x3f)
|
2014-04-14 08:53:11 +08:00
|
|
|
|
2017-07-09 18:38:25 +08:00
|
|
|
#define VT_UNION (1 << VT_STRUCT_SHIFT | VT_STRUCT)
|
|
|
|
#define VT_ENUM (2 << VT_STRUCT_SHIFT) /* integral type is an enum really */
|
|
|
|
#define VT_ENUM_VAL (3 << VT_STRUCT_SHIFT) /* integral type is an enum constant really */
|
|
|
|
|
|
|
|
#define IS_ENUM(t) ((t & VT_STRUCT_MASK) == VT_ENUM)
|
|
|
|
#define IS_ENUM_VAL(t) ((t & VT_STRUCT_MASK) == VT_ENUM_VAL)
|
|
|
|
#define IS_UNION(t) ((t & (VT_STRUCT_MASK|VT_BTYPE)) == VT_UNION)
|
|
|
|
|
2021-01-26 21:29:07 +08:00
|
|
|
#define VT_ATOMIC VT_VOLATILE
|
|
|
|
|
2009-05-06 02:17:26 +08:00
|
|
|
/* type mask (except storage) */
|
2019-06-17 09:34:03 +08:00
|
|
|
#define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE)
|
2017-07-09 18:38:25 +08:00
|
|
|
#define VT_TYPE (~(VT_STORAGE|VT_STRUCT_MASK))
|
2017-07-09 18:34:11 +08:00
|
|
|
|
2017-11-30 22:15:22 +08:00
|
|
|
/* symbol was created by tccasm.c first */
|
2020-11-25 18:23:01 +08:00
|
|
|
#define VT_ASM (VT_VOID | 1 << VT_STRUCT_SHIFT)
|
|
|
|
#define VT_ASM_FUNC (VT_ASM | 2 << VT_STRUCT_SHIFT)
|
2017-11-30 22:15:22 +08:00
|
|
|
#define IS_ASM_SYM(sym) (((sym)->type.t & (VT_BTYPE | VT_ASM)) == VT_ASM)
|
|
|
|
|
2019-12-17 01:51:28 +08:00
|
|
|
/* general: set/get the pseudo-bitfield value for bit-mask M */
|
|
|
|
#define BFVAL(M,N) ((unsigned)((M) & ~((M) << 1)) * (N))
|
|
|
|
#define BFGET(X,M) (((X) & (M)) / BFVAL(M,1))
|
|
|
|
#define BFSET(X,M,N) ((X) = ((X) & ~(M)) | BFVAL(M,N))
|
|
|
|
|
2009-05-06 02:17:26 +08:00
|
|
|
/* token values */
|
|
|
|
|
2020-06-18 00:08:09 +08:00
|
|
|
/* conditional ops */
|
|
|
|
#define TOK_LAND 0x90
|
|
|
|
#define TOK_LOR 0x91
|
2009-05-06 02:17:26 +08:00
|
|
|
/* warning: the following compare tokens depend on i386 asm code */
|
|
|
|
#define TOK_ULT 0x92
|
|
|
|
#define TOK_UGE 0x93
|
|
|
|
#define TOK_EQ 0x94
|
|
|
|
#define TOK_NE 0x95
|
|
|
|
#define TOK_ULE 0x96
|
|
|
|
#define TOK_UGT 0x97
|
|
|
|
#define TOK_Nset 0x98
|
|
|
|
#define TOK_Nclear 0x99
|
|
|
|
#define TOK_LT 0x9c
|
|
|
|
#define TOK_GE 0x9d
|
|
|
|
#define TOK_LE 0x9e
|
|
|
|
#define TOK_GT 0x9f
|
|
|
|
|
2020-06-18 00:08:09 +08:00
|
|
|
#define TOK_ISCOND(t) (t >= TOK_LAND && t <= TOK_GT)
|
|
|
|
|
|
|
|
#define TOK_DEC 0x80 /* -- */
|
|
|
|
#define TOK_MID 0x81 /* inc/dec, to void constant */
|
|
|
|
#define TOK_INC 0x82 /* ++ */
|
|
|
|
#define TOK_UDIV 0x83 /* unsigned division */
|
|
|
|
#define TOK_UMOD 0x84 /* unsigned modulo */
|
|
|
|
#define TOK_PDIV 0x85 /* fast division with undefined rounding for pointers */
|
|
|
|
#define TOK_UMULL 0x86 /* unsigned 32x32 -> 64 mul */
|
|
|
|
#define TOK_ADDC1 0x87 /* add with carry generation */
|
|
|
|
#define TOK_ADDC2 0x88 /* add with carry use */
|
|
|
|
#define TOK_SUBC1 0x89 /* add with carry generation */
|
|
|
|
#define TOK_SUBC2 0x8a /* add with carry use */
|
|
|
|
#define TOK_SHL '<' /* shift left */
|
|
|
|
#define TOK_SAR '>' /* signed shift right */
|
|
|
|
#define TOK_SHR 0x8b /* unsigned shift right */
|
2021-01-04 20:16:05 +08:00
|
|
|
#define TOK_NEG TOK_MID /* unary minus operation (for floats) */
|
2020-06-18 00:08:09 +08:00
|
|
|
|
|
|
|
#define TOK_ARROW 0xa0 /* -> */
|
|
|
|
#define TOK_DOTS 0xa1 /* three dots */
|
|
|
|
#define TOK_TWODOTS 0xa2 /* C++ token ? */
|
|
|
|
#define TOK_TWOSHARPS 0xa3 /* ## preprocessing token */
|
|
|
|
#define TOK_PLCHLDR 0xa4 /* placeholder token as defined in C99 */
|
|
|
|
#define TOK_NOSUBST 0xa5 /* means following token has already been pp'd */
|
2020-10-19 05:54:01 +08:00
|
|
|
#define TOK_PPJOIN 0xa6 /* A '##' in the right position to mean pasting */
|
2020-06-18 00:08:09 +08:00
|
|
|
|
|
|
|
/* assignment operators */
|
|
|
|
#define TOK_A_ADD 0xb0
|
|
|
|
#define TOK_A_SUB 0xb1
|
|
|
|
#define TOK_A_MUL 0xb2
|
|
|
|
#define TOK_A_DIV 0xb3
|
|
|
|
#define TOK_A_MOD 0xb4
|
|
|
|
#define TOK_A_AND 0xb5
|
|
|
|
#define TOK_A_OR 0xb6
|
|
|
|
#define TOK_A_XOR 0xb7
|
|
|
|
#define TOK_A_SHL 0xb8
|
|
|
|
#define TOK_A_SAR 0xb9
|
|
|
|
|
|
|
|
#define TOK_ASSIGN(t) (t >= TOK_A_ADD && t <= TOK_A_SAR)
|
|
|
|
#define TOK_ASSIGN_OP(t) ("+-*/%&|^<>"[t - TOK_A_ADD])
|
2014-03-29 23:40:54 +08:00
|
|
|
|
|
|
|
/* tokens that carry values (in additional token string space / tokc) --> */
|
2020-06-18 00:08:09 +08:00
|
|
|
#define TOK_CCHAR 0xc0 /* char constant in tokc */
|
|
|
|
#define TOK_LCHAR 0xc1
|
|
|
|
#define TOK_CINT 0xc2 /* number in tokc */
|
|
|
|
#define TOK_CUINT 0xc3 /* unsigned int constant */
|
|
|
|
#define TOK_CLLONG 0xc4 /* long long constant */
|
|
|
|
#define TOK_CULLONG 0xc5 /* unsigned long long constant */
|
|
|
|
#define TOK_CLONG 0xc6 /* long constant */
|
|
|
|
#define TOK_CULONG 0xc7 /* unsigned long constant */
|
|
|
|
#define TOK_STR 0xc8 /* pointer to string in tokc */
|
|
|
|
#define TOK_LSTR 0xc9
|
|
|
|
#define TOK_CFLOAT 0xca /* float constant */
|
|
|
|
#define TOK_CDOUBLE 0xcb /* double constant */
|
|
|
|
#define TOK_CLDOUBLE 0xcc /* long double constant */
|
|
|
|
#define TOK_PPNUM 0xcd /* preprocessor number */
|
|
|
|
#define TOK_PPSTR 0xce /* preprocessor string */
|
|
|
|
#define TOK_LINENUM 0xcf /* line number info */
|
|
|
|
|
|
|
|
#define TOK_HAS_VALUE(t) (t >= TOK_CCHAR && t <= TOK_LINENUM)
|
2009-05-06 02:17:26 +08:00
|
|
|
|
|
|
|
#define TOK_EOF (-1) /* end of file */
|
|
|
|
#define TOK_LINEFEED 10 /* line feed */
|
|
|
|
|
2017-05-08 12:38:09 +08:00
|
|
|
/* all identifiers and strings have token above that */
|
2009-05-06 02:17:26 +08:00
|
|
|
#define TOK_IDENT 256
|
|
|
|
|
|
|
|
enum tcc_token {
|
2015-11-20 02:26:47 +08:00
|
|
|
TOK_LAST = TOK_IDENT - 1
|
|
|
|
#define DEF(id, str) ,id
|
2009-05-06 02:17:26 +08:00
|
|
|
#include "tcctok.h"
|
|
|
|
#undef DEF
|
|
|
|
};
|
|
|
|
|
2016-10-10 02:33:14 +08:00
|
|
|
/* keywords: tok >= TOK_IDENT && tok < TOK_UIDENT */
|
2009-05-06 02:17:26 +08:00
|
|
|
#define TOK_UIDENT TOK_DEFINE
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
/* ------------ libtcc.c ------------ */
|
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_DATA struct TCCState *tcc_state;
|
2009-12-20 08:53:49 +08:00
|
|
|
|
|
|
|
/* public functions currently used by the tcc main function */
|
2019-12-02 03:45:42 +08:00
|
|
|
ST_FUNC char *pstrcpy(char *buf, size_t buf_size, const char *s);
|
|
|
|
ST_FUNC char *pstrcat(char *buf, size_t buf_size, const char *s);
|
2017-02-09 02:49:28 +08:00
|
|
|
ST_FUNC char *pstrncpy(char *out, const char *in, size_t num);
|
2009-12-20 08:53:49 +08:00
|
|
|
PUB_FUNC char *tcc_basename(const char *name);
|
|
|
|
PUB_FUNC char *tcc_fileextension (const char *name);
|
2015-05-12 16:56:39 +08:00
|
|
|
|
|
|
|
#ifndef MEM_DEBUG
|
2021-10-22 13:39:54 +08:00
|
|
|
PUB_FUNC void tcc_free(void *ptr);
|
|
|
|
PUB_FUNC void *tcc_malloc(unsigned long size);
|
|
|
|
PUB_FUNC void *tcc_mallocz(unsigned long size);
|
|
|
|
PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size);
|
|
|
|
PUB_FUNC char *tcc_strdup(const char *str);
|
2015-05-12 16:56:39 +08:00
|
|
|
#else
|
2021-10-22 13:39:54 +08:00
|
|
|
#define tcc_free(ptr) tcc_free_debug(ptr)
|
|
|
|
#define tcc_malloc(size) tcc_malloc_debug(size, __FILE__, __LINE__)
|
|
|
|
#define tcc_mallocz(size) tcc_mallocz_debug(size, __FILE__, __LINE__)
|
|
|
|
#define tcc_realloc(ptr,size) tcc_realloc_debug(ptr, size, __FILE__, __LINE__)
|
|
|
|
#define tcc_strdup(str) tcc_strdup_debug(str, __FILE__, __LINE__)
|
|
|
|
PUB_FUNC void tcc_free_debug(void *ptr);
|
|
|
|
PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line);
|
|
|
|
PUB_FUNC void *tcc_mallocz_debug(unsigned long size, const char *file, int line);
|
|
|
|
PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file, int line);
|
|
|
|
PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define free(p) use_tcc_free(p)
|
|
|
|
#define malloc(s) use_tcc_malloc(s)
|
|
|
|
#define realloc(p, s) use_tcc_realloc(p, s)
|
2020-10-24 03:38:53 +08:00
|
|
|
#undef strdup
|
2021-10-22 13:39:54 +08:00
|
|
|
#define strdup(s) use_tcc_strdup(s)
|
|
|
|
PUB_FUNC void _tcc_error_noabort(const char *fmt, ...) PRINTF_LIKE(1,2);
|
|
|
|
PUB_FUNC NORETURN void _tcc_error(const char *fmt, ...) PRINTF_LIKE(1,2);
|
|
|
|
PUB_FUNC void _tcc_warning(const char *fmt, ...) PRINTF_LIKE(1,2);
|
|
|
|
#define tcc_internal_error(msg) tcc_error("internal compiler error\n"\
|
2020-10-24 03:38:53 +08:00
|
|
|
"%s:%d: in %s(): " msg, __FILE__,__LINE__,__FUNCTION__)
|
2009-12-20 08:53:49 +08:00
|
|
|
|
|
|
|
/* other utilities */
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data);
|
|
|
|
ST_FUNC void dynarray_reset(void *pp, int *n);
|
|
|
|
ST_INLN void cstr_ccat(CString *cstr, int ch);
|
|
|
|
ST_FUNC void cstr_cat(CString *cstr, const char *str, int len);
|
|
|
|
ST_FUNC void cstr_wccat(CString *cstr, int ch);
|
|
|
|
ST_FUNC void cstr_new(CString *cstr);
|
|
|
|
ST_FUNC void cstr_free(CString *cstr);
|
|
|
|
ST_FUNC int cstr_printf(CString *cs, const char *fmt, ...) PRINTF_LIKE(2,3);
|
|
|
|
ST_FUNC int cstr_vprintf(CString *cstr, const char *fmt, va_list ap);
|
2013-02-13 02:13:28 +08:00
|
|
|
ST_FUNC void cstr_reset(CString *cstr);
|
2009-12-20 08:53:49 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen);
|
|
|
|
ST_FUNC int tcc_open(TCCState *s1, const char *filename);
|
|
|
|
ST_FUNC void tcc_close(void);
|
2010-11-25 20:29:15 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags);
|
2016-10-02 02:46:16 +08:00
|
|
|
/* flags: */
|
|
|
|
#define AFF_PRINT_ERROR 0x10 /* print error if file not found */
|
|
|
|
#define AFF_REFERENCED_DLL 0x20 /* load a referenced dll from another dll */
|
2017-07-21 04:21:27 +08:00
|
|
|
#define AFF_TYPE_BIN 0x40 /* file to add is binary */
|
2018-06-01 05:51:59 +08:00
|
|
|
#define AFF_WHOLE_ARCHIVE 0x80 /* load all objects from archive */
|
2017-07-21 04:21:27 +08:00
|
|
|
/* s->filetype: */
|
2016-10-02 02:54:45 +08:00
|
|
|
#define AFF_TYPE_NONE 0
|
|
|
|
#define AFF_TYPE_C 1
|
|
|
|
#define AFF_TYPE_ASM 2
|
2018-06-01 05:51:59 +08:00
|
|
|
#define AFF_TYPE_ASMPP 4
|
|
|
|
#define AFF_TYPE_LIB 8
|
|
|
|
#define AFF_TYPE_MASK (15 | AFF_TYPE_BIN)
|
2016-10-02 02:54:45 +08:00
|
|
|
/* values from tcc_object_type(...) */
|
|
|
|
#define AFF_BINTYPE_REL 1
|
|
|
|
#define AFF_BINTYPE_DYN 2
|
|
|
|
#define AFF_BINTYPE_AR 3
|
|
|
|
#define AFF_BINTYPE_C67 4
|
|
|
|
|
2020-06-27 23:15:06 +08:00
|
|
|
#ifndef ELF_OBJ_ONLY
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);
|
2018-06-08 21:31:40 +08:00
|
|
|
#endif
|
2020-06-27 23:15:06 +08:00
|
|
|
#ifndef TCC_TARGET_MACHO
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
|
2020-06-27 23:15:06 +08:00
|
|
|
#endif
|
2019-12-10 15:07:25 +08:00
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void tcc_add_bcheck(TCCState *s1);
|
2019-12-10 15:07:25 +08:00
|
|
|
#endif
|
2020-01-18 05:58:39 +08:00
|
|
|
#ifdef CONFIG_TCC_BACKTRACE
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void tcc_add_btstub(TCCState *s1);
|
2020-01-18 05:58:39 +08:00
|
|
|
#endif
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void tcc_add_pragma_libs(TCCState *s1);
|
|
|
|
PUB_FUNC int tcc_add_library_err(TCCState *s, const char *f);
|
|
|
|
PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time);
|
|
|
|
PUB_FUNC int tcc_parse_args(TCCState *s, int *argc, char ***argv, int optind);
|
2016-10-15 21:55:31 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
ST_FUNC char *normalize_slashes(char *path);
|
|
|
|
#endif
|
2022-05-29 02:47:48 +08:00
|
|
|
ST_FUNC DLLReference *tcc_add_dllref(TCCState *s1, const char *dllname, int level);
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC char *tcc_load_text(int fd);
|
2013-02-19 19:47:36 +08:00
|
|
|
|
2017-02-18 16:55:34 +08:00
|
|
|
/* tcc_parse_args return codes: */
|
|
|
|
#define OPT_HELP 1
|
2017-02-18 16:55:46 +08:00
|
|
|
#define OPT_HELP2 2
|
2017-02-18 16:55:34 +08:00
|
|
|
#define OPT_V 3
|
|
|
|
#define OPT_PRINT_DIRS 4
|
|
|
|
#define OPT_AR 5
|
|
|
|
#define OPT_IMPDEF 6
|
|
|
|
#define OPT_M32 32
|
|
|
|
#define OPT_M64 64
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
/* ------------ tccpp.c ------------ */
|
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_DATA struct BufferedFile *file;
|
|
|
|
ST_DATA int ch, tok;
|
|
|
|
ST_DATA CValue tokc;
|
|
|
|
ST_DATA const int *macro_ptr;
|
|
|
|
ST_DATA int parse_flags;
|
|
|
|
ST_DATA int tok_flags;
|
|
|
|
ST_DATA CString tokcstr; /* current parsed string, if any */
|
|
|
|
|
|
|
|
/* display benchmark infos */
|
|
|
|
ST_DATA int tok_ident;
|
|
|
|
ST_DATA TokenSym **table_ident;
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
#define TOK_FLAG_BOL 0x0001 /* beginning of line before */
|
|
|
|
#define TOK_FLAG_BOF 0x0002 /* beginning of file before */
|
|
|
|
#define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
|
|
|
|
#define TOK_FLAG_EOF 0x0008 /* end of file */
|
|
|
|
|
|
|
|
#define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */
|
|
|
|
#define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */
|
|
|
|
#define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a
|
|
|
|
token. line feed is also
|
|
|
|
returned at eof */
|
2015-04-27 21:36:58 +08:00
|
|
|
#define PARSE_FLAG_ASM_FILE 0x0008 /* we processing an asm file: '#' can be used for line comment, etc. */
|
2009-12-20 08:53:49 +08:00
|
|
|
#define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
|
2015-05-02 20:58:37 +08:00
|
|
|
#define PARSE_FLAG_ACCEPT_STRAYS 0x0020 /* next() returns '\\' token */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 20:29:39 +08:00
|
|
|
#define PARSE_FLAG_TOK_STR 0x0040 /* return parsed strings instead of TOK_PPSTR */
|
2009-12-20 08:53:49 +08:00
|
|
|
|
2016-08-25 22:40:50 +08:00
|
|
|
/* isidnum_table flags: */
|
|
|
|
#define IS_SPC 1
|
|
|
|
#define IS_ID 2
|
|
|
|
#define IS_NUM 4
|
|
|
|
|
2021-08-02 02:04:46 +08:00
|
|
|
enum line_macro_output_format {
|
|
|
|
LINE_MACRO_OUTPUT_FORMAT_GCC,
|
|
|
|
LINE_MACRO_OUTPUT_FORMAT_NONE,
|
|
|
|
LINE_MACRO_OUTPUT_FORMAT_STD,
|
|
|
|
LINE_MACRO_OUTPUT_FORMAT_P10 = 11
|
|
|
|
};
|
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC TokenSym *tok_alloc(const char *str, int len);
|
|
|
|
ST_FUNC int tok_alloc_const(const char *str);
|
|
|
|
ST_FUNC const char *get_tok_str(int v, CValue *cv);
|
|
|
|
ST_FUNC void begin_macro(TokenString *str, int alloc);
|
|
|
|
ST_FUNC void end_macro(void);
|
|
|
|
ST_FUNC int set_idnum(int c, int val);
|
2009-12-20 08:53:49 +08:00
|
|
|
ST_INLN void tok_str_new(TokenString *s);
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC TokenString *tok_str_alloc(void);
|
|
|
|
ST_FUNC void tok_str_free(TokenString *s);
|
|
|
|
ST_FUNC void tok_str_free_str(int *str);
|
|
|
|
ST_FUNC void tok_str_add(TokenString *s, int t);
|
|
|
|
ST_FUNC void tok_str_add_tok(TokenString *s);
|
|
|
|
ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg);
|
|
|
|
ST_FUNC void define_undef(Sym *s);
|
|
|
|
ST_INLN Sym *define_find(int v);
|
|
|
|
ST_FUNC void free_defines(Sym *b);
|
|
|
|
ST_FUNC Sym *label_find(int v);
|
|
|
|
ST_FUNC Sym *label_push(Sym **ptop, int v, int flags);
|
|
|
|
ST_FUNC void label_pop(Sym **ptop, Sym *slast, int keep);
|
|
|
|
ST_FUNC void parse_define(void);
|
|
|
|
ST_FUNC void preprocess(int is_bof);
|
|
|
|
ST_FUNC void next(void);
|
|
|
|
ST_INLN void unget_tok(int last_tok);
|
|
|
|
ST_FUNC void preprocess_start(TCCState *s1, int filetype);
|
|
|
|
ST_FUNC void preprocess_end(TCCState *s1);
|
|
|
|
ST_FUNC void tccpp_new(TCCState *s);
|
|
|
|
ST_FUNC void tccpp_delete(TCCState *s);
|
|
|
|
ST_FUNC int tcc_preprocess(TCCState *s1);
|
|
|
|
ST_FUNC void skip(int c);
|
|
|
|
ST_FUNC NORETURN void expect(const char *msg);
|
2009-12-20 08:53:49 +08:00
|
|
|
|
2017-05-08 12:38:09 +08:00
|
|
|
/* space excluding newline */
|
2016-10-10 02:33:14 +08:00
|
|
|
static inline int is_space(int ch) {
|
|
|
|
return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
|
|
|
|
}
|
|
|
|
static inline int isid(int c) {
|
|
|
|
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
|
|
|
|
}
|
|
|
|
static inline int isnum(int c) {
|
|
|
|
return c >= '0' && c <= '9';
|
|
|
|
}
|
|
|
|
static inline int isoct(int c) {
|
|
|
|
return c >= '0' && c <= '7';
|
|
|
|
}
|
|
|
|
static inline int toup(int c) {
|
|
|
|
return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c;
|
|
|
|
}
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
/* ------------ tccgen.c ------------ */
|
|
|
|
|
|
|
|
#define SYM_POOL_NB (8192 / sizeof(Sym))
|
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_DATA Sym *global_stack;
|
|
|
|
ST_DATA Sym *local_stack;
|
|
|
|
ST_DATA Sym *local_label_stack;
|
|
|
|
ST_DATA Sym *global_label_stack;
|
|
|
|
ST_DATA Sym *define_stack;
|
|
|
|
ST_DATA CType int_type, func_old_type, char_pointer_type;
|
|
|
|
ST_DATA SValue *vtop;
|
|
|
|
ST_DATA int rsym, anon_sym, ind, loc;
|
|
|
|
ST_DATA char debug_modes;
|
|
|
|
|
|
|
|
ST_DATA int const_wanted; /* true if constant wanted */
|
|
|
|
ST_DATA int nocode_wanted; /* true if no code generation wanted for an expression */
|
|
|
|
ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */
|
|
|
|
ST_DATA CType func_vt; /* current function return type (used by return instruction) */
|
|
|
|
ST_DATA int func_var; /* true if current function is variadic */
|
|
|
|
ST_DATA int func_vc;
|
2022-05-09 23:02:09 +08:00
|
|
|
ST_DATA int func_ind;
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_DATA const char *funcname;
|
|
|
|
|
|
|
|
ST_FUNC void tccgen_init(TCCState *s1);
|
|
|
|
ST_FUNC int tccgen_compile(TCCState *s1);
|
|
|
|
ST_FUNC void tccgen_finish(TCCState *s1);
|
|
|
|
ST_FUNC void check_vstack(void);
|
2016-10-18 05:24:01 +08:00
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
ST_INLN int is_float(int t);
|
2011-08-01 07:10:36 +08:00
|
|
|
ST_FUNC int ieee_finite(double d);
|
2020-05-15 09:46:55 +08:00
|
|
|
ST_FUNC int exact_log2p1(int i);
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void test_lvalue(void);
|
2020-11-25 18:23:01 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC ElfSym *elfsym(Sym *);
|
|
|
|
ST_FUNC void update_storage(Sym *sym);
|
|
|
|
ST_FUNC void put_extern_sym2(Sym *sym, int sh_num, addr_t value, unsigned long size, int can_add_underscore);
|
|
|
|
ST_FUNC void put_extern_sym(Sym *sym, Section *section, addr_t value, unsigned long size);
|
2020-11-25 18:23:01 +08:00
|
|
|
#if PTR_SIZE == 4
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type);
|
2020-11-25 18:23:01 +08:00
|
|
|
#endif
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void greloca(Section *s, Sym *sym, unsigned long offset, int type, addr_t addend);
|
2020-11-25 18:23:01 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_INLN void sym_free(Sym *sym);
|
|
|
|
ST_FUNC Sym *sym_push(int v, CType *type, int r, int c);
|
|
|
|
ST_FUNC void sym_pop(Sym **ptop, Sym *b, int keep);
|
|
|
|
ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, int c);
|
2020-11-25 18:23:01 +08:00
|
|
|
ST_FUNC Sym *sym_find2(Sym *s, int v);
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_INLN Sym *sym_find(int v);
|
|
|
|
ST_INLN Sym *struct_find(int v);
|
|
|
|
|
|
|
|
ST_FUNC Sym *global_identifier_push(int v, int t, int c);
|
|
|
|
ST_FUNC Sym *external_global_sym(int v, CType *type);
|
|
|
|
ST_FUNC Sym *external_helper_sym(int v);
|
|
|
|
ST_FUNC void vpush_helper_func(int v);
|
|
|
|
ST_FUNC void vset(CType *type, int r, int v);
|
|
|
|
ST_FUNC void vset_VT_CMP(int op);
|
|
|
|
ST_FUNC void vpushi(int v);
|
|
|
|
ST_FUNC void vpushv(SValue *v);
|
|
|
|
ST_FUNC void vpushsym(CType *type, Sym *sym);
|
|
|
|
ST_FUNC void vswap(void);
|
|
|
|
ST_FUNC void vrote(SValue *e, int n);
|
|
|
|
ST_FUNC void vrott(int n);
|
|
|
|
ST_FUNC void vrotb(int n);
|
|
|
|
ST_FUNC void vpop(void);
|
2019-01-09 02:06:26 +08:00
|
|
|
#if PTR_SIZE == 4
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void lexpand(void);
|
2019-01-09 02:06:26 +08:00
|
|
|
#endif
|
2009-12-21 03:33:41 +08:00
|
|
|
#ifdef TCC_TARGET_ARM
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC int get_reg_ex(int rc, int rc2);
|
|
|
|
#endif
|
|
|
|
ST_FUNC void save_reg(int r);
|
|
|
|
ST_FUNC void save_reg_upstack(int r, int n);
|
|
|
|
ST_FUNC int get_reg(int rc);
|
|
|
|
ST_FUNC void save_regs(int n);
|
|
|
|
ST_FUNC void gaddrof(void);
|
|
|
|
ST_FUNC int gv(int rc);
|
|
|
|
ST_FUNC void gv2(int rc1, int rc2);
|
|
|
|
ST_FUNC void gen_op(int op);
|
2009-12-20 08:53:49 +08:00
|
|
|
ST_FUNC int type_size(CType *type, int *a);
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void mk_pointer(CType *type);
|
|
|
|
ST_FUNC void vstore(void);
|
|
|
|
ST_FUNC void inc(int post, int c);
|
|
|
|
ST_FUNC void parse_mult_str (CString *astr, const char *msg);
|
|
|
|
ST_FUNC void parse_asm_str(CString *astr);
|
|
|
|
ST_FUNC void indir(void);
|
|
|
|
ST_FUNC void unary(void);
|
|
|
|
ST_FUNC void gexpr(void);
|
|
|
|
ST_FUNC int expr_const(void);
|
2009-12-21 03:33:41 +08:00
|
|
|
#if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size);
|
2009-12-20 08:53:49 +08:00
|
|
|
#endif
|
2013-04-28 03:39:34 +08:00
|
|
|
#if defined TCC_TARGET_X86_64 && !defined TCC_TARGET_PE
|
2013-04-19 18:08:12 +08:00
|
|
|
ST_FUNC int classify_x86_64_va_arg(CType *ty);
|
|
|
|
#endif
|
bcheck cleanup
- revert Makefiles to state before last bcheck additions
Instead, just load bcheck.o explicitly if that is
what is wanted.
- move tcc_add_bcheck() to the <target>-link.c files and
remove revently added arguments. This function is to
support tccelf.c with linking, not for tccgen.c to
support compilation.
- remove -ba option: It said:
"-ba Enable better address checking with bounds checker"
Okay, if it is better then to have it is not an option.
- remove va_copy. It is C99 and we try to stay C89 in tinycc
when possible. For example, MS compilers do not have va_copy.
- win64: revert any 'fixes' to alloca
It was correct as it was before, except for bound_checking
where it was not implemented. This should now work too.
- remove parasitic filename:linenum features
Such feature is already present with rt_printline in
tccrun.c. If it doesn't work it can be fixed.
- revert changes to gen_bounded_ptr_add()
gen_bounded_ptr_add() was working as it should before
(mostly). For the sake of simplicity I switched it to
CDECL. Anyway, FASTCALL means SLOWCALL with tinycc.
In exchange you get one addition which is required for
bounds_cnecking function arguments. The important thing
is to check them *BEFORE* they are loaded into registers.
New function gbound_args() does that.
In any case, code instrumentation with the bounds-check
functions as such now seems to work flawlessly again,
which means when they are inserted as NOPs, any code that
tcc can compile, seems to behave just the same as without
them.
What these functions then do when fully enabled, is a
differnt story. I did not touch this.
2019-12-12 22:45:45 +08:00
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void gbound_args(int nb_args);
|
2021-10-22 13:39:26 +08:00
|
|
|
ST_DATA int func_bound_add_epilog;
|
bcheck cleanup
- revert Makefiles to state before last bcheck additions
Instead, just load bcheck.o explicitly if that is
what is wanted.
- move tcc_add_bcheck() to the <target>-link.c files and
remove revently added arguments. This function is to
support tccelf.c with linking, not for tccgen.c to
support compilation.
- remove -ba option: It said:
"-ba Enable better address checking with bounds checker"
Okay, if it is better then to have it is not an option.
- remove va_copy. It is C99 and we try to stay C89 in tinycc
when possible. For example, MS compilers do not have va_copy.
- win64: revert any 'fixes' to alloca
It was correct as it was before, except for bound_checking
where it was not implemented. This should now work too.
- remove parasitic filename:linenum features
Such feature is already present with rt_printline in
tccrun.c. If it doesn't work it can be fixed.
- revert changes to gen_bounded_ptr_add()
gen_bounded_ptr_add() was working as it should before
(mostly). For the sake of simplicity I switched it to
CDECL. Anyway, FASTCALL means SLOWCALL with tinycc.
In exchange you get one addition which is required for
bounds_cnecking function arguments. The important thing
is to check them *BEFORE* they are loaded into registers.
New function gbound_args() does that.
In any case, code instrumentation with the bounds-check
functions as such now seems to work flawlessly again,
which means when they are inserted as NOPs, any code that
tcc can compile, seems to behave just the same as without
them.
What these functions then do when fully enabled, is a
differnt story. I did not touch this.
2019-12-12 22:45:45 +08:00
|
|
|
#endif
|
2009-12-20 08:53:49 +08:00
|
|
|
|
|
|
|
/* ------------ tccelf.c ------------ */
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
#define TCC_OUTPUT_FORMAT_ELF 0 /* default output format: ELF */
|
|
|
|
#define TCC_OUTPUT_FORMAT_BINARY 1 /* binary image output */
|
|
|
|
#define TCC_OUTPUT_FORMAT_COFF 2 /* COFF */
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
#define ARMAG "!<arch>\012" /* For COFF and a.out archives */
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned int n_strx; /* index into string table of name */
|
|
|
|
unsigned char n_type; /* type of symbol */
|
|
|
|
unsigned char n_other; /* misc info (usually empty) */
|
|
|
|
unsigned short n_desc; /* description field */
|
|
|
|
unsigned int n_value; /* value of symbol */
|
|
|
|
} Stab_Sym;
|
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void tccelf_new(TCCState *s);
|
|
|
|
ST_FUNC void tccelf_delete(TCCState *s);
|
|
|
|
ST_FUNC void tccelf_begin_file(TCCState *s1);
|
|
|
|
ST_FUNC void tccelf_end_file(TCCState *s1);
|
2019-12-11 07:37:18 +08:00
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void tccelf_bounds_new(TCCState *s);
|
|
|
|
#endif
|
|
|
|
ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
|
|
|
|
ST_FUNC void section_realloc(Section *sec, unsigned long new_size);
|
|
|
|
ST_FUNC size_t section_add(Section *sec, addr_t size, int align);
|
|
|
|
ST_FUNC void *section_ptr_add(Section *sec, addr_t size);
|
|
|
|
ST_FUNC Section *find_section(TCCState *s1, const char *name);
|
|
|
|
ST_FUNC Section *new_symtab(TCCState *s1, const char *symtab_name, int sh_type, int sh_flags, const char *strtab_name, const char *hash_name, int hash_sh_flags);
|
|
|
|
|
|
|
|
ST_FUNC int put_elf_str(Section *s, const char *sym);
|
|
|
|
ST_FUNC int put_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
|
|
|
|
ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
|
|
|
|
ST_FUNC int find_elf_sym(Section *s, const char *name);
|
2009-12-20 08:53:49 +08:00
|
|
|
ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol);
|
2015-03-24 00:24:55 +08:00
|
|
|
ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset, int type, int symbol, addr_t addend);
|
2009-12-20 08:53:49 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void resolve_common_syms(TCCState *s1);
|
|
|
|
ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve);
|
|
|
|
ST_FUNC void relocate_sections(TCCState *s1);
|
2009-12-20 08:53:49 +08:00
|
|
|
|
2020-05-25 23:27:01 +08:00
|
|
|
ST_FUNC ssize_t full_read(int fd, void *buf, size_t count);
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void *load_data(int fd, unsigned long file_offset, unsigned long size);
|
2016-10-02 02:54:45 +08:00
|
|
|
ST_FUNC int tcc_object_type(int fd, ElfW(Ehdr) *h);
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset);
|
|
|
|
ST_FUNC int tcc_load_archive(TCCState *s1, int fd, int alacarte);
|
|
|
|
ST_FUNC void add_array(TCCState *s1, const char *sec, int c);
|
2009-12-20 08:53:49 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc);
|
|
|
|
ST_FUNC addr_t get_sym_addr(TCCState *s, const char *name, int err, int forc);
|
|
|
|
ST_FUNC void list_elf_symbols(TCCState *s, void *ctx,
|
2019-09-16 15:24:16 +08:00
|
|
|
void (*symbol_cb)(void *ctx, const char *name, const void *val));
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC int set_global_sym(TCCState *s1, const char *name, Section *sec, addr_t offs);
|
2020-01-18 05:58:39 +08:00
|
|
|
|
2020-05-17 10:18:26 +08:00
|
|
|
/* Browse each elem of type <type> in section <sec> starting at elem <startoff>
|
|
|
|
using variable <elem> */
|
|
|
|
#define for_each_elem(sec, startoff, elem, type) \
|
|
|
|
for (elem = (type *) sec->data + startoff; \
|
|
|
|
elem < (type *) (sec->data + sec->data_offset); elem++)
|
|
|
|
|
2020-06-27 23:15:06 +08:00
|
|
|
#ifndef ELF_OBJ_ONLY
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level);
|
|
|
|
ST_FUNC int tcc_load_ldscript(TCCState *s1, int fd);
|
2020-06-27 23:15:06 +08:00
|
|
|
#endif
|
|
|
|
#ifndef TCC_TARGET_PE
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void tcc_add_runtime(TCCState *s1);
|
2009-12-20 08:53:49 +08:00
|
|
|
#endif
|
|
|
|
|
2016-12-11 01:22:08 +08:00
|
|
|
/* ------------ xxx-link.c ------------ */
|
|
|
|
|
2022-05-08 05:16:13 +08:00
|
|
|
#if !defined ELF_OBJ_ONLY || defined TCC_TARGET_MACHO
|
|
|
|
ST_FUNC int code_reloc (int reloc_type);
|
|
|
|
ST_FUNC int gotplt_entry_type (int reloc_type);
|
2017-09-25 09:03:26 +08:00
|
|
|
/* Whether to generate a GOT/PLT entry and when. NO_GOTPLT_ENTRY is first so
|
2016-12-11 01:22:08 +08:00
|
|
|
that unknown relocation don't create a GOT or PLT entry */
|
|
|
|
enum gotplt_entry {
|
|
|
|
NO_GOTPLT_ENTRY, /* never generate (eg. GLOB_DAT & JMP_SLOT relocs) */
|
|
|
|
BUILD_GOT_ONLY, /* only build GOT (eg. TPOFF relocs) */
|
|
|
|
AUTO_GOTPLT_ENTRY, /* generate if sym is UNDEF */
|
|
|
|
ALWAYS_GOTPLT_ENTRY /* always generate (eg. PLTOFF relocs) */
|
|
|
|
};
|
2022-05-08 05:16:13 +08:00
|
|
|
#define NEED_RELOC_TYPE
|
2016-12-11 01:22:08 +08:00
|
|
|
|
2022-05-08 05:16:13 +08:00
|
|
|
#if !defined TCC_TARGET_MACHO || defined TCC_IS_NATIVE
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr);
|
|
|
|
ST_FUNC void relocate_plt(TCCState *s1);
|
2022-05-08 05:16:13 +08:00
|
|
|
ST_FUNC void build_got_entries(TCCState *s1); /* in tccelf.c */
|
|
|
|
#define NEED_BUILD_GOT
|
|
|
|
|
2019-12-10 03:32:13 +08:00
|
|
|
#endif
|
2020-06-27 23:15:06 +08:00
|
|
|
#endif
|
2022-05-08 05:16:13 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
|
2016-12-11 01:22:08 +08:00
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
/* ------------ xxx-gen.c ------------ */
|
2021-02-01 22:10:58 +08:00
|
|
|
ST_DATA const char * const target_machine_defs;
|
2013-02-13 02:13:28 +08:00
|
|
|
ST_DATA const int reg_classes[NB_REGS];
|
2013-02-09 02:07:11 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void gsym_addr(int t, int a);
|
|
|
|
ST_FUNC void gsym(int t);
|
|
|
|
ST_FUNC void load(int r, SValue *sv);
|
|
|
|
ST_FUNC void store(int r, SValue *v);
|
2015-07-30 04:57:41 +08:00
|
|
|
ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *align, int *regsize);
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void gfunc_call(int nb_args);
|
|
|
|
ST_FUNC void gfunc_prolog(Sym *func_sym);
|
|
|
|
ST_FUNC void gfunc_epilog(void);
|
|
|
|
ST_FUNC void gen_fill_nops(int);
|
|
|
|
ST_FUNC int gjmp(int t);
|
|
|
|
ST_FUNC void gjmp_addr(int a);
|
|
|
|
ST_FUNC int gjmp_cond(int op, int t);
|
|
|
|
ST_FUNC int gjmp_append(int n, int t);
|
|
|
|
ST_FUNC void gen_opi(int op);
|
|
|
|
ST_FUNC void gen_opf(int op);
|
|
|
|
ST_FUNC void gen_cvt_ftoi(int t);
|
|
|
|
ST_FUNC void gen_cvt_itof(int t);
|
|
|
|
ST_FUNC void gen_cvt_ftof(int t);
|
|
|
|
ST_FUNC void ggoto(void);
|
2009-12-20 08:53:49 +08:00
|
|
|
#ifndef TCC_TARGET_C67
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void o(unsigned int c);
|
2009-12-20 08:53:49 +08:00
|
|
|
#endif
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void gen_vla_sp_save(int addr);
|
|
|
|
ST_FUNC void gen_vla_sp_restore(int addr);
|
|
|
|
ST_FUNC void gen_vla_alloc(CType *type, int align);
|
2009-12-20 08:53:49 +08:00
|
|
|
|
2016-10-10 02:33:14 +08:00
|
|
|
static inline uint16_t read16le(unsigned char *p) {
|
2016-10-02 02:26:50 +08:00
|
|
|
return p[0] | (uint16_t)p[1] << 8;
|
|
|
|
}
|
2016-10-10 02:33:14 +08:00
|
|
|
static inline void write16le(unsigned char *p, uint16_t x) {
|
2017-09-26 13:16:23 +08:00
|
|
|
p[0] = x & 255; p[1] = x >> 8 & 255;
|
2016-10-02 02:26:50 +08:00
|
|
|
}
|
2016-10-10 02:33:14 +08:00
|
|
|
static inline uint32_t read32le(unsigned char *p) {
|
|
|
|
return read16le(p) | (uint32_t)read16le(p + 2) << 16;
|
2016-10-02 02:26:50 +08:00
|
|
|
}
|
2016-10-10 02:33:14 +08:00
|
|
|
static inline void write32le(unsigned char *p, uint32_t x) {
|
2017-09-26 13:16:23 +08:00
|
|
|
write16le(p, x); write16le(p + 2, x >> 16);
|
2016-10-02 02:26:50 +08:00
|
|
|
}
|
2016-11-20 21:52:56 +08:00
|
|
|
static inline void add32le(unsigned char *p, int32_t x) {
|
|
|
|
write32le(p, read32le(p) + x);
|
|
|
|
}
|
2016-10-10 02:33:14 +08:00
|
|
|
static inline uint64_t read64le(unsigned char *p) {
|
|
|
|
return read32le(p) | (uint64_t)read32le(p + 4) << 32;
|
2016-10-02 02:26:50 +08:00
|
|
|
}
|
2016-10-10 02:33:14 +08:00
|
|
|
static inline void write64le(unsigned char *p, uint64_t x) {
|
2017-09-26 13:16:23 +08:00
|
|
|
write32le(p, x); write32le(p + 4, x >> 32);
|
2016-10-02 02:26:50 +08:00
|
|
|
}
|
2016-11-20 21:52:56 +08:00
|
|
|
static inline void add64le(unsigned char *p, int64_t x) {
|
|
|
|
write64le(p, read64le(p) + x);
|
|
|
|
}
|
2016-10-02 02:26:50 +08:00
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
/* ------------ i386-gen.c ------------ */
|
2020-12-26 23:36:38 +08:00
|
|
|
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void g(int c);
|
|
|
|
ST_FUNC void gen_le16(int c);
|
|
|
|
ST_FUNC void gen_le32(int c);
|
2020-12-26 23:36:38 +08:00
|
|
|
#endif
|
|
|
|
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void gen_addr32(int r, Sym *sym, int c);
|
|
|
|
ST_FUNC void gen_addrpc32(int r, Sym *sym, int c);
|
|
|
|
ST_FUNC void gen_cvt_csti(int t);
|
|
|
|
ST_FUNC void gen_increment_tcov (SValue *sv);
|
2009-12-20 08:53:49 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ------------ x86_64-gen.c ------------ */
|
|
|
|
#ifdef TCC_TARGET_X86_64
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void gen_addr64(int r, Sym *sym, int64_t c);
|
|
|
|
ST_FUNC void gen_opl(int op);
|
2017-12-13 00:57:20 +08:00
|
|
|
#ifdef TCC_TARGET_PE
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void gen_vla_result(int addr);
|
2017-12-13 00:57:20 +08:00
|
|
|
#endif
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void gen_cvt_sxtw(void);
|
|
|
|
ST_FUNC void gen_cvt_csti(int t);
|
2009-12-20 08:53:49 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ------------ arm-gen.c ------------ */
|
|
|
|
#ifdef TCC_TARGET_ARM
|
2015-03-03 22:16:52 +08:00
|
|
|
#if defined(TCC_ARM_EABI) && !defined(CONFIG_TCC_ELFINTERP)
|
2021-10-22 13:39:54 +08:00
|
|
|
PUB_FUNC const char *default_elfinterp(struct TCCState *s);
|
2014-01-07 15:23:54 +08:00
|
|
|
#endif
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void arm_init(struct TCCState *s);
|
|
|
|
ST_FUNC void gen_increment_tcov (SValue *sv);
|
2009-12-20 08:53:49 +08:00
|
|
|
#endif
|
|
|
|
|
2015-02-14 02:58:31 +08:00
|
|
|
/* ------------ arm64-gen.c ------------ */
|
|
|
|
#ifdef TCC_TARGET_ARM64
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void gen_opl(int op);
|
|
|
|
ST_FUNC void gfunc_return(CType *func_type);
|
|
|
|
ST_FUNC void gen_va_start(void);
|
|
|
|
ST_FUNC void gen_va_arg(CType *t);
|
|
|
|
ST_FUNC void gen_clear_cache(void);
|
|
|
|
ST_FUNC void gen_cvt_sxtw(void);
|
|
|
|
ST_FUNC void gen_cvt_csti(int t);
|
|
|
|
ST_FUNC void gen_increment_tcov (SValue *sv);
|
2015-02-14 02:58:31 +08:00
|
|
|
#endif
|
|
|
|
|
2019-06-22 12:13:10 +08:00
|
|
|
/* ------------ riscv64-gen.c ------------ */
|
|
|
|
#ifdef TCC_TARGET_RISCV64
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void gen_opl(int op);
|
|
|
|
//ST_FUNC void gfunc_return(CType *func_type);
|
|
|
|
ST_FUNC void gen_va_start(void);
|
|
|
|
ST_FUNC void arch_transfer_ret_regs(int);
|
|
|
|
ST_FUNC void gen_cvt_sxtw(void);
|
|
|
|
ST_FUNC void gen_increment_tcov (SValue *sv);
|
2019-06-22 12:13:10 +08:00
|
|
|
#endif
|
2019-12-17 01:51:28 +08:00
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
/* ------------ c67-gen.c ------------ */
|
|
|
|
#ifdef TCC_TARGET_C67
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ------------ tcccoff.c ------------ */
|
|
|
|
#ifdef TCC_TARGET_COFF
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f);
|
|
|
|
ST_FUNC int tcc_load_coff(TCCState * s1, int fd);
|
2009-12-20 08:53:49 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ------------ tccasm.c ------------ */
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void asm_instr(void);
|
|
|
|
ST_FUNC void asm_global_instr(void);
|
|
|
|
ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess);
|
2009-12-20 08:53:49 +08:00
|
|
|
#ifdef CONFIG_TCC_ASM
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp);
|
|
|
|
ST_FUNC Sym* get_asm_sym(int name, Sym *csym);
|
|
|
|
ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe);
|
|
|
|
ST_FUNC int asm_int_expr(TCCState *s1);
|
2009-12-20 08:53:49 +08:00
|
|
|
/* ------------ i386-asm.c ------------ */
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void gen_expr32(ExprValue *pe);
|
2016-06-30 01:22:07 +08:00
|
|
|
#ifdef TCC_TARGET_X86_64
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void gen_expr64(ExprValue *pe);
|
2016-06-30 01:22:07 +08:00
|
|
|
#endif
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void asm_opcode(TCCState *s1, int opcode);
|
|
|
|
ST_FUNC int asm_parse_regvar(int t);
|
|
|
|
ST_FUNC void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg);
|
|
|
|
ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier);
|
|
|
|
ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg);
|
|
|
|
ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str);
|
2009-12-20 08:53:49 +08:00
|
|
|
#endif
|
2013-02-13 02:13:28 +08:00
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
/* ------------ tccpe.c -------------- */
|
|
|
|
#ifdef TCC_TARGET_PE
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC int pe_load_file(struct TCCState *s1, int fd, const char *filename);
|
|
|
|
ST_FUNC int pe_output_file(TCCState * s1, const char *filename);
|
|
|
|
ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value);
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-12 00:13:43 +08:00
|
|
|
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2);
|
2016-10-03 18:29:38 +08:00
|
|
|
#endif
|
2009-12-20 05:40:28 +08:00
|
|
|
#ifdef TCC_TARGET_X86_64
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack);
|
2009-12-20 05:40:28 +08:00
|
|
|
#endif
|
2021-10-22 13:39:54 +08:00
|
|
|
PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp);
|
2014-04-17 23:01:28 +08:00
|
|
|
/* symbol properties stored in Elf32_Sym->st_other */
|
|
|
|
# define ST_PE_EXPORT 0x10
|
|
|
|
# define ST_PE_IMPORT 0x20
|
|
|
|
# define ST_PE_STDCALL 0x40
|
2009-12-20 08:53:49 +08:00
|
|
|
#endif
|
2017-11-27 11:03:03 +08:00
|
|
|
#define ST_ASM_SET 0x04
|
|
|
|
|
2020-05-15 09:46:55 +08:00
|
|
|
/* ------------ tccmacho.c ----------------- */
|
|
|
|
#ifdef TCC_TARGET_MACHO
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC int macho_output_file(TCCState * s1, const char *filename);
|
|
|
|
ST_FUNC int macho_load_dll(TCCState *s1, int fd, const char *filename, int lev);
|
|
|
|
ST_FUNC int macho_load_tbd(TCCState *s1, int fd, const char *filename, int lev);
|
2021-07-26 02:39:11 +08:00
|
|
|
#ifdef TCC_IS_NATIVE
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void tcc_add_macos_sdkpath(TCCState* s);
|
2021-07-26 02:39:11 +08:00
|
|
|
ST_FUNC const char* macho_tbd_soname(const char* filename);
|
|
|
|
#endif
|
2020-05-15 09:46:55 +08:00
|
|
|
#endif
|
2009-12-20 08:53:49 +08:00
|
|
|
/* ------------ tccrun.c ----------------- */
|
2013-02-04 23:08:06 +08:00
|
|
|
#ifdef TCC_IS_NATIVE
|
2009-12-21 03:33:41 +08:00
|
|
|
#ifdef CONFIG_TCC_STATIC
|
|
|
|
#define RTLD_LAZY 0x001
|
|
|
|
#define RTLD_NOW 0x002
|
|
|
|
#define RTLD_GLOBAL 0x100
|
|
|
|
#define RTLD_DEFAULT NULL
|
|
|
|
/* dummy function for profiling */
|
|
|
|
ST_FUNC void *dlopen(const char *filename, int flag);
|
|
|
|
ST_FUNC void dlclose(void *p);
|
2013-02-13 02:13:28 +08:00
|
|
|
ST_FUNC const char *dlerror(void);
|
2016-11-13 18:45:55 +08:00
|
|
|
ST_FUNC void *dlsym(void *handle, const char *symbol);
|
2009-12-20 08:53:49 +08:00
|
|
|
#endif
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void tcc_run_free(TCCState *s1);
|
2013-02-04 23:08:06 +08:00
|
|
|
#endif
|
2012-04-19 00:43:29 +08:00
|
|
|
|
2017-02-18 16:55:34 +08:00
|
|
|
/* ------------ tcctools.c ----------------- */
|
|
|
|
#if 0 /* included in tcc.c */
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC int tcc_tool_ar(TCCState *s, int argc, char **argv);
|
2017-02-18 16:55:34 +08:00
|
|
|
#ifdef TCC_TARGET_PE
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC int tcc_tool_impdef(TCCState *s, int argc, char **argv);
|
2017-02-18 16:55:34 +08:00
|
|
|
#endif
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int option);
|
|
|
|
ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename);
|
2017-02-18 16:55:34 +08:00
|
|
|
#endif
|
|
|
|
|
2022-05-09 23:02:09 +08:00
|
|
|
/* ------------ tccdbg.c ------------ */
|
|
|
|
|
|
|
|
ST_FUNC void tcc_debug_new(TCCState *s);
|
|
|
|
|
|
|
|
ST_FUNC void tcc_debug_start(TCCState *s1);
|
|
|
|
ST_FUNC void tcc_debug_end(TCCState *s1);
|
|
|
|
ST_FUNC void tcc_debug_bincl(TCCState *s1);
|
|
|
|
ST_FUNC void tcc_debug_eincl(TCCState *s1);
|
|
|
|
ST_FUNC void tcc_debug_putfile(TCCState *s1, const char *filename);
|
|
|
|
|
|
|
|
ST_FUNC void tcc_debug_line(TCCState *s1);
|
|
|
|
ST_FUNC void tcc_add_debug_info(TCCState *s1, int param, Sym *s, Sym *e);
|
|
|
|
ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym);
|
|
|
|
ST_FUNC void tcc_debug_funcend(TCCState *s1, int size);
|
|
|
|
ST_FUNC void tcc_debug_extern_sym(TCCState *s1, Sym *sym, int sh_num, int sym_bind, int sym_type);
|
|
|
|
ST_FUNC void tcc_debug_typedef(TCCState *s1, Sym *sym);
|
|
|
|
ST_FUNC void tcc_debug_stabn(TCCState *s1, int type, int value);
|
|
|
|
ST_FUNC void tcc_debug_fix_anon(TCCState *s1, CType *t);
|
|
|
|
|
|
|
|
ST_FUNC void tcc_tcov_start(TCCState *s1);
|
|
|
|
ST_FUNC void tcc_tcov_end(TCCState *s1);
|
|
|
|
ST_FUNC void tcc_tcov_check_line(TCCState *s1, int start);
|
|
|
|
ST_FUNC void tcc_tcov_block_end(TCCState *s1, int line);
|
|
|
|
ST_FUNC void tcc_tcov_block_begin(TCCState *s1);
|
|
|
|
ST_FUNC void tcc_tcov_reset_ind(TCCState *s1);
|
|
|
|
|
|
|
|
#define stab_section s1->stab_section
|
|
|
|
#define stabstr_section stab_section->link
|
|
|
|
#define tcov_section s1->tcov_section
|
|
|
|
#define dwarf_info_section s1->dwarf_info_section
|
|
|
|
#define dwarf_abbrev_section s1->dwarf_abbrev_section
|
|
|
|
#define dwarf_line_section s1->dwarf_line_section
|
|
|
|
#define dwarf_aranges_section s1->dwarf_aranges_section
|
|
|
|
#define dwarf_str_section s1->dwarf_str_section
|
|
|
|
#define dwarf_line_str_section s1->dwarf_line_str_section
|
|
|
|
|
|
|
|
#ifndef DWARF_VERSION
|
|
|
|
# define DWARF_VERSION 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined TCC_TARGET_PE
|
|
|
|
# define R_DATA_32DW 'Z' /* fake code to avoid DLL relocs */
|
|
|
|
#elif defined TCC_TARGET_X86_64
|
|
|
|
# define R_DATA_32DW R_X86_64_32
|
|
|
|
#else
|
|
|
|
# define R_DATA_32DW R_DATA_32
|
|
|
|
#endif
|
|
|
|
|
2021-08-02 02:04:46 +08:00
|
|
|
/********************************************************/
|
|
|
|
#if CONFIG_TCC_SEMLOCK
|
|
|
|
#if defined _WIN32
|
|
|
|
typedef struct { int init; CRITICAL_SECTION cr; } TCCSem;
|
|
|
|
#elif defined __APPLE__
|
|
|
|
#include <dispatch/dispatch.h>
|
|
|
|
typedef struct { int init; dispatch_semaphore_t sem; } TCCSem;
|
|
|
|
#else
|
|
|
|
#include <semaphore.h>
|
|
|
|
typedef struct { int init; sem_t sem; } TCCSem;
|
|
|
|
#endif
|
|
|
|
ST_FUNC void wait_sem(TCCSem *p);
|
|
|
|
ST_FUNC void post_sem(TCCSem *p);
|
|
|
|
#define TCC_SEM(s) TCCSem s
|
|
|
|
#define WAIT_SEM wait_sem
|
|
|
|
#define POST_SEM post_sem
|
|
|
|
#else
|
|
|
|
#define TCC_SEM(s)
|
|
|
|
#define WAIT_SEM(p)
|
|
|
|
#define POST_SEM(p)
|
|
|
|
#endif
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
/********************************************************/
|
|
|
|
#undef ST_DATA
|
2017-07-24 03:24:11 +08:00
|
|
|
#if ONE_SOURCE
|
2009-12-20 08:53:49 +08:00
|
|
|
#define ST_DATA static
|
|
|
|
#else
|
|
|
|
#define ST_DATA
|
|
|
|
#endif
|
2019-12-11 07:37:18 +08:00
|
|
|
/********************************************************/
|
|
|
|
|
|
|
|
#define text_section TCC_STATE_VAR(text_section)
|
|
|
|
#define data_section TCC_STATE_VAR(data_section)
|
2021-02-01 22:10:58 +08:00
|
|
|
#define rodata_section TCC_STATE_VAR(rodata_section)
|
2019-12-11 07:37:18 +08:00
|
|
|
#define bss_section TCC_STATE_VAR(bss_section)
|
|
|
|
#define common_section TCC_STATE_VAR(common_section)
|
|
|
|
#define cur_text_section TCC_STATE_VAR(cur_text_section)
|
|
|
|
#define bounds_section TCC_STATE_VAR(bounds_section)
|
|
|
|
#define lbounds_section TCC_STATE_VAR(lbounds_section)
|
|
|
|
#define symtab_section TCC_STATE_VAR(symtab_section)
|
|
|
|
#define gnu_ext TCC_STATE_VAR(gnu_ext)
|
|
|
|
#define tcc_error_noabort TCC_SET_STATE(_tcc_error_noabort)
|
|
|
|
#define tcc_error TCC_SET_STATE(_tcc_error)
|
|
|
|
#define tcc_warning TCC_SET_STATE(_tcc_warning)
|
|
|
|
|
2019-12-14 19:31:03 +08:00
|
|
|
#define total_idents TCC_STATE_VAR(total_idents)
|
|
|
|
#define total_lines TCC_STATE_VAR(total_lines)
|
|
|
|
#define total_bytes TCC_STATE_VAR(total_bytes)
|
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
PUB_FUNC void tcc_enter_state(TCCState *s1);
|
|
|
|
PUB_FUNC void tcc_exit_state(TCCState *s1);
|
2019-12-11 07:37:18 +08:00
|
|
|
|
2021-08-01 02:44:51 +08:00
|
|
|
/* conditional warning depending on switch */
|
|
|
|
#define tcc_warning_c(sw) TCC_SET_STATE((\
|
2021-10-22 13:39:54 +08:00
|
|
|
tcc_state->warn_num = offsetof(TCCState, sw) \
|
2021-08-01 02:44:51 +08:00
|
|
|
- offsetof(TCCState, warn_none), _tcc_warning))
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
/********************************************************/
|
|
|
|
#endif /* _TCC_H */
|
2019-12-11 07:37:18 +08:00
|
|
|
|
|
|
|
#undef TCC_STATE_VAR
|
|
|
|
#undef TCC_SET_STATE
|
|
|
|
|
|
|
|
#ifdef USING_GLOBALS
|
2021-10-22 13:39:54 +08:00
|
|
|
# define TCC_STATE_VAR(sym) tcc_state->sym
|
2019-12-11 07:37:18 +08:00
|
|
|
# define TCC_SET_STATE(fn) fn
|
|
|
|
# undef USING_GLOBALS
|
|
|
|
#else
|
2021-10-22 13:39:54 +08:00
|
|
|
# define TCC_STATE_VAR(sym) s1->sym
|
|
|
|
# define TCC_SET_STATE(fn) (tcc_enter_state(s1),fn)
|
2019-12-11 07:37:18 +08:00
|
|
|
#endif
|