2009-05-06 02:17:11 +08:00
|
|
|
|
/*
|
|
|
|
|
* TCC - Tiny C Compiler
|
2013-11-09 03:24:15 +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
|
|
|
|
|
*/
|
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
|
#if !defined ONE_SOURCE || ONE_SOURCE
|
2009-12-20 08:53:49 +08:00
|
|
|
|
#include "tccpp.c"
|
|
|
|
|
#include "tccgen.c"
|
|
|
|
|
#include "tccelf.c"
|
|
|
|
|
#include "tccrun.c"
|
2009-05-06 02:18:53 +08:00
|
|
|
|
#ifdef TCC_TARGET_I386
|
2015-07-30 04:53:57 +08:00
|
|
|
|
#include "i386-gen.c"
|
2016-11-12 23:16:06 +08:00
|
|
|
|
#include "i386-link.c"
|
2017-05-13 14:59:06 +08:00
|
|
|
|
#include "i386-asm.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-11-12 23:16:06 +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-11-12 23:16:06 +08:00
|
|
|
|
#include "arm64-link.c"
|
2019-06-22 12:13:10 +08:00
|
|
|
|
#elif defined(TCC_TARGET_C67)
|
2015-07-30 04:53:57 +08:00
|
|
|
|
#include "c67-gen.c"
|
2016-11-12 23:16:06 +08:00
|
|
|
|
#include "c67-link.c"
|
2017-07-24 03:24:11 +08:00
|
|
|
|
#include "tcccoff.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-11-12 23:16:06 +08:00
|
|
|
|
#include "x86_64-link.c"
|
2017-05-13 14:59:06 +08:00
|
|
|
|
#include "i386-asm.c"
|
2019-06-22 12:13:10 +08:00
|
|
|
|
#elif defined(TCC_TARGET_RISCV64)
|
|
|
|
|
#include "riscv64-gen.c"
|
|
|
|
|
#include "riscv64-link.c"
|
|
|
|
|
#else
|
|
|
|
|
#error unknown target
|
2009-05-06 02:18:53 +08:00
|
|
|
|
#endif
|
2009-07-07 03:13:20 +08:00
|
|
|
|
#ifdef CONFIG_TCC_ASM
|
2009-12-20 08:53:49 +08:00
|
|
|
|
#include "tccasm.c"
|
2009-07-07 03:13:20 +08:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
|
#include "tccpe.c"
|
|
|
|
|
#endif
|
2011-07-22 17:12:49 +08:00
|
|
|
|
#endif /* ONE_SOURCE */
|
2009-07-07 03:13:20 +08:00
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
|
#include "tcc.h"
|
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
|
/********************************************************/
|
2019-12-11 07:37:18 +08:00
|
|
|
|
/* global variables */
|
|
|
|
|
|
|
|
|
|
/* XXX: get rid of this ASAP (or maybe not) */
|
|
|
|
|
ST_DATA struct TCCState *tcc_state;
|
|
|
|
|
|
2019-12-14 19:31:03 +08:00
|
|
|
|
#ifdef MEM_DEBUG
|
2019-12-11 07:37:18 +08:00
|
|
|
|
static int nb_states;
|
2019-12-14 19:31:03 +08:00
|
|
|
|
#endif
|
2009-12-20 05:10:26 +08:00
|
|
|
|
|
2009-07-19 04:07:25 +08:00
|
|
|
|
/********************************************************/
|
|
|
|
|
#ifdef _WIN32
|
2016-10-15 21:55:31 +08:00
|
|
|
|
ST_FUNC char *normalize_slashes(char *path)
|
2009-07-19 04:07:25 +08:00
|
|
|
|
{
|
|
|
|
|
char *p;
|
2013-08-29 04:55:05 +08:00
|
|
|
|
for (p = path; *p; ++p)
|
|
|
|
|
if (*p == '\\')
|
|
|
|
|
*p = '/';
|
2009-07-19 04:07:25 +08:00
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
|
static HMODULE tcc_module;
|
2009-07-19 04:07:25 +08:00
|
|
|
|
|
|
|
|
|
/* on win32, we suppose the lib and includes are at the location of 'tcc.exe' */
|
2009-12-20 08:53:49 +08:00
|
|
|
|
static void tcc_set_lib_path_w32(TCCState *s)
|
2009-07-19 04:07:25 +08:00
|
|
|
|
{
|
|
|
|
|
char path[1024], *p;
|
|
|
|
|
GetModuleFileNameA(tcc_module, path, sizeof path);
|
|
|
|
|
p = tcc_basename(normalize_slashes(strlwr(path)));
|
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 (p > path)
|
|
|
|
|
--p;
|
2009-07-19 04:07:25 +08:00
|
|
|
|
*p = 0;
|
|
|
|
|
tcc_set_lib_path(s, path);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-07 02:01:07 +08:00
|
|
|
|
#ifdef TCC_TARGET_PE
|
2011-08-01 07:10:36 +08:00
|
|
|
|
static void tcc_add_systemdir(TCCState *s)
|
|
|
|
|
{
|
|
|
|
|
char buf[1000];
|
|
|
|
|
GetSystemDirectory(buf, sizeof buf);
|
2011-08-11 22:55:30 +08:00
|
|
|
|
tcc_add_library_path(s, normalize_slashes(buf));
|
2011-08-01 07:10:36 +08:00
|
|
|
|
}
|
2013-02-07 02:01:07 +08:00
|
|
|
|
#endif
|
2011-08-01 07:10:36 +08:00
|
|
|
|
|
2009-07-19 04:07:25 +08:00
|
|
|
|
#ifdef LIBTCC_AS_DLL
|
2014-04-12 11:49:53 +08:00
|
|
|
|
BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved)
|
2009-07-19 04:07:25 +08:00
|
|
|
|
{
|
|
|
|
|
if (DLL_PROCESS_ATTACH == dwReason)
|
|
|
|
|
tcc_module = hDll;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
|
/********************************************************/
|
|
|
|
|
#ifndef CONFIG_TCC_SEMLOCK
|
|
|
|
|
#define WAIT_SEM()
|
|
|
|
|
#define POST_SEM()
|
|
|
|
|
#elif defined _WIN32
|
|
|
|
|
static int tcc_sem_init;
|
|
|
|
|
static CRITICAL_SECTION tcc_cr;
|
|
|
|
|
static void wait_sem(void)
|
|
|
|
|
{
|
|
|
|
|
if (!tcc_sem_init)
|
|
|
|
|
InitializeCriticalSection(&tcc_cr), tcc_sem_init = 1;
|
|
|
|
|
EnterCriticalSection(&tcc_cr);
|
|
|
|
|
}
|
|
|
|
|
#define WAIT_SEM() wait_sem()
|
|
|
|
|
#define POST_SEM() LeaveCriticalSection(&tcc_cr);
|
|
|
|
|
#else
|
|
|
|
|
#include <semaphore.h>
|
|
|
|
|
static int tcc_sem_init;
|
|
|
|
|
static sem_t tcc_sem;
|
|
|
|
|
static void wait_sem(void)
|
|
|
|
|
{
|
|
|
|
|
if (!tcc_sem_init)
|
|
|
|
|
sem_init(&tcc_sem, 0, 1), tcc_sem_init = 1;
|
|
|
|
|
while (sem_wait (&tcc_sem) < 0 && errno == EINTR);
|
|
|
|
|
}
|
|
|
|
|
#define WAIT_SEM() wait_sem()
|
|
|
|
|
#define POST_SEM() sem_post(&tcc_sem)
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
/********************************************************/
|
|
|
|
|
/* copy a string and truncate it. */
|
2019-12-02 03:45:42 +08:00
|
|
|
|
ST_FUNC char *pstrcpy(char *buf, size_t buf_size, const char *s)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
char *q, *q_end;
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
if (buf_size > 0) {
|
|
|
|
|
q = buf;
|
|
|
|
|
q_end = buf + buf_size - 1;
|
|
|
|
|
while (q < q_end) {
|
|
|
|
|
c = *s++;
|
|
|
|
|
if (c == '\0')
|
|
|
|
|
break;
|
|
|
|
|
*q++ = c;
|
|
|
|
|
}
|
|
|
|
|
*q = '\0';
|
|
|
|
|
}
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* strcat and truncate. */
|
2019-12-02 03:45:42 +08:00
|
|
|
|
ST_FUNC char *pstrcat(char *buf, size_t buf_size, const char *s)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2019-12-02 03:45:42 +08:00
|
|
|
|
size_t len;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
len = strlen(buf);
|
2013-11-09 03:24:15 +08:00
|
|
|
|
if (len < buf_size)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
pstrcpy(buf + len, buf_size - len, s);
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-09 02:49:28 +08:00
|
|
|
|
ST_FUNC char *pstrncpy(char *out, const char *in, size_t num)
|
2011-08-01 07:10:36 +08:00
|
|
|
|
{
|
|
|
|
|
memcpy(out, in, num);
|
|
|
|
|
out[num] = '\0';
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
/* extract the basename of a file */
|
2009-12-20 08:53:49 +08:00
|
|
|
|
PUB_FUNC char *tcc_basename(const char *name)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
char *p = strchr(name, 0);
|
2011-08-01 07:10:36 +08:00
|
|
|
|
while (p > name && !IS_DIRSEP(p[-1]))
|
2009-05-06 02:18:53 +08:00
|
|
|
|
--p;
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-20 23:17:42 +08:00
|
|
|
|
/* extract extension part of a file
|
|
|
|
|
*
|
|
|
|
|
* (if no extension, return pointer to end-of-string)
|
|
|
|
|
*/
|
2009-12-20 08:53:49 +08:00
|
|
|
|
PUB_FUNC char *tcc_fileextension (const char *name)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
char *b = tcc_basename(name);
|
|
|
|
|
char *e = strrchr(b, '.');
|
|
|
|
|
return e ? e : strchr(b, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
|
/********************************************************/
|
2009-05-06 02:18:53 +08:00
|
|
|
|
/* memory management */
|
2009-12-20 08:53:49 +08:00
|
|
|
|
|
|
|
|
|
#undef free
|
|
|
|
|
#undef malloc
|
|
|
|
|
#undef realloc
|
|
|
|
|
|
2015-05-12 16:56:39 +08:00
|
|
|
|
#ifndef MEM_DEBUG
|
2009-05-06 02:18:53 +08:00
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
|
PUB_FUNC void tcc_free(void *ptr)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
free(ptr);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
|
PUB_FUNC void *tcc_malloc(unsigned long size)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
void *ptr;
|
|
|
|
|
ptr = malloc(size);
|
|
|
|
|
if (!ptr && size)
|
2019-12-11 07:37:18 +08:00
|
|
|
|
_tcc_error("memory full (malloc)");
|
2009-05-06 02:18:53 +08:00
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
|
PUB_FUNC void *tcc_mallocz(unsigned long size)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
void *ptr;
|
|
|
|
|
ptr = tcc_malloc(size);
|
|
|
|
|
memset(ptr, 0, size);
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
|
PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
void *ptr1;
|
|
|
|
|
ptr1 = realloc(ptr, size);
|
2012-04-19 00:43:55 +08:00
|
|
|
|
if (!ptr1 && size)
|
2019-12-11 07:37:18 +08:00
|
|
|
|
_tcc_error("memory full (realloc)");
|
2009-05-06 02:18:53 +08:00
|
|
|
|
return ptr1;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
|
PUB_FUNC char *tcc_strdup(const char *str)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
char *ptr;
|
|
|
|
|
ptr = tcc_malloc(strlen(str) + 1);
|
|
|
|
|
strcpy(ptr, str);
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-12 16:56:39 +08:00
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
#define MEM_DEBUG_MAGIC1 0xFEEDDEB1
|
|
|
|
|
#define MEM_DEBUG_MAGIC2 0xFEEDDEB2
|
2016-12-19 05:57:03 +08:00
|
|
|
|
#define MEM_DEBUG_MAGIC3 0xFEEDDEB3
|
|
|
|
|
#define MEM_DEBUG_FILE_LEN 40
|
|
|
|
|
#define MEM_DEBUG_CHECK3(header) \
|
|
|
|
|
((mem_debug_header_t*)((char*)header + header->size))->magic3
|
|
|
|
|
#define MEM_USER_PTR(header) \
|
|
|
|
|
((char *)header + offsetof(mem_debug_header_t, magic3))
|
|
|
|
|
#define MEM_HEADER_PTR(ptr) \
|
|
|
|
|
(mem_debug_header_t *)((char*)ptr - offsetof(mem_debug_header_t, magic3))
|
2015-05-12 16:56:39 +08:00
|
|
|
|
|
|
|
|
|
struct mem_debug_header {
|
2016-12-19 05:05:42 +08:00
|
|
|
|
unsigned magic1;
|
|
|
|
|
unsigned size;
|
2015-05-12 16:56:39 +08:00
|
|
|
|
struct mem_debug_header *prev;
|
|
|
|
|
struct mem_debug_header *next;
|
2016-12-19 05:05:42 +08:00
|
|
|
|
int line_num;
|
|
|
|
|
char file_name[MEM_DEBUG_FILE_LEN + 1];
|
|
|
|
|
unsigned magic2;
|
2017-07-09 18:07:40 +08:00
|
|
|
|
ALIGNED(16) unsigned magic3;
|
2015-05-12 16:56:39 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct mem_debug_header mem_debug_header_t;
|
|
|
|
|
|
|
|
|
|
static mem_debug_header_t *mem_debug_chain;
|
2016-12-19 05:05:42 +08:00
|
|
|
|
static unsigned mem_cur_size;
|
|
|
|
|
static unsigned mem_max_size;
|
2015-05-12 16:56:39 +08:00
|
|
|
|
|
2016-12-19 05:57:03 +08:00
|
|
|
|
static mem_debug_header_t *malloc_check(void *ptr, const char *msg)
|
|
|
|
|
{
|
|
|
|
|
mem_debug_header_t * header = MEM_HEADER_PTR(ptr);
|
|
|
|
|
if (header->magic1 != MEM_DEBUG_MAGIC1 ||
|
|
|
|
|
header->magic2 != MEM_DEBUG_MAGIC2 ||
|
|
|
|
|
MEM_DEBUG_CHECK3(header) != MEM_DEBUG_MAGIC3 ||
|
|
|
|
|
header->size == (unsigned)-1) {
|
|
|
|
|
fprintf(stderr, "%s check failed\n", msg);
|
|
|
|
|
if (header->magic1 == MEM_DEBUG_MAGIC1)
|
|
|
|
|
fprintf(stderr, "%s:%u: block allocated here.\n",
|
|
|
|
|
header->file_name, header->line_num);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
return header;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-12 16:56:39 +08:00
|
|
|
|
PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line)
|
|
|
|
|
{
|
2016-04-17 21:37:23 +08:00
|
|
|
|
int ofs;
|
2015-05-12 16:56:39 +08:00
|
|
|
|
mem_debug_header_t *header;
|
|
|
|
|
|
2016-12-19 05:57:03 +08:00
|
|
|
|
header = malloc(sizeof(mem_debug_header_t) + size);
|
|
|
|
|
if (!header)
|
2019-12-11 07:37:18 +08:00
|
|
|
|
_tcc_error("memory full (malloc)");
|
2015-05-12 16:56:39 +08:00
|
|
|
|
|
|
|
|
|
header->magic1 = MEM_DEBUG_MAGIC1;
|
|
|
|
|
header->magic2 = MEM_DEBUG_MAGIC2;
|
|
|
|
|
header->size = size;
|
2016-12-19 05:57:03 +08:00
|
|
|
|
MEM_DEBUG_CHECK3(header) = MEM_DEBUG_MAGIC3;
|
2015-05-12 16:56:39 +08:00
|
|
|
|
header->line_num = line;
|
2016-04-17 21:37:23 +08:00
|
|
|
|
ofs = strlen(file) - MEM_DEBUG_FILE_LEN;
|
|
|
|
|
strncpy(header->file_name, file + (ofs > 0 ? ofs : 0), MEM_DEBUG_FILE_LEN);
|
2015-05-12 16:56:39 +08:00
|
|
|
|
header->file_name[MEM_DEBUG_FILE_LEN] = 0;
|
|
|
|
|
|
|
|
|
|
header->next = mem_debug_chain;
|
|
|
|
|
header->prev = NULL;
|
|
|
|
|
if (header->next)
|
|
|
|
|
header->next->prev = header;
|
|
|
|
|
mem_debug_chain = header;
|
|
|
|
|
|
2016-12-19 05:57:03 +08:00
|
|
|
|
mem_cur_size += size;
|
|
|
|
|
if (mem_cur_size > mem_max_size)
|
|
|
|
|
mem_max_size = mem_cur_size;
|
|
|
|
|
|
|
|
|
|
return MEM_USER_PTR(header);
|
2015-05-12 16:56:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PUB_FUNC void tcc_free_debug(void *ptr)
|
|
|
|
|
{
|
|
|
|
|
mem_debug_header_t *header;
|
|
|
|
|
if (!ptr)
|
|
|
|
|
return;
|
2016-12-19 05:57:03 +08:00
|
|
|
|
header = malloc_check(ptr, "tcc_free");
|
2015-05-12 16:56:39 +08:00
|
|
|
|
mem_cur_size -= header->size;
|
2016-12-19 05:05:42 +08:00
|
|
|
|
header->size = (unsigned)-1;
|
2015-05-12 16:56:39 +08:00
|
|
|
|
if (header->next)
|
|
|
|
|
header->next->prev = header->prev;
|
|
|
|
|
if (header->prev)
|
|
|
|
|
header->prev->next = header->next;
|
|
|
|
|
if (header == mem_debug_chain)
|
|
|
|
|
mem_debug_chain = header->next;
|
2016-12-19 05:57:03 +08:00
|
|
|
|
free(header);
|
2015-05-12 16:56:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PUB_FUNC void *tcc_mallocz_debug(unsigned long size, const char *file, int line)
|
|
|
|
|
{
|
|
|
|
|
void *ptr;
|
|
|
|
|
ptr = tcc_malloc_debug(size,file,line);
|
|
|
|
|
memset(ptr, 0, size);
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file, int line)
|
|
|
|
|
{
|
|
|
|
|
mem_debug_header_t *header;
|
|
|
|
|
int mem_debug_chain_update = 0;
|
|
|
|
|
if (!ptr)
|
2016-12-19 05:57:03 +08:00
|
|
|
|
return tcc_malloc_debug(size, file, line);
|
|
|
|
|
header = malloc_check(ptr, "tcc_realloc");
|
|
|
|
|
mem_cur_size -= header->size;
|
|
|
|
|
mem_debug_chain_update = (header == mem_debug_chain);
|
|
|
|
|
header = realloc(header, sizeof(mem_debug_header_t) + size);
|
|
|
|
|
if (!header)
|
2019-12-11 07:37:18 +08:00
|
|
|
|
_tcc_error("memory full (realloc)");
|
2015-05-12 16:56:39 +08:00
|
|
|
|
header->size = size;
|
2016-12-19 05:57:03 +08:00
|
|
|
|
MEM_DEBUG_CHECK3(header) = MEM_DEBUG_MAGIC3;
|
2015-05-12 16:56:39 +08:00
|
|
|
|
if (header->next)
|
|
|
|
|
header->next->prev = header;
|
|
|
|
|
if (header->prev)
|
|
|
|
|
header->prev->next = header;
|
|
|
|
|
if (mem_debug_chain_update)
|
|
|
|
|
mem_debug_chain = header;
|
2016-12-19 05:57:03 +08:00
|
|
|
|
mem_cur_size += size;
|
|
|
|
|
if (mem_cur_size > mem_max_size)
|
|
|
|
|
mem_max_size = mem_cur_size;
|
|
|
|
|
return MEM_USER_PTR(header);
|
2015-05-12 16:56:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line)
|
|
|
|
|
{
|
|
|
|
|
char *ptr;
|
|
|
|
|
ptr = tcc_malloc_debug(strlen(str) + 1, file, line);
|
|
|
|
|
strcpy(ptr, str);
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-18 16:55:34 +08:00
|
|
|
|
PUB_FUNC void tcc_memcheck(void)
|
2015-05-12 16:56:39 +08:00
|
|
|
|
{
|
|
|
|
|
if (mem_cur_size) {
|
|
|
|
|
mem_debug_header_t *header = mem_debug_chain;
|
|
|
|
|
fprintf(stderr, "MEM_DEBUG: mem_leak= %d bytes, mem_max_size= %d bytes\n",
|
|
|
|
|
mem_cur_size, mem_max_size);
|
|
|
|
|
while (header) {
|
2016-10-06 00:34:17 +08:00
|
|
|
|
fprintf(stderr, "%s:%u: error: %u bytes leaked\n",
|
2015-05-12 16:56:39 +08:00
|
|
|
|
header->file_name, header->line_num, header->size);
|
|
|
|
|
header = header->next;
|
|
|
|
|
}
|
2016-12-19 05:05:42 +08:00
|
|
|
|
#if MEM_DEBUG-0 == 2
|
|
|
|
|
exit(2);
|
|
|
|
|
#endif
|
2017-02-18 16:55:34 +08:00
|
|
|
|
}
|
2015-05-12 16:56:39 +08:00
|
|
|
|
}
|
2016-12-19 05:57:03 +08:00
|
|
|
|
#endif /* MEM_DEBUG */
|
2015-05-12 16:56:39 +08:00
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
#define free(p) use_tcc_free(p)
|
|
|
|
|
#define malloc(s) use_tcc_malloc(s)
|
|
|
|
|
#define realloc(p, s) use_tcc_realloc(p, s)
|
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
|
/********************************************************/
|
|
|
|
|
/* dynarrays */
|
|
|
|
|
|
2017-02-14 01:23:43 +08:00
|
|
|
|
ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
int nb, nb_alloc;
|
|
|
|
|
void **pp;
|
2013-11-09 03:24:15 +08:00
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
nb = *nb_ptr;
|
2017-02-14 01:23:43 +08:00
|
|
|
|
pp = *(void ***)ptab;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
/* every power of two we double array size */
|
|
|
|
|
if ((nb & (nb - 1)) == 0) {
|
|
|
|
|
if (!nb)
|
|
|
|
|
nb_alloc = 1;
|
|
|
|
|
else
|
|
|
|
|
nb_alloc = nb * 2;
|
|
|
|
|
pp = tcc_realloc(pp, nb_alloc * sizeof(void *));
|
2017-02-14 01:23:43 +08:00
|
|
|
|
*(void***)ptab = pp;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
pp[nb++] = data;
|
|
|
|
|
*nb_ptr = nb;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
|
ST_FUNC void dynarray_reset(void *pp, int *n)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
void **p;
|
|
|
|
|
for (p = *(void***)pp; *n; ++p, --*n)
|
|
|
|
|
if (*p)
|
|
|
|
|
tcc_free(*p);
|
|
|
|
|
tcc_free(*(void**)pp);
|
|
|
|
|
*(void**)pp = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-18 16:55:34 +08:00
|
|
|
|
static void tcc_split_path(TCCState *s, void *p_ary, int *p_nb_ary, const char *in)
|
2011-07-08 16:51:26 +08:00
|
|
|
|
{
|
2011-08-01 07:10:36 +08:00
|
|
|
|
const char *p;
|
2011-07-08 16:51:26 +08:00
|
|
|
|
do {
|
2011-08-01 07:10:36 +08:00
|
|
|
|
int c;
|
|
|
|
|
CString str;
|
|
|
|
|
|
|
|
|
|
cstr_new(&str);
|
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
|
|
|
|
for (p = in; c = *p, c != '\0' && c != PATHSEP[0]; ++p) {
|
2011-08-11 22:55:30 +08:00
|
|
|
|
if (c == '{' && p[1] && p[2] == '}') {
|
|
|
|
|
c = p[1], p += 2;
|
|
|
|
|
if (c == 'B')
|
2016-04-17 21:37:23 +08:00
|
|
|
|
cstr_cat(&str, s->tcc_lib_path, -1);
|
2019-12-17 05:34:47 +08:00
|
|
|
|
if (c == 'f' && file) {
|
|
|
|
|
/* substitute current file's dir */
|
|
|
|
|
const char *f = file->true_filename;
|
|
|
|
|
const char *b = tcc_basename(f);
|
|
|
|
|
if (b > f)
|
|
|
|
|
cstr_cat(&str, f, b - f - 1);
|
|
|
|
|
else
|
|
|
|
|
cstr_cat(&str, ".", 1);
|
|
|
|
|
}
|
2011-08-06 22:11:12 +08:00
|
|
|
|
} else {
|
|
|
|
|
cstr_ccat(&str, c);
|
2011-08-01 07:10:36 +08:00
|
|
|
|
}
|
2011-07-08 16:51:26 +08:00
|
|
|
|
}
|
2016-10-03 18:29:38 +08:00
|
|
|
|
if (str.size) {
|
|
|
|
|
cstr_ccat(&str, '\0');
|
|
|
|
|
dynarray_add(p_ary, p_nb_ary, tcc_strdup(str.data));
|
|
|
|
|
}
|
2016-04-17 21:37:23 +08:00
|
|
|
|
cstr_free(&str);
|
2011-08-06 22:11:12 +08:00
|
|
|
|
in = p+1;
|
|
|
|
|
} while (*p);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
|
/********************************************************/
|
2009-05-06 02:18:53 +08:00
|
|
|
|
|
|
|
|
|
static void strcat_vprintf(char *buf, int buf_size, const char *fmt, va_list ap)
|
|
|
|
|
{
|
|
|
|
|
int len;
|
|
|
|
|
len = strlen(buf);
|
|
|
|
|
vsnprintf(buf + len, buf_size - len, fmt, ap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void strcat_printf(char *buf, int buf_size, const char *fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
strcat_vprintf(buf, buf_size, fmt, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
|
#define ERROR_WARN 0
|
|
|
|
|
#define ERROR_NOABORT 1
|
|
|
|
|
#define ERROR_ERROR 2
|
|
|
|
|
|
|
|
|
|
PUB_FUNC void tcc_enter_state(TCCState *s1)
|
|
|
|
|
{
|
|
|
|
|
WAIT_SEM();
|
|
|
|
|
tcc_state = s1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void error1(int mode, const char *fmt, va_list ap)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
char buf[2048];
|
2013-02-14 13:53:07 +08:00
|
|
|
|
BufferedFile **pf, *f;
|
2019-12-11 07:37:18 +08:00
|
|
|
|
TCCState *s1 = tcc_state;
|
|
|
|
|
|
|
|
|
|
/* 's1->error_set_jmp_enabled' means that we're called from
|
|
|
|
|
within the parser/generator and 'tcc_state' was already
|
|
|
|
|
set (i.e. not by the function above).
|
|
|
|
|
|
|
|
|
|
Otherwise, 's1 = NULL' means we're called because of severe
|
|
|
|
|
problems from tcc_malloc() which under normal conditions
|
|
|
|
|
should never happen. */
|
|
|
|
|
|
|
|
|
|
if (s1 && !s1->error_set_jmp_enabled) {
|
|
|
|
|
tcc_state = NULL;
|
|
|
|
|
POST_SEM();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mode == ERROR_WARN) {
|
|
|
|
|
if (s1->warn_none)
|
|
|
|
|
return;
|
|
|
|
|
if (s1->warn_error)
|
|
|
|
|
mode = ERROR_ERROR;
|
|
|
|
|
}
|
2013-11-09 03:24:15 +08:00
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
buf[0] = '\0';
|
2013-02-14 13:53:07 +08:00
|
|
|
|
/* use upper file if inline ":asm:" or token ":paste:" */
|
2013-02-18 22:44:18 +08:00
|
|
|
|
for (f = file; f && f->filename[0] == ':'; f = f->prev)
|
|
|
|
|
;
|
2013-02-14 13:53:07 +08:00
|
|
|
|
if (f) {
|
|
|
|
|
for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++)
|
|
|
|
|
strcat_printf(buf, sizeof(buf), "In file included from %s:%d:\n",
|
|
|
|
|
(*pf)->filename, (*pf)->line_num);
|
2017-12-13 00:33:37 +08:00
|
|
|
|
if (s1->error_set_jmp_enabled) {
|
2013-02-14 13:53:07 +08:00
|
|
|
|
strcat_printf(buf, sizeof(buf), "%s:%d: ",
|
2016-05-26 00:51:36 +08:00
|
|
|
|
f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL));
|
2009-05-06 02:18:53 +08:00
|
|
|
|
} else {
|
2013-02-14 13:53:07 +08:00
|
|
|
|
strcat_printf(buf, sizeof(buf), "%s: ",
|
|
|
|
|
f->filename);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2013-02-14 13:53:07 +08:00
|
|
|
|
strcat_printf(buf, sizeof(buf), "tcc: ");
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
2019-12-11 07:37:18 +08:00
|
|
|
|
if (mode == ERROR_WARN)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
strcat_printf(buf, sizeof(buf), "warning: ");
|
2009-06-17 08:10:56 +08:00
|
|
|
|
else
|
|
|
|
|
strcat_printf(buf, sizeof(buf), "error: ");
|
2009-05-06 02:18:53 +08:00
|
|
|
|
strcat_vprintf(buf, sizeof(buf), fmt, ap);
|
2019-12-11 07:37:18 +08:00
|
|
|
|
if (!s1 || !s1->error_func) {
|
2009-05-06 02:18:53 +08:00
|
|
|
|
/* default case: stderr */
|
2019-12-11 07:37:18 +08:00
|
|
|
|
if (s1 && s1->output_type == TCC_OUTPUT_PREPROCESS && s1->ppfp == stdout)
|
2017-07-21 04:21:27 +08:00
|
|
|
|
/* print a newline during tcc -E */
|
|
|
|
|
printf("\n"), fflush(stdout);
|
2017-02-14 01:23:55 +08:00
|
|
|
|
fflush(stdout); /* flush -v output */
|
2009-05-06 02:18:53 +08:00
|
|
|
|
fprintf(stderr, "%s\n", buf);
|
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
|
|
|
|
fflush(stderr); /* print error/warning now (win32) */
|
2009-05-06 02:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
s1->error_func(s1->error_opaque, buf);
|
|
|
|
|
}
|
2019-12-11 07:37:18 +08:00
|
|
|
|
if (s1) {
|
|
|
|
|
if (mode != ERROR_WARN)
|
|
|
|
|
s1->nb_errors++;
|
|
|
|
|
if (mode != ERROR_ERROR)
|
|
|
|
|
return;
|
|
|
|
|
if (s1->error_set_jmp_enabled)
|
|
|
|
|
longjmp(s1->error_jmp_buf, 1);
|
|
|
|
|
}
|
|
|
|
|
exit(1);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-14 15:36:14 +08:00
|
|
|
|
LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, TCCErrorFunc error_func)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
s->error_opaque = error_opaque;
|
|
|
|
|
s->error_func = error_func;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-14 15:36:14 +08:00
|
|
|
|
LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *s)
|
|
|
|
|
{
|
|
|
|
|
return s->error_func;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBTCCAPI void *tcc_get_error_opaque(TCCState *s)
|
|
|
|
|
{
|
|
|
|
|
return s->error_opaque;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
/* error without aborting current compilation */
|
2019-12-11 07:37:18 +08:00
|
|
|
|
PUB_FUNC void _tcc_error_noabort(const char *fmt, ...)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, fmt);
|
2019-12-11 07:37:18 +08:00
|
|
|
|
error1(ERROR_NOABORT, fmt, ap);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
|
PUB_FUNC void _tcc_error(const char *fmt, ...)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, fmt);
|
2019-12-11 07:37:18 +08:00
|
|
|
|
for (;;) error1(ERROR_ERROR, fmt, ap);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
|
PUB_FUNC void _tcc_warning(const char *fmt, ...)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, fmt);
|
2019-12-11 07:37:18 +08:00
|
|
|
|
error1(ERROR_WARN, fmt, ap);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
|
/********************************************************/
|
2009-05-06 02:18:53 +08:00
|
|
|
|
/* I/O layer */
|
|
|
|
|
|
2010-11-25 20:29:15 +08:00
|
|
|
|
ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
BufferedFile *bf;
|
2010-11-25 20:29:15 +08:00
|
|
|
|
int buflen = initlen ? initlen : IO_BUF_SIZE;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
|
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
|
|
|
|
bf = tcc_mallocz(sizeof(BufferedFile) + buflen);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
bf->buf_ptr = bf->buffer;
|
2010-11-25 20:29:15 +08:00
|
|
|
|
bf->buf_end = bf->buffer + initlen;
|
|
|
|
|
bf->buf_end[0] = CH_EOB; /* put eob symbol */
|
2009-05-06 02:18:53 +08:00
|
|
|
|
pstrcpy(bf->filename, sizeof(bf->filename), filename);
|
2019-12-11 07:37:18 +08:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
normalize_slashes(bf->filename);
|
|
|
|
|
#endif
|
2017-07-09 18:07:40 +08:00
|
|
|
|
bf->true_filename = bf->filename;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
bf->line_num = 1;
|
|
|
|
|
bf->ifdef_stack_ptr = s1->ifdef_stack_ptr;
|
2013-01-15 00:34:07 +08:00
|
|
|
|
bf->fd = -1;
|
2010-11-25 20:29:15 +08:00
|
|
|
|
bf->prev = file;
|
|
|
|
|
file = bf;
|
2017-07-21 04:21:27 +08:00
|
|
|
|
tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 20:29:15 +08:00
|
|
|
|
ST_FUNC void tcc_close(void)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2019-12-14 19:31:03 +08:00
|
|
|
|
TCCState *s1 = tcc_state;
|
2010-11-25 20:29:15 +08:00
|
|
|
|
BufferedFile *bf = file;
|
2013-01-15 00:34:07 +08:00
|
|
|
|
if (bf->fd > 0) {
|
|
|
|
|
close(bf->fd);
|
2010-11-25 20:29:15 +08:00
|
|
|
|
total_lines += bf->line_num;
|
|
|
|
|
}
|
2017-07-09 18:07:40 +08:00
|
|
|
|
if (bf->true_filename != bf->filename)
|
|
|
|
|
tcc_free(bf->true_filename);
|
2010-11-25 20:29:15 +08:00
|
|
|
|
file = bf->prev;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
tcc_free(bf);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
|
static int _tcc_open(TCCState *s1, const char *filename)
|
2010-11-25 20:29:15 +08:00
|
|
|
|
{
|
2013-01-15 00:34:07 +08:00
|
|
|
|
int fd;
|
|
|
|
|
if (strcmp(filename, "-") == 0)
|
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
|
|
|
|
fd = 0, filename = "<stdin>";
|
2010-11-25 20:29:15 +08:00
|
|
|
|
else
|
2013-01-15 00:34:07 +08:00
|
|
|
|
fd = open(filename, O_RDONLY | O_BINARY);
|
|
|
|
|
if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3)
|
|
|
|
|
printf("%s %*s%s\n", fd < 0 ? "nf":"->",
|
2010-11-25 20:29:15 +08:00
|
|
|
|
(int)(s1->include_stack_ptr - s1->include_stack), "", filename);
|
2019-12-11 07:37:18 +08:00
|
|
|
|
return fd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ST_FUNC int tcc_open(TCCState *s1, const char *filename)
|
|
|
|
|
{
|
|
|
|
|
int fd = _tcc_open(s1, filename);
|
2013-01-15 00:34:07 +08:00
|
|
|
|
if (fd < 0)
|
|
|
|
|
return -1;
|
2010-11-25 20:29:15 +08:00
|
|
|
|
tcc_open_bf(s1, filename, 0);
|
|
|
|
|
file->fd = fd;
|
2019-12-11 07:37:18 +08:00
|
|
|
|
return 0;
|
2010-11-25 20:29:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-21 04:21:27 +08:00
|
|
|
|
/* compile the file opened in 'file'. Return non zero if errors. */
|
2019-12-11 07:37:18 +08:00
|
|
|
|
static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2019-12-11 07:37:18 +08:00
|
|
|
|
/* Here we enter the code section where we use the global variables for
|
|
|
|
|
parsing and code generation (tccpp.c, tccgen.c, <target>-gen.c).
|
|
|
|
|
Other threads need to wait until we're done.
|
|
|
|
|
|
|
|
|
|
Alternatively we could use thread local storage for those global
|
|
|
|
|
variables, which may or may not have advantages */
|
|
|
|
|
|
|
|
|
|
WAIT_SEM();
|
|
|
|
|
tcc_state = s1;
|
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
if (setjmp(s1->error_jmp_buf) == 0) {
|
2019-12-11 07:37:18 +08:00
|
|
|
|
int is_asm;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
s1->error_set_jmp_enabled = 1;
|
2019-12-11 07:37:18 +08:00
|
|
|
|
s1->nb_errors = 0;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
|
if (fd == -1) {
|
|
|
|
|
int len = strlen(str);
|
|
|
|
|
tcc_open_bf(s1, "<string>", len);
|
|
|
|
|
memcpy(file->buffer, str, len);
|
|
|
|
|
} else {
|
|
|
|
|
tcc_open_bf(s1, str, 0);
|
|
|
|
|
file->fd = fd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
is_asm = !!(filetype & (AFF_TYPE_ASM|AFF_TYPE_ASMPP));
|
2019-12-14 19:31:03 +08:00
|
|
|
|
tccelf_begin_file(s1);
|
2017-07-21 04:21:27 +08:00
|
|
|
|
preprocess_start(s1, is_asm);
|
2019-12-14 19:31:03 +08:00
|
|
|
|
tccgen_init(s1);
|
2017-07-21 04:21:27 +08:00
|
|
|
|
if (s1->output_type == TCC_OUTPUT_PREPROCESS) {
|
|
|
|
|
tcc_preprocess(s1);
|
|
|
|
|
} else if (is_asm) {
|
|
|
|
|
#ifdef CONFIG_TCC_ASM
|
2018-06-01 05:51:59 +08:00
|
|
|
|
tcc_assemble(s1, !!(filetype & AFF_TYPE_ASMPP));
|
2017-07-21 04:21:27 +08:00
|
|
|
|
#else
|
|
|
|
|
tcc_error_noabort("asm not supported");
|
2016-10-15 21:55:31 +08:00
|
|
|
|
#endif
|
2017-07-21 04:21:27 +08:00
|
|
|
|
} else {
|
|
|
|
|
tccgen_compile(s1);
|
|
|
|
|
}
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
s1->error_set_jmp_enabled = 0;
|
2019-12-14 19:31:03 +08:00
|
|
|
|
tccgen_finish(s1);
|
2017-07-21 04:21:27 +08:00
|
|
|
|
preprocess_end(s1);
|
2019-12-14 19:31:03 +08:00
|
|
|
|
tccelf_end_file(s1);
|
2019-12-11 07:37:18 +08:00
|
|
|
|
|
|
|
|
|
tcc_state = NULL;
|
|
|
|
|
POST_SEM();
|
2009-05-06 02:18:53 +08:00
|
|
|
|
return s1->nb_errors != 0 ? -1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-15 00:34:07 +08:00
|
|
|
|
LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2019-12-11 07:37:18 +08:00
|
|
|
|
return tcc_compile(s, s->filetype, str, -1);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* define a preprocessor symbol. A value can also be provided with the '=' operator */
|
2009-12-20 08:53:49 +08:00
|
|
|
|
LIBTCCAPI void tcc_define_symbol(TCCState *s1, const char *sym, const char *value)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2010-11-25 20:29:15 +08:00
|
|
|
|
if (!value)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
value = "1";
|
2019-12-11 07:37:18 +08:00
|
|
|
|
cstr_printf(&s1->cmdline_defs, "#define %s %s\n", sym, value);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* undefine a preprocessor symbol */
|
2009-12-20 08:53:49 +08:00
|
|
|
|
LIBTCCAPI void tcc_undefine_symbol(TCCState *s1, const char *sym)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2019-12-11 07:37:18 +08:00
|
|
|
|
cstr_printf(&s1->cmdline_defs, "#undef %s\n", sym);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
|
LIBTCCAPI TCCState *tcc_new(void)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
TCCState *s;
|
2016-10-18 05:24:01 +08:00
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
s = tcc_mallocz(sizeof(TCCState));
|
|
|
|
|
if (!s)
|
|
|
|
|
return NULL;
|
2019-12-14 19:31:03 +08:00
|
|
|
|
#ifdef MEM_DEBUG
|
2017-02-14 01:23:55 +08:00
|
|
|
|
++nb_states;
|
2019-12-14 19:31:03 +08:00
|
|
|
|
#endif
|
2016-10-15 21:55:31 +08:00
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
|
#undef gnu_ext
|
|
|
|
|
|
|
|
|
|
s->gnu_ext = 1;
|
|
|
|
|
s->tcc_ext = 1;
|
2016-10-15 21:55:31 +08:00
|
|
|
|
s->nocommon = 1;
|
2019-06-11 19:45:22 +08:00
|
|
|
|
s->dollars_in_identifiers = 1; /*on by default like in gcc/clang*/
|
2019-01-10 21:41:54 +08:00
|
|
|
|
s->cversion = 199901; /* default unless -std=c11 is supplied */
|
2016-10-15 21:55:31 +08:00
|
|
|
|
s->warn_implicit_function_declaration = 1;
|
2017-07-09 18:07:40 +08:00
|
|
|
|
s->ms_extensions = 1;
|
2016-10-15 21:55:31 +08:00
|
|
|
|
|
|
|
|
|
#ifdef CHAR_IS_UNSIGNED
|
|
|
|
|
s->char_is_unsigned = 1;
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef TCC_TARGET_I386
|
|
|
|
|
s->seg_size = 32;
|
|
|
|
|
#endif
|
|
|
|
|
/* enable this if you want symbols with leading underscore on windows: */
|
|
|
|
|
#if 0 /* def TCC_TARGET_PE */
|
|
|
|
|
s->leading_underscore = 1;
|
2019-12-11 07:37:18 +08:00
|
|
|
|
#endif
|
|
|
|
|
s->ppfp = stdout;
|
|
|
|
|
/* might be used in error() before preprocess_start() */
|
|
|
|
|
s->include_stack_ptr = s->include_stack;
|
|
|
|
|
|
|
|
|
|
tccelf_new(s);
|
|
|
|
|
|
2009-07-19 04:07:33 +08:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
tcc_set_lib_path_w32(s);
|
|
|
|
|
#else
|
|
|
|
|
tcc_set_lib_path(s, CONFIG_TCCDIR);
|
|
|
|
|
#endif
|
2019-12-11 07:37:18 +08:00
|
|
|
|
|
2016-10-15 21:55:31 +08:00
|
|
|
|
{
|
|
|
|
|
/* define __TINYC__ 92X */
|
|
|
|
|
char buffer[32]; int a,b,c;
|
|
|
|
|
sscanf(TCC_VERSION, "%d.%d.%d", &a, &b, &c);
|
|
|
|
|
sprintf(buffer, "%d", a*10000 + b*100 + c);
|
|
|
|
|
tcc_define_symbol(s, "__TINYC__", buffer);
|
|
|
|
|
}
|
2013-02-13 02:13:28 +08:00
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
/* standard defines */
|
|
|
|
|
tcc_define_symbol(s, "__STDC__", NULL);
|
|
|
|
|
tcc_define_symbol(s, "__STDC_VERSION__", "199901L");
|
2013-02-18 22:44:18 +08:00
|
|
|
|
tcc_define_symbol(s, "__STDC_HOSTED__", NULL);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
|
|
|
|
|
/* target defines */
|
2009-05-06 02:18:53 +08:00
|
|
|
|
#if defined(TCC_TARGET_I386)
|
2010-01-15 03:56:35 +08:00
|
|
|
|
tcc_define_symbol(s, "__i386__", NULL);
|
|
|
|
|
tcc_define_symbol(s, "__i386", NULL);
|
|
|
|
|
tcc_define_symbol(s, "i386", NULL);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
#elif defined(TCC_TARGET_X86_64)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
tcc_define_symbol(s, "__x86_64__", NULL);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
#elif defined(TCC_TARGET_ARM)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
tcc_define_symbol(s, "__ARM_ARCH_4__", NULL);
|
|
|
|
|
tcc_define_symbol(s, "__arm_elf__", NULL);
|
|
|
|
|
tcc_define_symbol(s, "__arm_elf", NULL);
|
|
|
|
|
tcc_define_symbol(s, "arm_elf", NULL);
|
|
|
|
|
tcc_define_symbol(s, "__arm__", NULL);
|
|
|
|
|
tcc_define_symbol(s, "__arm", NULL);
|
|
|
|
|
tcc_define_symbol(s, "arm", NULL);
|
|
|
|
|
tcc_define_symbol(s, "__APCS_32__", NULL);
|
2013-11-26 12:06:21 +08:00
|
|
|
|
tcc_define_symbol(s, "__ARMEL__", NULL);
|
|
|
|
|
#if defined(TCC_ARM_EABI)
|
|
|
|
|
tcc_define_symbol(s, "__ARM_EABI__", NULL);
|
2014-01-07 15:23:54 +08:00
|
|
|
|
#endif
|
2013-06-12 00:13:04 +08:00
|
|
|
|
#if defined(TCC_ARM_HARDFLOAT)
|
2014-01-07 15:23:54 +08:00
|
|
|
|
s->float_abi = ARM_HARD_FLOAT;
|
2013-06-12 00:13:04 +08:00
|
|
|
|
tcc_define_symbol(s, "__ARM_PCS_VFP", NULL);
|
2014-01-07 15:23:54 +08:00
|
|
|
|
#else
|
|
|
|
|
s->float_abi = ARM_SOFTFP_FLOAT;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
#endif
|
2015-02-14 02:58:31 +08:00
|
|
|
|
#elif defined(TCC_TARGET_ARM64)
|
|
|
|
|
tcc_define_symbol(s, "__aarch64__", NULL);
|
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
|
|
|
|
#elif defined TCC_TARGET_C67
|
|
|
|
|
tcc_define_symbol(s, "__C67__", NULL);
|
2019-06-24 08:34:46 +08:00
|
|
|
|
#elif defined TCC_TARGET_RISCV64
|
|
|
|
|
tcc_define_symbol(s, "__riscv", NULL);
|
|
|
|
|
tcc_define_symbol(s, "__riscv_xlen", "64");
|
2019-07-16 03:50:07 +08:00
|
|
|
|
tcc_define_symbol(s, "__riscv_flen", "64");
|
|
|
|
|
tcc_define_symbol(s, "__riscv_div", NULL);
|
|
|
|
|
tcc_define_symbol(s, "__riscv_mul", NULL);
|
|
|
|
|
tcc_define_symbol(s, "__riscv_fdiv", NULL);
|
|
|
|
|
tcc_define_symbol(s, "__riscv_fsqrt", NULL);
|
|
|
|
|
tcc_define_symbol(s, "__riscv_float_abi_double", NULL);
|
2013-11-26 12:06:21 +08:00
|
|
|
|
#endif
|
2013-02-13 02:13:28 +08:00
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
|
tcc_define_symbol(s, "_WIN32", NULL);
|
2019-12-17 05:34:47 +08:00
|
|
|
|
tcc_define_symbol(s, "__declspec(x)", "__attribute__((x))");
|
|
|
|
|
tcc_define_symbol(s, "__cdecl", "");
|
2013-02-13 02:13:28 +08:00
|
|
|
|
# ifdef TCC_TARGET_X86_64
|
2009-07-19 04:05:27 +08:00
|
|
|
|
tcc_define_symbol(s, "_WIN64", NULL);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
# endif
|
2009-05-06 02:18:53 +08:00
|
|
|
|
#else
|
2010-01-15 03:56:35 +08:00
|
|
|
|
tcc_define_symbol(s, "__unix__", NULL);
|
|
|
|
|
tcc_define_symbol(s, "__unix", NULL);
|
|
|
|
|
tcc_define_symbol(s, "unix", NULL);
|
2016-04-15 22:41:49 +08:00
|
|
|
|
# if defined(__linux__)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
tcc_define_symbol(s, "__linux__", NULL);
|
|
|
|
|
tcc_define_symbol(s, "__linux", NULL);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
# endif
|
|
|
|
|
# if defined(__FreeBSD__)
|
2016-05-05 20:12:53 +08:00
|
|
|
|
tcc_define_symbol(s, "__FreeBSD__", "__FreeBSD__");
|
2016-10-16 00:47:31 +08:00
|
|
|
|
/* No 'Thread Storage Local' on FreeBSD with tcc */
|
|
|
|
|
tcc_define_symbol(s, "__NO_TLS", NULL);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
# endif
|
|
|
|
|
# if defined(__FreeBSD_kernel__)
|
|
|
|
|
tcc_define_symbol(s, "__FreeBSD_kernel__", NULL);
|
|
|
|
|
# endif
|
2015-10-11 09:12:35 +08:00
|
|
|
|
# if defined(__NetBSD__)
|
2016-05-05 20:12:53 +08:00
|
|
|
|
tcc_define_symbol(s, "__NetBSD__", "__NetBSD__");
|
2015-10-11 09:12:35 +08:00
|
|
|
|
# endif
|
2016-10-15 21:08:44 +08:00
|
|
|
|
# if defined(__OpenBSD__)
|
|
|
|
|
tcc_define_symbol(s, "__OpenBSD__", "__OpenBSD__");
|
|
|
|
|
# endif
|
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
|
|
|
|
#endif
|
2009-05-06 02:18:53 +08:00
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
|
/* TinyCC & gcc defines */
|
2017-09-25 00:57:48 +08:00
|
|
|
|
#if PTR_SIZE == 4
|
|
|
|
|
/* 32bit systems. */
|
|
|
|
|
tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned int");
|
|
|
|
|
tcc_define_symbol(s, "__PTRDIFF_TYPE__", "int");
|
|
|
|
|
tcc_define_symbol(s, "__ILP32__", NULL);
|
|
|
|
|
#elif LONG_SIZE == 4
|
2016-09-25 18:03:23 +08:00
|
|
|
|
/* 64bit Windows. */
|
2010-01-15 03:56:35 +08:00
|
|
|
|
tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned long long");
|
|
|
|
|
tcc_define_symbol(s, "__PTRDIFF_TYPE__", "long long");
|
2016-05-16 02:07:05 +08:00
|
|
|
|
tcc_define_symbol(s, "__LLP64__", NULL);
|
2017-09-25 00:57:48 +08:00
|
|
|
|
#else
|
2016-09-25 18:03:23 +08:00
|
|
|
|
/* Other 64bit systems. */
|
2009-07-19 03:26:19 +08:00
|
|
|
|
tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned long");
|
|
|
|
|
tcc_define_symbol(s, "__PTRDIFF_TYPE__", "long");
|
2016-05-16 02:07:05 +08:00
|
|
|
|
tcc_define_symbol(s, "__LP64__", NULL);
|
2010-01-15 03:56:35 +08:00
|
|
|
|
#endif
|
2019-06-24 08:34:46 +08:00
|
|
|
|
tcc_define_symbol(s, "__SIZEOF_POINTER__", PTR_SIZE == 4 ? "4" : "8");
|
2010-01-15 03:56:35 +08:00
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
|
tcc_define_symbol(s, "__WCHAR_TYPE__", "unsigned short");
|
2014-04-07 06:26:36 +08:00
|
|
|
|
tcc_define_symbol(s, "__WINT_TYPE__", "unsigned short");
|
2009-05-06 02:18:53 +08:00
|
|
|
|
#else
|
|
|
|
|
tcc_define_symbol(s, "__WCHAR_TYPE__", "int");
|
2014-04-07 06:26:36 +08:00
|
|
|
|
/* wint_t is unsigned int by default, but (signed) int on BSDs
|
|
|
|
|
and unsigned short on windows. Other OSes might have still
|
|
|
|
|
other conventions, sigh. */
|
2016-10-16 00:13:01 +08:00
|
|
|
|
# if defined(__FreeBSD__) || defined (__FreeBSD_kernel__) \
|
2016-10-15 22:01:16 +08:00
|
|
|
|
|| defined(__NetBSD__) || defined(__OpenBSD__)
|
2014-04-07 06:26:36 +08:00
|
|
|
|
tcc_define_symbol(s, "__WINT_TYPE__", "int");
|
2016-10-17 07:08:29 +08:00
|
|
|
|
# ifdef __FreeBSD__
|
|
|
|
|
/* define __GNUC__ to have some useful stuff from sys/cdefs.h
|
|
|
|
|
that are unconditionally used in FreeBSDs other system headers :/ */
|
|
|
|
|
tcc_define_symbol(s, "__GNUC__", "2");
|
2016-10-18 05:24:01 +08:00
|
|
|
|
tcc_define_symbol(s, "__GNUC_MINOR__", "7");
|
2016-10-17 07:08:29 +08:00
|
|
|
|
tcc_define_symbol(s, "__builtin_alloca", "alloca");
|
|
|
|
|
# endif
|
2016-10-15 22:01:16 +08:00
|
|
|
|
# else
|
2014-04-07 06:26:36 +08:00
|
|
|
|
tcc_define_symbol(s, "__WINT_TYPE__", "unsigned int");
|
2010-09-11 23:57:15 +08:00
|
|
|
|
/* glibc defines */
|
2016-10-15 22:01:16 +08:00
|
|
|
|
tcc_define_symbol(s, "__REDIRECT(name, proto, alias)",
|
|
|
|
|
"name proto __asm__ (#alias)");
|
|
|
|
|
tcc_define_symbol(s, "__REDIRECT_NTH(name, proto, alias)",
|
|
|
|
|
"name proto __asm__ (#alias) __THROW");
|
|
|
|
|
# endif
|
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_MUSL)
|
|
|
|
|
tcc_define_symbol(s, "__DEFINED_va_list", "");
|
|
|
|
|
tcc_define_symbol(s, "__DEFINED___isoc_va_list", "");
|
|
|
|
|
tcc_define_symbol(s, "__isoc_va_list", "void *");
|
|
|
|
|
# endif /* TCC_MUSL */
|
2016-09-27 03:52:57 +08:00
|
|
|
|
/* Some GCC builtins that are simple to express as macros. */
|
|
|
|
|
tcc_define_symbol(s, "__builtin_extract_return_addr(x)", "x");
|
2017-02-18 16:55:34 +08:00
|
|
|
|
#endif /* ndef TCC_TARGET_PE */
|
2009-05-06 02:18:53 +08:00
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
|
LIBTCCAPI void tcc_delete(TCCState *s1)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2016-10-15 21:55:31 +08:00
|
|
|
|
/* free sections */
|
|
|
|
|
tccelf_delete(s1);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
|
|
|
|
|
/* free library paths */
|
|
|
|
|
dynarray_reset(&s1->library_paths, &s1->nb_library_paths);
|
2011-08-06 22:49:30 +08:00
|
|
|
|
dynarray_reset(&s1->crt_paths, &s1->nb_crt_paths);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
|
|
|
|
|
/* free include paths */
|
|
|
|
|
dynarray_reset(&s1->include_paths, &s1->nb_include_paths);
|
|
|
|
|
dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
|
|
|
|
|
|
2011-08-06 22:08:46 +08:00
|
|
|
|
tcc_free(s1->tcc_lib_path);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
tcc_free(s1->soname);
|
|
|
|
|
tcc_free(s1->rpath);
|
|
|
|
|
tcc_free(s1->init_symbol);
|
|
|
|
|
tcc_free(s1->fini_symbol);
|
|
|
|
|
tcc_free(s1->outfile);
|
|
|
|
|
tcc_free(s1->deps_outfile);
|
|
|
|
|
dynarray_reset(&s1->files, &s1->nb_files);
|
|
|
|
|
dynarray_reset(&s1->target_deps, &s1->nb_target_deps);
|
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
|
|
|
|
dynarray_reset(&s1->pragma_libs, &s1->nb_pragma_libs);
|
2017-02-18 16:55:34 +08:00
|
|
|
|
dynarray_reset(&s1->argv, &s1->argc);
|
2011-08-06 22:08:46 +08:00
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
|
cstr_free(&s1->cmdline_defs);
|
|
|
|
|
cstr_free(&s1->cmdline_incl);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
#ifdef TCC_IS_NATIVE
|
2016-10-20 01:21:27 +08:00
|
|
|
|
/* free runtime memory */
|
|
|
|
|
tcc_run_free(s1);
|
2010-04-24 18:28:54 +08:00
|
|
|
|
#endif
|
2013-02-13 02:13:28 +08:00
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
tcc_free(s1);
|
2019-12-14 19:31:03 +08:00
|
|
|
|
#ifdef MEM_DEBUG
|
2017-02-14 01:23:55 +08:00
|
|
|
|
if (0 == --nb_states)
|
2017-02-18 16:55:34 +08:00
|
|
|
|
tcc_memcheck();
|
2019-12-14 19:31:03 +08:00
|
|
|
|
#endif
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-15 21:55:31 +08:00
|
|
|
|
LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
|
|
|
|
|
{
|
|
|
|
|
s->output_type = output_type;
|
|
|
|
|
|
|
|
|
|
/* always elf for objects */
|
|
|
|
|
if (output_type == TCC_OUTPUT_OBJ)
|
|
|
|
|
s->output_format = TCC_OUTPUT_FORMAT_ELF;
|
|
|
|
|
|
|
|
|
|
if (s->char_is_unsigned)
|
|
|
|
|
tcc_define_symbol(s, "__CHAR_UNSIGNED__", NULL);
|
|
|
|
|
|
|
|
|
|
if (!s->nostdinc) {
|
|
|
|
|
/* default include paths */
|
|
|
|
|
/* -isystem paths have already been handled */
|
|
|
|
|
tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
|
|
|
|
if (s->do_bounds_check) {
|
2016-10-18 05:24:01 +08:00
|
|
|
|
/* if bound checking, then add corresponding sections */
|
|
|
|
|
tccelf_bounds_new(s);
|
2016-10-15 21:55:31 +08:00
|
|
|
|
/* define symbol */
|
|
|
|
|
tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
if (s->do_debug) {
|
2016-10-18 05:24:01 +08:00
|
|
|
|
/* add debug sections */
|
|
|
|
|
tccelf_stab_new(s);
|
2016-10-15 21:55:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
|
|
|
|
|
|
|
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
|
# ifdef _WIN32
|
|
|
|
|
if (!s->nostdlib && output_type != TCC_OUTPUT_OBJ)
|
|
|
|
|
tcc_add_systemdir(s);
|
|
|
|
|
# endif
|
|
|
|
|
#else
|
|
|
|
|
/* paths for crt objects */
|
2017-02-18 16:55:34 +08:00
|
|
|
|
tcc_split_path(s, &s->crt_paths, &s->nb_crt_paths, CONFIG_TCC_CRTPREFIX);
|
2016-10-15 21:55:31 +08:00
|
|
|
|
/* add libc crt1/crti objects */
|
|
|
|
|
if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) &&
|
|
|
|
|
!s->nostdlib) {
|
|
|
|
|
if (output_type != TCC_OUTPUT_DLL)
|
|
|
|
|
tcc_add_crt(s, "crt1.o");
|
|
|
|
|
tcc_add_crt(s, "crti.o");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-01 07:10:36 +08:00
|
|
|
|
LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2017-02-18 16:55:34 +08:00
|
|
|
|
tcc_split_path(s, &s->include_paths, &s->nb_include_paths, pathname);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-01 07:10:36 +08:00
|
|
|
|
LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2017-02-18 16:55:34 +08:00
|
|
|
|
tcc_split_path(s, &s->sysinclude_paths, &s->nb_sysinclude_paths, pathname);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 02:46:16 +08:00
|
|
|
|
ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2019-12-11 07:37:18 +08:00
|
|
|
|
int fd, ret;
|
2009-07-19 04:07:25 +08:00
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
/* open the file */
|
2019-12-11 07:37:18 +08:00
|
|
|
|
fd = _tcc_open(s1, filename);
|
|
|
|
|
if (fd < 0) {
|
2009-07-19 04:07:25 +08:00
|
|
|
|
if (flags & AFF_PRINT_ERROR)
|
2011-08-11 23:07:56 +08:00
|
|
|
|
tcc_error_noabort("file '%s' not found", filename);
|
2019-12-11 07:37:18 +08:00
|
|
|
|
return -1;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
tcc: Draft suppoprt for -MD/-MF options
In build systems, this is used to automatically collect target
dependencies, e.g.
---- 8< (hello.c) ----
#include "hello.h"
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
$ tcc -MD -c hello.c # -> hello.o, hello.d
$ cat hello.d
hello.o : \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
NOTE: gcc supports -MD only for .c -> .o, but in tcc, we generate
dependencies for whatever action is being taken. E.g. for .c -> exe, the
result will be:
$ tcc -MD -o hello hello.c # -> hello, hello.d
hello: \
/usr/lib/crt1.o \
/usr/lib/crti.o \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
/usr/lib/libc.so \
/lib/libc.so.6 \
/usr/lib/ld-linux.so.2 \
/lib/ld-linux.so.2 \
/usr/lib/libc_nonshared.a \
/lib/libc.so.6 \
/usr/lib/libc_nonshared.a \
/home/kirr/local/tcc/lib/tcc/libtcc1.a \
/usr/lib/crtn.o \
So tcc dependency generator is a bit more clever than one used in gcc :)
Also, I've updated TODO and Changelog (in not-yet-released section).
v2:
(Taking inputs from grischka and me myself)
- put code to generate deps file into a function.
- used tcc_fileextension() instead of open-coding
- generate deps only when compilation/preprocessing was successful
v3:
- use pstrcpy instead of snprintf(buf, sizeof(buf), "%s", ...)
2010-06-21 00:08:12 +08:00
|
|
|
|
/* update target deps */
|
2017-02-14 01:23:43 +08:00
|
|
|
|
dynarray_add(&s1->target_deps, &s1->nb_target_deps,
|
tcc: Draft suppoprt for -MD/-MF options
In build systems, this is used to automatically collect target
dependencies, e.g.
---- 8< (hello.c) ----
#include "hello.h"
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
$ tcc -MD -c hello.c # -> hello.o, hello.d
$ cat hello.d
hello.o : \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
NOTE: gcc supports -MD only for .c -> .o, but in tcc, we generate
dependencies for whatever action is being taken. E.g. for .c -> exe, the
result will be:
$ tcc -MD -o hello hello.c # -> hello, hello.d
hello: \
/usr/lib/crt1.o \
/usr/lib/crti.o \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
/usr/lib/libc.so \
/lib/libc.so.6 \
/usr/lib/ld-linux.so.2 \
/lib/ld-linux.so.2 \
/usr/lib/libc_nonshared.a \
/lib/libc.so.6 \
/usr/lib/libc_nonshared.a \
/home/kirr/local/tcc/lib/tcc/libtcc1.a \
/usr/lib/crtn.o \
So tcc dependency generator is a bit more clever than one used in gcc :)
Also, I've updated TODO and Changelog (in not-yet-released section).
v2:
(Taking inputs from grischka and me myself)
- put code to generate deps file into a function.
- used tcc_fileextension() instead of open-coding
- generate deps only when compilation/preprocessing was successful
v3:
- use pstrcpy instead of snprintf(buf, sizeof(buf), "%s", ...)
2010-06-21 00:08:12 +08:00
|
|
|
|
tcc_strdup(filename));
|
|
|
|
|
|
2017-07-21 04:21:27 +08:00
|
|
|
|
if (flags & AFF_TYPE_BIN) {
|
2016-10-02 02:54:45 +08:00
|
|
|
|
ElfW(Ehdr) ehdr;
|
2019-12-11 07:37:18 +08:00
|
|
|
|
int obj_type;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
|
2016-10-02 02:54:45 +08:00
|
|
|
|
obj_type = tcc_object_type(fd, &ehdr);
|
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
2009-07-19 04:07:25 +08:00
|
|
|
|
|
2017-04-26 03:01:54 +08:00
|
|
|
|
#ifdef TCC_TARGET_MACHO
|
2017-10-19 13:55:42 +08:00
|
|
|
|
if (0 == obj_type && 0 == strcmp(tcc_fileextension(filename), ".dylib"))
|
2017-04-26 03:01:54 +08:00
|
|
|
|
obj_type = AFF_BINTYPE_DYN;
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-10-02 02:54:45 +08:00
|
|
|
|
switch (obj_type) {
|
|
|
|
|
case AFF_BINTYPE_REL:
|
|
|
|
|
ret = tcc_load_object_file(s1, fd, 0);
|
|
|
|
|
break;
|
2009-07-19 04:07:25 +08:00
|
|
|
|
#ifndef TCC_TARGET_PE
|
2016-10-02 02:54:45 +08:00
|
|
|
|
case AFF_BINTYPE_DYN:
|
2009-07-19 04:07:25 +08:00
|
|
|
|
if (s1->output_type == TCC_OUTPUT_MEMORY) {
|
2016-10-02 02:54:45 +08:00
|
|
|
|
ret = 0;
|
2013-02-07 02:01:07 +08:00
|
|
|
|
#ifdef TCC_IS_NATIVE
|
2016-10-02 02:54:45 +08:00
|
|
|
|
if (NULL == dlopen(filename, RTLD_GLOBAL | RTLD_LAZY))
|
|
|
|
|
ret = -1;
|
2013-02-07 02:01:07 +08:00
|
|
|
|
#endif
|
2009-05-06 02:18:53 +08:00
|
|
|
|
} else {
|
2013-11-09 03:24:15 +08:00
|
|
|
|
ret = tcc_load_dll(s1, fd, filename,
|
2009-07-19 04:07:25 +08:00
|
|
|
|
(flags & AFF_REFERENCED_DLL) != 0);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
2016-10-02 02:54:45 +08:00
|
|
|
|
break;
|
2009-07-19 04:07:25 +08:00
|
|
|
|
#endif
|
2016-10-02 02:54:45 +08:00
|
|
|
|
case AFF_BINTYPE_AR:
|
2018-06-01 05:51:59 +08:00
|
|
|
|
ret = tcc_load_archive(s1, fd, !(flags & AFF_WHOLE_ARCHIVE));
|
2016-10-02 02:54:45 +08:00
|
|
|
|
break;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
#ifdef TCC_TARGET_COFF
|
2016-10-02 02:54:45 +08:00
|
|
|
|
case AFF_BINTYPE_C67:
|
|
|
|
|
ret = tcc_load_coff(s1, fd);
|
|
|
|
|
break;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
#endif
|
2016-10-02 02:54:45 +08:00
|
|
|
|
default:
|
2017-04-26 03:01:54 +08:00
|
|
|
|
#ifdef TCC_TARGET_PE
|
2016-10-02 02:54:45 +08:00
|
|
|
|
ret = pe_load_file(s1, filename, fd);
|
2009-07-19 04:07:25 +08:00
|
|
|
|
#else
|
2016-10-02 02:54:45 +08:00
|
|
|
|
/* as GNU ld, consider it is an ld script if not recognized */
|
2019-12-11 07:37:18 +08:00
|
|
|
|
ret = tcc_load_ldscript(s1, fd);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
#endif
|
2016-10-02 02:54:45 +08:00
|
|
|
|
if (ret < 0)
|
|
|
|
|
tcc_error_noabort("unrecognized file type");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-12-11 07:37:18 +08:00
|
|
|
|
close(fd);
|
2017-07-21 04:21:27 +08:00
|
|
|
|
} else {
|
2019-12-11 07:37:18 +08:00
|
|
|
|
ret = tcc_compile(s1, flags, filename, fd);
|
2016-10-02 02:54:45 +08:00
|
|
|
|
}
|
2009-05-06 02:18:53 +08:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 02:46:16 +08:00
|
|
|
|
LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2017-07-21 04:21:27 +08:00
|
|
|
|
int filetype = s->filetype;
|
2018-06-01 05:51:59 +08:00
|
|
|
|
if (0 == (filetype & AFF_TYPE_MASK)) {
|
2017-07-21 04:21:27 +08:00
|
|
|
|
/* use a file extension to detect a filetype */
|
|
|
|
|
const char *ext = tcc_fileextension(filename);
|
|
|
|
|
if (ext[0]) {
|
|
|
|
|
ext++;
|
|
|
|
|
if (!strcmp(ext, "S"))
|
|
|
|
|
filetype = AFF_TYPE_ASMPP;
|
|
|
|
|
else if (!strcmp(ext, "s"))
|
|
|
|
|
filetype = AFF_TYPE_ASM;
|
|
|
|
|
else if (!PATHCMP(ext, "c") || !PATHCMP(ext, "i"))
|
|
|
|
|
filetype = AFF_TYPE_C;
|
|
|
|
|
else
|
2018-06-01 05:51:59 +08:00
|
|
|
|
filetype |= AFF_TYPE_BIN;
|
2017-07-21 04:21:27 +08:00
|
|
|
|
} else {
|
|
|
|
|
filetype = AFF_TYPE_C;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-01 05:51:59 +08:00
|
|
|
|
return tcc_add_file_internal(s, filename, filetype | AFF_PRINT_ERROR);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2009-12-20 08:53:49 +08:00
|
|
|
|
LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2017-02-18 16:55:34 +08:00
|
|
|
|
tcc_split_path(s, &s->library_paths, &s->nb_library_paths, pathname);
|
2009-05-06 02:18:53 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-06 22:49:30 +08:00
|
|
|
|
static int tcc_add_library_internal(TCCState *s, const char *fmt,
|
|
|
|
|
const char *filename, int flags, char **paths, int nb_paths)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
|
|
|
|
char buf[1024];
|
|
|
|
|
int i;
|
|
|
|
|
|
2011-08-06 22:49:30 +08:00
|
|
|
|
for(i = 0; i < nb_paths; i++) {
|
|
|
|
|
snprintf(buf, sizeof(buf), fmt, paths[i], filename);
|
2016-10-02 02:46:16 +08:00
|
|
|
|
if (tcc_add_file_internal(s, buf, flags | AFF_TYPE_BIN) == 0)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-06 22:49:30 +08:00
|
|
|
|
/* find and load a dll. Return non zero if not found */
|
|
|
|
|
/* XXX: add '-rpath' option support ? */
|
|
|
|
|
ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags)
|
|
|
|
|
{
|
|
|
|
|
return tcc_add_library_internal(s, "%s/%s", filename, flags,
|
|
|
|
|
s->library_paths, s->nb_library_paths);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-08 21:31:40 +08:00
|
|
|
|
#ifndef TCC_TARGET_PE
|
2019-12-11 07:37:18 +08:00
|
|
|
|
ST_FUNC int tcc_add_crt(TCCState *s1, const char *filename)
|
2011-08-06 22:49:30 +08:00
|
|
|
|
{
|
2019-12-11 07:37:18 +08:00
|
|
|
|
if (-1 == tcc_add_library_internal(s1, "%s/%s",
|
|
|
|
|
filename, 0, s1->crt_paths, s1->nb_crt_paths))
|
2011-08-11 23:07:56 +08:00
|
|
|
|
tcc_error_noabort("file '%s' not found", filename);
|
2011-08-06 22:49:30 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2018-06-08 21:31:40 +08:00
|
|
|
|
#endif
|
2011-08-06 22:49:30 +08:00
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
/* the library name is the same as the argument of the '-l' option */
|
2009-12-20 08:53:49 +08:00
|
|
|
|
LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2017-04-26 03:01:54 +08:00
|
|
|
|
#if defined TCC_TARGET_PE
|
2011-08-06 22:49:30 +08:00
|
|
|
|
const char *libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL };
|
|
|
|
|
const char **pp = s->static_link ? libs + 4 : libs;
|
2017-04-26 03:01:54 +08:00
|
|
|
|
#elif defined TCC_TARGET_MACHO
|
|
|
|
|
const char *libs[] = { "%s/lib%s.dylib", "%s/lib%s.a", NULL };
|
|
|
|
|
const char **pp = s->static_link ? libs + 1 : libs;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
#else
|
2011-08-06 22:49:30 +08:00
|
|
|
|
const char *libs[] = { "%s/lib%s.so", "%s/lib%s.a", NULL };
|
|
|
|
|
const char **pp = s->static_link ? libs + 1 : libs;
|
2009-07-19 04:07:25 +08:00
|
|
|
|
#endif
|
2018-06-01 05:51:59 +08:00
|
|
|
|
int flags = s->filetype & AFF_WHOLE_ARCHIVE;
|
2011-08-06 22:49:30 +08:00
|
|
|
|
while (*pp) {
|
|
|
|
|
if (0 == tcc_add_library_internal(s, *pp,
|
2018-06-01 05:51:59 +08:00
|
|
|
|
libraryname, flags, s->library_paths, s->nb_library_paths))
|
2009-05-06 02:18:53 +08:00
|
|
|
|
return 0;
|
2011-08-06 22:49:30 +08:00
|
|
|
|
++pp;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
|
PUB_FUNC int tcc_add_library_err(TCCState *s1, const char *libname)
|
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
|
|
|
|
{
|
2019-12-11 07:37:18 +08:00
|
|
|
|
int ret = tcc_add_library(s1, libname);
|
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
|
|
|
|
if (ret < 0)
|
2017-02-09 02:49:28 +08:00
|
|
|
|
tcc_error_noabort("library '%s' not found", libname);
|
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
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-08 12:38:09 +08:00
|
|
|
|
/* handle #pragma comment(lib,) */
|
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
|
|
|
|
ST_FUNC void tcc_add_pragma_libs(TCCState *s1)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < s1->nb_pragma_libs; i++)
|
|
|
|
|
tcc_add_library_err(s1, s1->pragma_libs[i]);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 07:37:18 +08:00
|
|
|
|
LIBTCCAPI int tcc_add_symbol(TCCState *s1, const char *name, const void *val)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2010-01-15 03:55:51 +08:00
|
|
|
|
#ifdef TCC_TARGET_PE
|
2013-02-13 02:13:28 +08:00
|
|
|
|
/* On x86_64 'val' might not be reachable with a 32bit offset.
|
|
|
|
|
So it is handled here as if it were in a DLL. */
|
2019-12-11 07:37:18 +08:00
|
|
|
|
pe_putimport(s1, 0, name, (uintptr_t)val);
|
2010-01-15 03:55:51 +08:00
|
|
|
|
#else
|
2016-11-12 23:16:04 +08:00
|
|
|
|
set_elf_sym(symtab_section, (uintptr_t)val, 0,
|
2013-02-13 02:13:28 +08:00
|
|
|
|
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
|
|
|
|
|
SHN_ABS, name);
|
2010-01-15 03:55:51 +08:00
|
|
|
|
#endif
|
2009-05-06 02:18:53 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
|
LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path)
|
|
|
|
|
{
|
|
|
|
|
tcc_free(s->tcc_lib_path);
|
|
|
|
|
s->tcc_lib_path = tcc_strdup(path);
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-06 02:18:53 +08:00
|
|
|
|
#define WD_ALL 0x0001 /* warning is activated when using -Wall */
|
|
|
|
|
#define FD_INVERT 0x0002 /* invert value before storing */
|
|
|
|
|
|
|
|
|
|
typedef struct FlagDef {
|
|
|
|
|
uint16_t offset;
|
|
|
|
|
uint16_t flags;
|
|
|
|
|
const char *name;
|
|
|
|
|
} FlagDef;
|
|
|
|
|
|
2016-10-02 02:54:45 +08:00
|
|
|
|
static int no_flag(const char **pp)
|
|
|
|
|
{
|
|
|
|
|
const char *p = *pp;
|
|
|
|
|
if (*p != 'n' || *++p != 'o' || *++p != '-')
|
|
|
|
|
return 0;
|
|
|
|
|
*pp = p + 1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 05:57:03 +08:00
|
|
|
|
ST_FUNC int set_flag(TCCState *s, const FlagDef *flags, const char *name)
|
2009-05-06 02:18:53 +08:00
|
|
|
|
{
|
2016-12-19 05:57:03 +08:00
|
|
|
|
int value, ret;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
const FlagDef *p;
|
|
|
|
|
const char *r;
|
|
|
|
|
|
2016-12-19 05:57:03 +08:00
|
|
|
|
value = 1;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
r = name;
|
2016-10-02 02:54:45 +08:00
|
|
|
|
if (no_flag(&r))
|
2016-12-19 05:57:03 +08:00
|
|
|
|
value = 0;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
|
2016-12-19 05:57:03 +08:00
|
|
|
|
for (ret = -1, p = flags; p->name; ++p) {
|
|
|
|
|
if (ret) {
|
|
|
|
|
if (strcmp(r, p->name))
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
if (0 == (p->flags & WD_ALL))
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (p->offset) {
|
2019-12-06 00:04:04 +08:00
|
|
|
|
*((unsigned char *)s + p->offset) =
|
2016-12-19 05:57:03 +08:00
|
|
|
|
p->flags & FD_INVERT ? !value : value;
|
|
|
|
|
if (ret)
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
ret = 0;
|
2009-05-06 02:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-19 05:57:03 +08:00
|
|
|
|
return ret;
|
2016-10-03 11:20:21 +08:00
|
|
|
|
}
|
2010-04-06 03:21:58 +08:00
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
|
static int strstart(const char *val, const char **str)
|
2010-04-06 03:21:58 +08:00
|
|
|
|
{
|
|
|
|
|
const char *p, *q;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
p = *str;
|
2010-04-06 03:21:58 +08:00
|
|
|
|
q = val;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
while (*q) {
|
2010-04-06 03:21:58 +08:00
|
|
|
|
if (*p != *q)
|
|
|
|
|
return 0;
|
|
|
|
|
p++;
|
|
|
|
|
q++;
|
|
|
|
|
}
|
2013-02-13 02:13:28 +08:00
|
|
|
|
*str = p;
|
2010-04-06 03:21:58 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-13 03:30:21 +08:00
|
|
|
|
/* Like strstart, but automatically takes into account that ld options can
|
|
|
|
|
*
|
|
|
|
|
* - start with double or single dash (e.g. '--soname' or '-soname')
|
|
|
|
|
* - arguments can be given as separate or after '=' (e.g. '-Wl,-soname,x.so'
|
|
|
|
|
* or '-Wl,-soname=x.so')
|
|
|
|
|
*
|
|
|
|
|
* you provide `val` always in 'option[=]' form (no leading -)
|
|
|
|
|
*/
|
2013-02-13 02:13:28 +08:00
|
|
|
|
static int link_option(const char *str, const char *val, const char **ptr)
|
2010-08-13 03:30:21 +08:00
|
|
|
|
{
|
|
|
|
|
const char *p, *q;
|
2016-10-02 02:54:45 +08:00
|
|
|
|
int ret;
|
2010-08-13 03:30:21 +08:00
|
|
|
|
|
|
|
|
|
/* there should be 1 or 2 dashes */
|
|
|
|
|
if (*str++ != '-')
|
|
|
|
|
return 0;
|
|
|
|
|
if (*str == '-')
|
|
|
|
|
str++;
|
|
|
|
|
|
2017-05-08 12:38:09 +08:00
|
|
|
|
/* then str & val should match (potentially up to '=') */
|
2010-08-13 03:30:21 +08:00
|
|
|
|
p = str;
|
|
|
|
|
q = val;
|
|
|
|
|
|
2016-10-02 02:54:45 +08:00
|
|
|
|
ret = 1;
|
|
|
|
|
if (q[0] == '?') {
|
|
|
|
|
++q;
|
|
|
|
|
if (no_flag(&p))
|
|
|
|
|
ret = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-13 03:30:21 +08:00
|
|
|
|
while (*q != '\0' && *q != '=') {
|
|
|
|
|
if (*p != *q)
|
|
|
|
|
return 0;
|
|
|
|
|
p++;
|
|
|
|
|
q++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* '=' near eos means ',' or '=' is ok */
|
|
|
|
|
if (*q == '=') {
|
2016-10-02 02:49:38 +08:00
|
|
|
|
if (*p == 0)
|
|
|
|
|
*ptr = p;
|
2010-08-13 03:30:21 +08:00
|
|
|
|
if (*p != ',' && *p != '=')
|
|
|
|
|
return 0;
|
|
|
|
|
p++;
|
2017-04-04 14:34:52 +08:00
|
|
|
|
} else if (*p) {
|
|
|
|
|
return 0;
|
2010-08-13 03:30:21 +08:00
|
|
|
|
}
|
2016-10-02 02:49:38 +08:00
|
|
|
|
*ptr = p;
|
2016-10-02 02:54:45 +08:00
|
|
|
|
return ret;
|
2010-08-13 03:30:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
|
static const char *skip_linker_arg(const char **str)
|
|
|
|
|
{
|
|
|
|
|
const char *s1 = *str;
|
|
|
|
|
const char *s2 = strchr(s1, ',');
|
|
|
|
|
*str = s2 ? s2++ : (s2 = s1 + strlen(s1));
|
|
|
|
|
return s2;
|
|
|
|
|
}
|
2010-08-13 03:30:21 +08:00
|
|
|
|
|
2017-02-11 16:54:01 +08:00
|
|
|
|
static void copy_linker_arg(char **pp, const char *s, int sep)
|
2010-04-06 03:21:58 +08:00
|
|
|
|
{
|
2017-02-11 16:54:01 +08:00
|
|
|
|
const char *q = s;
|
|
|
|
|
char *p = *pp;
|
|
|
|
|
int l = 0;
|
|
|
|
|
if (p && sep)
|
|
|
|
|
p[l = strlen(p)] = sep, ++l;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
skip_linker_arg(&q);
|
2017-02-11 16:54:01 +08:00
|
|
|
|
pstrncpy(l + (*pp = tcc_realloc(p, q - s + l + 1)), s, q - s);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
}
|
2010-04-06 03:21:58 +08:00
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
|
/* set linker options */
|
|
|
|
|
static int tcc_set_linker(TCCState *s, const char *option)
|
|
|
|
|
{
|
2019-12-11 07:37:18 +08:00
|
|
|
|
TCCState *s1 = s;
|
2016-10-02 02:49:38 +08:00
|
|
|
|
while (*option) {
|
2013-02-13 02:13:28 +08:00
|
|
|
|
|
2016-10-02 02:49:38 +08:00
|
|
|
|
const char *p = NULL;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
char *end = NULL;
|
|
|
|
|
int ignoring = 0;
|
2016-10-02 02:54:45 +08:00
|
|
|
|
int ret;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
|
2010-08-13 03:30:21 +08:00
|
|
|
|
if (link_option(option, "Bsymbolic", &p)) {
|
2013-02-04 22:10:08 +08:00
|
|
|
|
s->symbolic = 1;
|
2012-04-18 15:48:57 +08:00
|
|
|
|
} else if (link_option(option, "nostdlib", &p)) {
|
2013-02-04 22:10:08 +08:00
|
|
|
|
s->nostdlib = 1;
|
2010-08-13 03:30:21 +08:00
|
|
|
|
} else if (link_option(option, "fini=", &p)) {
|
2017-02-11 16:54:01 +08:00
|
|
|
|
copy_linker_arg(&s->fini_symbol, p, 0);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
ignoring = 1;
|
|
|
|
|
} else if (link_option(option, "image-base=", &p)
|
|
|
|
|
|| link_option(option, "Ttext=", &p)) {
|
2012-03-04 01:10:15 +08:00
|
|
|
|
s->text_addr = strtoull(p, &end, 16);
|
2010-04-06 03:21:58 +08:00
|
|
|
|
s->has_text_addr = 1;
|
2010-08-13 03:30:21 +08:00
|
|
|
|
} else if (link_option(option, "init=", &p)) {
|
2017-02-11 16:54:01 +08:00
|
|
|
|
copy_linker_arg(&s->init_symbol, p, 0);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
ignoring = 1;
|
2010-08-13 03:30:21 +08:00
|
|
|
|
} else if (link_option(option, "oformat=", &p)) {
|
2010-04-06 03:21:58 +08:00
|
|
|
|
#if defined(TCC_TARGET_PE)
|
2013-02-13 02:13:28 +08:00
|
|
|
|
if (strstart("pe-", &p)) {
|
2017-05-13 14:59:06 +08:00
|
|
|
|
#elif PTR_SIZE == 8
|
2013-02-13 02:13:28 +08:00
|
|
|
|
if (strstart("elf64-", &p)) {
|
2010-04-06 03:21:58 +08:00
|
|
|
|
#else
|
2013-02-13 02:13:28 +08:00
|
|
|
|
if (strstart("elf32-", &p)) {
|
2010-04-06 03:21:58 +08:00
|
|
|
|
#endif
|
|
|
|
|
s->output_format = TCC_OUTPUT_FORMAT_ELF;
|
|
|
|
|
} else if (!strcmp(p, "binary")) {
|
|
|
|
|
s->output_format = TCC_OUTPUT_FORMAT_BINARY;
|
|
|
|
|
#ifdef TCC_TARGET_COFF
|
2013-02-13 02:13:28 +08:00
|
|
|
|
} else if (!strcmp(p, "coff")) {
|
2010-04-06 03:21:58 +08:00
|
|
|
|
s->output_format = TCC_OUTPUT_FORMAT_COFF;
|
|
|
|
|
#endif
|
2013-02-13 02:13:28 +08:00
|
|
|
|
} else
|
|
|
|
|
goto err;
|
2010-04-06 03:21:58 +08:00
|
|
|
|
|
2014-03-07 04:29:19 +08:00
|
|
|
|
} else if (link_option(option, "as-needed", &p)) {
|
|
|
|
|
ignoring = 1;
|
|
|
|
|
} else if (link_option(option, "O", &p)) {
|
|
|
|
|
ignoring = 1;
|
2017-04-04 14:34:52 +08:00
|
|
|
|
} else if (link_option(option, "export-all-symbols", &p)) {
|
|
|
|
|
s->rdynamic = 1;
|
2018-06-12 00:15:24 +08:00
|
|
|
|
} else if (link_option(option, "export-dynamic", &p)) {
|
|
|
|
|
s->rdynamic = 1;
|
2010-08-13 03:30:21 +08:00
|
|
|
|
} else if (link_option(option, "rpath=", &p)) {
|
2017-02-11 16:54:01 +08:00
|
|
|
|
copy_linker_arg(&s->rpath, p, ':');
|
-Wl, --enable-new-dtags for DT_RUNPATH instead of DT_RPATH
Today by accident i had to deal with linker problems of some
software and found an issue that mentioned DT_RUNPATH, which
mentioned that DT_RPATH is legacy and searched for
$LD_LIBRARY_PATH, whereas the newer DT_RUNPATH is searched
thereafter. Completely unencrypted! Well. For what's it worth,
i for one am astonished because of course i want to override
$LD_LIBRARY_PATH, but it surely has its merites, smart people came
to the conclusion, did they.
The attached diff below seems to be sufficient to support
DT_RUNPATH instead of DT_RPATH with tcc(1). But i have no insight
in what --enable-new-dtags is supposed to change in addition, so
i wonder.
Ciao!
--steffen
libtcc.c | 2 ++
tcc-doc.texi | 4 ++++
tcc.h | 1 +
tccelf.c | 3 ++-
4 files changed, 9 insertions(+), 1 deletion(-)
2017-02-16 22:49:02 +08:00
|
|
|
|
} else if (link_option(option, "enable-new-dtags", &p)) {
|
|
|
|
|
s->enable_new_dtags = 1;
|
2010-08-13 03:30:21 +08:00
|
|
|
|
} else if (link_option(option, "section-alignment=", &p)) {
|
2010-04-06 03:21:58 +08:00
|
|
|
|
s->section_align = strtoul(p, &end, 16);
|
2010-08-13 03:30:21 +08:00
|
|
|
|
} else if (link_option(option, "soname=", &p)) {
|
2017-02-11 16:54:01 +08:00
|
|
|
|
copy_linker_arg(&s->soname, p, 0);
|
2010-04-06 03:21:58 +08:00
|
|
|
|
#ifdef TCC_TARGET_PE
|
2016-12-12 22:52:45 +08:00
|
|
|
|
} else if (link_option(option, "large-address-aware", &p)) {
|
|
|
|
|
s->pe_characteristics |= 0x20;
|
2011-07-12 00:47:16 +08:00
|
|
|
|
} else if (link_option(option, "file-alignment=", &p)) {
|
|
|
|
|
s->pe_file_align = strtoul(p, &end, 16);
|
|
|
|
|
} else if (link_option(option, "stack=", &p)) {
|
|
|
|
|
s->pe_stack_size = strtoul(p, &end, 10);
|
2010-08-13 03:30:21 +08:00
|
|
|
|
} else if (link_option(option, "subsystem=", &p)) {
|
2010-04-06 03:21:58 +08:00
|
|
|
|
#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
|
|
|
|
|
if (!strcmp(p, "native")) {
|
|
|
|
|
s->pe_subsystem = 1;
|
|
|
|
|
} else if (!strcmp(p, "console")) {
|
|
|
|
|
s->pe_subsystem = 3;
|
2017-04-04 14:34:52 +08:00
|
|
|
|
} else if (!strcmp(p, "gui") || !strcmp(p, "windows")) {
|
2010-04-06 03:21:58 +08:00
|
|
|
|
s->pe_subsystem = 2;
|
|
|
|
|
} else if (!strcmp(p, "posix")) {
|
|
|
|
|
s->pe_subsystem = 7;
|
|
|
|
|
} else if (!strcmp(p, "efiapp")) {
|
|
|
|
|
s->pe_subsystem = 10;
|
|
|
|
|
} else if (!strcmp(p, "efiboot")) {
|
|
|
|
|
s->pe_subsystem = 11;
|
|
|
|
|
} else if (!strcmp(p, "efiruntime")) {
|
|
|
|
|
s->pe_subsystem = 12;
|
|
|
|
|
} else if (!strcmp(p, "efirom")) {
|
|
|
|
|
s->pe_subsystem = 13;
|
|
|
|
|
#elif defined(TCC_TARGET_ARM)
|
|
|
|
|
if (!strcmp(p, "wince")) {
|
|
|
|
|
s->pe_subsystem = 9;
|
|
|
|
|
#endif
|
2013-02-13 02:13:28 +08:00
|
|
|
|
} else
|
|
|
|
|
goto err;
|
2010-04-06 03:21:58 +08:00
|
|
|
|
#endif
|
2016-10-02 02:54:45 +08:00
|
|
|
|
} else if (ret = link_option(option, "?whole-archive", &p), ret) {
|
2018-06-01 05:51:59 +08:00
|
|
|
|
if (ret > 0)
|
|
|
|
|
s->filetype |= AFF_WHOLE_ARCHIVE;
|
|
|
|
|
else
|
|
|
|
|
s->filetype &= ~AFF_WHOLE_ARCHIVE;
|
2016-10-02 02:49:38 +08:00
|
|
|
|
} else if (p) {
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
err:
|
|
|
|
|
tcc_error("unsupported linker option '%s'", option);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
}
|
2016-10-02 02:49:38 +08:00
|
|
|
|
|
|
|
|
|
if (ignoring && s->warn_unsupported)
|
|
|
|
|
tcc_warning("unsupported linker option '%s'", option);
|
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
|
option = skip_linker_arg(&p);
|
2010-04-06 03:21:58 +08:00
|
|
|
|
}
|
2016-10-02 02:49:38 +08:00
|
|
|
|
return 1;
|
2010-04-06 03:21:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
|
typedef struct TCCOption {
|
|
|
|
|
const char *name;
|
|
|
|
|
uint16_t index;
|
|
|
|
|
uint16_t flags;
|
|
|
|
|
} TCCOption;
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
TCC_OPTION_HELP,
|
2017-02-18 16:55:46 +08:00
|
|
|
|
TCC_OPTION_HELP2,
|
2017-02-18 16:55:34 +08:00
|
|
|
|
TCC_OPTION_v,
|
2013-02-13 02:13:28 +08:00
|
|
|
|
TCC_OPTION_I,
|
|
|
|
|
TCC_OPTION_D,
|
|
|
|
|
TCC_OPTION_U,
|
2015-03-03 19:19:14 +08:00
|
|
|
|
TCC_OPTION_P,
|
2013-02-13 02:13:28 +08:00
|
|
|
|
TCC_OPTION_L,
|
|
|
|
|
TCC_OPTION_B,
|
|
|
|
|
TCC_OPTION_l,
|
|
|
|
|
TCC_OPTION_bench,
|
|
|
|
|
TCC_OPTION_bt,
|
|
|
|
|
TCC_OPTION_b,
|
2019-12-12 20:29:45 +08:00
|
|
|
|
TCC_OPTION_ba,
|
2013-02-13 02:13:28 +08:00
|
|
|
|
TCC_OPTION_g,
|
|
|
|
|
TCC_OPTION_c,
|
2015-03-24 01:58:27 +08:00
|
|
|
|
TCC_OPTION_dumpversion,
|
2015-05-13 17:16:00 +08:00
|
|
|
|
TCC_OPTION_d,
|
2013-02-13 02:13:28 +08:00
|
|
|
|
TCC_OPTION_static,
|
2015-03-03 21:25:02 +08:00
|
|
|
|
TCC_OPTION_std,
|
2013-02-13 02:13:28 +08:00
|
|
|
|
TCC_OPTION_shared,
|
|
|
|
|
TCC_OPTION_soname,
|
|
|
|
|
TCC_OPTION_o,
|
|
|
|
|
TCC_OPTION_r,
|
|
|
|
|
TCC_OPTION_s,
|
2015-05-04 01:10:57 +08:00
|
|
|
|
TCC_OPTION_traditional,
|
2013-02-13 02:13:28 +08:00
|
|
|
|
TCC_OPTION_Wl,
|
2016-06-28 02:09:40 +08:00
|
|
|
|
TCC_OPTION_Wp,
|
2013-02-13 02:13:28 +08:00
|
|
|
|
TCC_OPTION_W,
|
|
|
|
|
TCC_OPTION_O,
|
2016-12-19 05:57:03 +08:00
|
|
|
|
TCC_OPTION_mfloat_abi,
|
2013-02-13 02:13:28 +08:00
|
|
|
|
TCC_OPTION_m,
|
|
|
|
|
TCC_OPTION_f,
|
|
|
|
|
TCC_OPTION_isystem,
|
2015-05-04 01:10:57 +08:00
|
|
|
|
TCC_OPTION_iwithprefix,
|
2016-06-27 22:40:00 +08:00
|
|
|
|
TCC_OPTION_include,
|
2013-02-13 02:13:28 +08:00
|
|
|
|
TCC_OPTION_nostdinc,
|
|
|
|
|
TCC_OPTION_nostdlib,
|
|
|
|
|
TCC_OPTION_print_search_dirs,
|
|
|
|
|
TCC_OPTION_rdynamic,
|
2016-06-28 00:06:32 +08:00
|
|
|
|
TCC_OPTION_param,
|
2013-02-13 02:13:28 +08:00
|
|
|
|
TCC_OPTION_pedantic,
|
|
|
|
|
TCC_OPTION_pthread,
|
|
|
|
|
TCC_OPTION_run,
|
|
|
|
|
TCC_OPTION_w,
|
|
|
|
|
TCC_OPTION_pipe,
|
|
|
|
|
TCC_OPTION_E,
|
|
|
|
|
TCC_OPTION_MD,
|
|
|
|
|
TCC_OPTION_MF,
|
2017-02-18 16:55:34 +08:00
|
|
|
|
TCC_OPTION_x,
|
|
|
|
|
TCC_OPTION_ar,
|
|
|
|
|
TCC_OPTION_impdef
|
2013-02-13 02:13:28 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define TCC_OPTION_HAS_ARG 0x0001
|
|
|
|
|
#define TCC_OPTION_NOSEP 0x0002 /* cannot have space before option and arg */
|
|
|
|
|
|
|
|
|
|
static const TCCOption tcc_options[] = {
|
|
|
|
|
{ "h", TCC_OPTION_HELP, 0 },
|
|
|
|
|
{ "-help", TCC_OPTION_HELP, 0 },
|
|
|
|
|
{ "?", TCC_OPTION_HELP, 0 },
|
2017-02-18 16:55:46 +08:00
|
|
|
|
{ "hh", TCC_OPTION_HELP2, 0 },
|
2017-02-18 16:55:34 +08:00
|
|
|
|
{ "v", TCC_OPTION_v, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
2013-02-13 02:13:28 +08:00
|
|
|
|
{ "I", TCC_OPTION_I, TCC_OPTION_HAS_ARG },
|
|
|
|
|
{ "D", TCC_OPTION_D, TCC_OPTION_HAS_ARG },
|
|
|
|
|
{ "U", TCC_OPTION_U, TCC_OPTION_HAS_ARG },
|
2015-03-03 19:19:14 +08:00
|
|
|
|
{ "P", TCC_OPTION_P, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
2013-02-13 02:13:28 +08:00
|
|
|
|
{ "L", TCC_OPTION_L, TCC_OPTION_HAS_ARG },
|
|
|
|
|
{ "B", TCC_OPTION_B, TCC_OPTION_HAS_ARG },
|
2018-11-13 00:50:20 +08:00
|
|
|
|
{ "l", TCC_OPTION_l, TCC_OPTION_HAS_ARG },
|
2013-02-13 02:13:28 +08:00
|
|
|
|
{ "bench", TCC_OPTION_bench, 0 },
|
|
|
|
|
#ifdef CONFIG_TCC_BACKTRACE
|
2020-01-18 05:58:39 +08:00
|
|
|
|
{ "bt", TCC_OPTION_bt, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
2013-02-13 02:13:28 +08:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
|
|
|
|
{ "b", TCC_OPTION_b, 0 },
|
|
|
|
|
#endif
|
|
|
|
|
{ "g", TCC_OPTION_g, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
|
|
|
|
{ "c", TCC_OPTION_c, 0 },
|
2015-03-24 01:58:27 +08:00
|
|
|
|
{ "dumpversion", TCC_OPTION_dumpversion, 0},
|
2015-05-13 17:16:00 +08:00
|
|
|
|
{ "d", TCC_OPTION_d, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
2013-02-13 02:13:28 +08:00
|
|
|
|
{ "static", TCC_OPTION_static, 0 },
|
2015-03-03 21:25:02 +08:00
|
|
|
|
{ "std", TCC_OPTION_std, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
2013-02-13 02:13:28 +08:00
|
|
|
|
{ "shared", TCC_OPTION_shared, 0 },
|
|
|
|
|
{ "soname", TCC_OPTION_soname, TCC_OPTION_HAS_ARG },
|
|
|
|
|
{ "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG },
|
2016-06-28 00:06:32 +08:00
|
|
|
|
{ "-param", TCC_OPTION_param, TCC_OPTION_HAS_ARG },
|
2013-02-13 02:13:28 +08:00
|
|
|
|
{ "pedantic", TCC_OPTION_pedantic, 0},
|
|
|
|
|
{ "pthread", TCC_OPTION_pthread, 0},
|
|
|
|
|
{ "run", TCC_OPTION_run, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
|
|
|
|
{ "rdynamic", TCC_OPTION_rdynamic, 0 },
|
|
|
|
|
{ "r", TCC_OPTION_r, 0 },
|
|
|
|
|
{ "s", TCC_OPTION_s, 0 },
|
2015-05-04 01:10:57 +08:00
|
|
|
|
{ "traditional", TCC_OPTION_traditional, 0 },
|
2013-02-13 02:13:28 +08:00
|
|
|
|
{ "Wl,", TCC_OPTION_Wl, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
2016-06-28 02:09:40 +08:00
|
|
|
|
{ "Wp,", TCC_OPTION_Wp, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
2013-02-13 02:13:28 +08:00
|
|
|
|
{ "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
|
|
|
|
{ "O", TCC_OPTION_O, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
2016-12-19 05:57:03 +08:00
|
|
|
|
#ifdef TCC_TARGET_ARM
|
|
|
|
|
{ "mfloat-abi", TCC_OPTION_mfloat_abi, TCC_OPTION_HAS_ARG },
|
|
|
|
|
#endif
|
|
|
|
|
{ "m", TCC_OPTION_m, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
2013-02-13 02:13:28 +08:00
|
|
|
|
{ "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
|
|
|
|
{ "isystem", TCC_OPTION_isystem, TCC_OPTION_HAS_ARG },
|
2016-06-27 22:40:00 +08:00
|
|
|
|
{ "include", TCC_OPTION_include, TCC_OPTION_HAS_ARG },
|
2013-02-13 02:13:28 +08:00
|
|
|
|
{ "nostdinc", TCC_OPTION_nostdinc, 0 },
|
|
|
|
|
{ "nostdlib", TCC_OPTION_nostdlib, 0 },
|
2013-11-09 03:24:15 +08:00
|
|
|
|
{ "print-search-dirs", TCC_OPTION_print_search_dirs, 0 },
|
2013-02-13 02:13:28 +08:00
|
|
|
|
{ "w", TCC_OPTION_w, 0 },
|
|
|
|
|
{ "pipe", TCC_OPTION_pipe, 0},
|
|
|
|
|
{ "E", TCC_OPTION_E, 0},
|
|
|
|
|
{ "MD", TCC_OPTION_MD, 0},
|
|
|
|
|
{ "MF", TCC_OPTION_MF, TCC_OPTION_HAS_ARG },
|
|
|
|
|
{ "x", TCC_OPTION_x, TCC_OPTION_HAS_ARG },
|
2017-02-18 16:55:34 +08:00
|
|
|
|
{ "ar", TCC_OPTION_ar, 0},
|
|
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
|
{ "impdef", TCC_OPTION_impdef, 0},
|
|
|
|
|
#endif
|
2013-02-13 02:13:28 +08:00
|
|
|
|
{ NULL, 0, 0 },
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-19 05:57:03 +08:00
|
|
|
|
static const FlagDef options_W[] = {
|
|
|
|
|
{ 0, 0, "all" },
|
|
|
|
|
{ offsetof(TCCState, warn_unsupported), 0, "unsupported" },
|
|
|
|
|
{ offsetof(TCCState, warn_write_strings), 0, "write-strings" },
|
|
|
|
|
{ offsetof(TCCState, warn_error), 0, "error" },
|
2017-05-10 00:10:02 +08:00
|
|
|
|
{ offsetof(TCCState, warn_gcc_compat), 0, "gcc-compat" },
|
2016-12-19 05:57:03 +08:00
|
|
|
|
{ offsetof(TCCState, warn_implicit_function_declaration), WD_ALL,
|
|
|
|
|
"implicit-function-declaration" },
|
|
|
|
|
{ 0, 0, NULL }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const FlagDef options_f[] = {
|
|
|
|
|
{ offsetof(TCCState, char_is_unsigned), 0, "unsigned-char" },
|
|
|
|
|
{ offsetof(TCCState, char_is_unsigned), FD_INVERT, "signed-char" },
|
|
|
|
|
{ offsetof(TCCState, nocommon), FD_INVERT, "common" },
|
|
|
|
|
{ offsetof(TCCState, leading_underscore), 0, "leading-underscore" },
|
|
|
|
|
{ offsetof(TCCState, ms_extensions), 0, "ms-extensions" },
|
|
|
|
|
{ offsetof(TCCState, dollars_in_identifiers), 0, "dollars-in-identifiers" },
|
|
|
|
|
{ 0, 0, NULL }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const FlagDef options_m[] = {
|
|
|
|
|
{ offsetof(TCCState, ms_bitfields), 0, "ms-bitfields" },
|
|
|
|
|
#ifdef TCC_TARGET_X86_64
|
|
|
|
|
{ offsetof(TCCState, nosse), FD_INVERT, "sse" },
|
|
|
|
|
#endif
|
|
|
|
|
{ 0, 0, NULL }
|
|
|
|
|
};
|
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
|
static void parse_option_D(TCCState *s1, const char *optarg)
|
2009-12-20 08:53:49 +08:00
|
|
|
|
{
|
2013-02-13 02:13:28 +08:00
|
|
|
|
char *sym = tcc_strdup(optarg);
|
|
|
|
|
char *value = strchr(sym, '=');
|
|
|
|
|
if (value)
|
|
|
|
|
*value++ = '\0';
|
|
|
|
|
tcc_define_symbol(s1, sym, value);
|
|
|
|
|
tcc_free(sym);
|
2009-12-20 08:53:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-12 20:35:37 +08:00
|
|
|
|
static void args_parser_add_file(TCCState *s, const char* filename, int filetype)
|
|
|
|
|
{
|
2016-10-02 02:04:58 +08:00
|
|
|
|
struct filespec *f = tcc_malloc(sizeof *f + strlen(filename));
|
|
|
|
|
f->type = filetype;
|
|
|
|
|
strcpy(f->name, filename);
|
2017-02-14 01:23:43 +08:00
|
|
|
|
dynarray_add(&s->files, &s->nb_files, f);
|
2015-04-12 20:35:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-18 16:55:34 +08:00
|
|
|
|
static int args_parser_make_argv(const char *r, int *argc, char ***argv)
|
|
|
|
|
{
|
|
|
|
|
int ret = 0, q, c;
|
|
|
|
|
CString str;
|
|
|
|
|
for(;;) {
|
|
|
|
|
while (c = (unsigned char)*r, c && c <= ' ')
|
2019-01-11 21:26:17 +08:00
|
|
|
|
++r;
|
2017-02-18 16:55:34 +08:00
|
|
|
|
if (c == 0)
|
|
|
|
|
break;
|
|
|
|
|
q = 0;
|
|
|
|
|
cstr_new(&str);
|
|
|
|
|
while (c = (unsigned char)*r, c) {
|
|
|
|
|
++r;
|
|
|
|
|
if (c == '\\' && (*r == '"' || *r == '\\')) {
|
|
|
|
|
c = *r++;
|
|
|
|
|
} else if (c == '"') {
|
|
|
|
|
q = !q;
|
|
|
|
|
continue;
|
|
|
|
|
} else if (q == 0 && c <= ' ') {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
cstr_ccat(&str, c);
|
|
|
|
|
}
|
|
|
|
|
cstr_ccat(&str, 0);
|
|
|
|
|
//printf("<%s>\n", str.data), fflush(stdout);
|
|
|
|
|
dynarray_add(argv, argc, tcc_strdup(str.data));
|
|
|
|
|
cstr_free(&str);
|
|
|
|
|
++ret;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 02:19:37 +08:00
|
|
|
|
/* read list file */
|
2017-02-18 16:55:34 +08:00
|
|
|
|
static void args_parser_listfile(TCCState *s,
|
|
|
|
|
const char *filename, int optind, int *pargc, char ***pargv)
|
2016-10-02 02:19:37 +08:00
|
|
|
|
{
|
2019-12-11 07:37:18 +08:00
|
|
|
|
TCCState *s1 = s;
|
2017-02-18 16:55:34 +08:00
|
|
|
|
int fd, i;
|
2016-10-02 02:19:37 +08:00
|
|
|
|
size_t len;
|
|
|
|
|
char *p;
|
2017-02-18 16:55:34 +08:00
|
|
|
|
int argc = 0;
|
|
|
|
|
char **argv = NULL;
|
2016-10-02 02:19:37 +08:00
|
|
|
|
|
|
|
|
|
fd = open(filename, O_RDONLY | O_BINARY);
|
|
|
|
|
if (fd < 0)
|
2017-02-18 16:55:34 +08:00
|
|
|
|
tcc_error("listfile '%s' not found", filename);
|
2016-10-02 02:19:37 +08:00
|
|
|
|
|
|
|
|
|
len = lseek(fd, 0, SEEK_END);
|
|
|
|
|
p = tcc_malloc(len + 1), p[len] = 0;
|
|
|
|
|
lseek(fd, 0, SEEK_SET), read(fd, p, len), close(fd);
|
2017-02-18 16:55:34 +08:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < *pargc; ++i)
|
|
|
|
|
if (i == optind)
|
|
|
|
|
args_parser_make_argv(p, &argc, &argv);
|
|
|
|
|
else
|
|
|
|
|
dynarray_add(&argv, &argc, tcc_strdup((*pargv)[i]));
|
|
|
|
|
|
2016-10-02 02:19:37 +08:00
|
|
|
|
tcc_free(p);
|
2017-02-18 16:55:34 +08:00
|
|
|
|
dynarray_reset(&s->argv, &s->argc);
|
|
|
|
|
*pargc = s->argc = argc, *pargv = s->argv = argv;
|
2016-10-02 02:19:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-18 16:55:34 +08:00
|
|
|
|
PUB_FUNC int tcc_parse_args(TCCState *s, int *pargc, char ***pargv, int optind)
|
2010-06-16 20:54:24 +08:00
|
|
|
|
{
|
2019-12-11 07:37:18 +08:00
|
|
|
|
TCCState *s1 = s;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
const TCCOption *popt;
|
|
|
|
|
const char *optarg, *r;
|
2017-02-14 01:23:43 +08:00
|
|
|
|
const char *run = NULL;
|
2016-10-18 02:50:54 +08:00
|
|
|
|
int last_o = -1;
|
2017-02-18 16:55:34 +08:00
|
|
|
|
int x;
|
2016-10-02 02:49:38 +08:00
|
|
|
|
CString linker_arg; /* collect -Wl options */
|
2017-02-18 16:55:34 +08:00
|
|
|
|
int tool = 0, arg_start = 0, noaction = optind;
|
|
|
|
|
char **argv = *pargv;
|
|
|
|
|
int argc = *pargc;
|
2016-10-02 02:19:37 +08:00
|
|
|
|
|
2016-10-02 02:49:38 +08:00
|
|
|
|
cstr_new(&linker_arg);
|
2010-06-16 20:54:24 +08:00
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
|
while (optind < argc) {
|
2017-02-18 16:55:34 +08:00
|
|
|
|
r = argv[optind];
|
2016-10-02 02:19:37 +08:00
|
|
|
|
if (r[0] == '@' && r[1] != '\0') {
|
2017-02-18 16:55:34 +08:00
|
|
|
|
args_parser_listfile(s, r + 1, optind, &argc, &argv);
|
2019-01-11 21:26:17 +08:00
|
|
|
|
continue;
|
2016-10-02 02:19:37 +08:00
|
|
|
|
}
|
2017-02-18 16:55:34 +08:00
|
|
|
|
optind++;
|
|
|
|
|
if (tool) {
|
|
|
|
|
if (r[0] == '-' && r[1] == 'v' && r[2] == 0)
|
|
|
|
|
++s->verbose;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
reparse:
|
2013-02-13 02:13:28 +08:00
|
|
|
|
if (r[0] != '-' || r[1] == '\0') {
|
2017-02-14 01:23:43 +08:00
|
|
|
|
if (r[0] != '@') /* allow "tcc file(s) -run @ args ..." */
|
|
|
|
|
args_parser_add_file(s, r, s->filetype);
|
2016-10-02 02:19:37 +08:00
|
|
|
|
if (run) {
|
2017-02-14 01:23:43 +08:00
|
|
|
|
tcc_set_options(s, run);
|
2017-02-18 16:55:34 +08:00
|
|
|
|
arg_start = optind - 1;
|
2016-10-02 02:19:37 +08:00
|
|
|
|
break;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
tcc: Draft suppoprt for -MD/-MF options
In build systems, this is used to automatically collect target
dependencies, e.g.
---- 8< (hello.c) ----
#include "hello.h"
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
$ tcc -MD -c hello.c # -> hello.o, hello.d
$ cat hello.d
hello.o : \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
NOTE: gcc supports -MD only for .c -> .o, but in tcc, we generate
dependencies for whatever action is being taken. E.g. for .c -> exe, the
result will be:
$ tcc -MD -o hello hello.c # -> hello, hello.d
hello: \
/usr/lib/crt1.o \
/usr/lib/crti.o \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
/usr/lib/libc.so \
/lib/libc.so.6 \
/usr/lib/ld-linux.so.2 \
/lib/ld-linux.so.2 \
/usr/lib/libc_nonshared.a \
/lib/libc.so.6 \
/usr/lib/libc_nonshared.a \
/home/kirr/local/tcc/lib/tcc/libtcc1.a \
/usr/lib/crtn.o \
So tcc dependency generator is a bit more clever than one used in gcc :)
Also, I've updated TODO and Changelog (in not-yet-released section).
v2:
(Taking inputs from grischka and me myself)
- put code to generate deps file into a function.
- used tcc_fileextension() instead of open-coding
- generate deps only when compilation/preprocessing was successful
v3:
- use pstrcpy instead of snprintf(buf, sizeof(buf), "%s", ...)
2010-06-21 00:08:12 +08:00
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
|
/* find option in table */
|
|
|
|
|
for(popt = tcc_options; ; ++popt) {
|
|
|
|
|
const char *p1 = popt->name;
|
|
|
|
|
const char *r1 = r + 1;
|
|
|
|
|
if (p1 == NULL)
|
|
|
|
|
tcc_error("invalid option -- '%s'", r);
|
|
|
|
|
if (!strstart(p1, &r1))
|
|
|
|
|
continue;
|
|
|
|
|
optarg = r1;
|
|
|
|
|
if (popt->flags & TCC_OPTION_HAS_ARG) {
|
|
|
|
|
if (*r1 == '\0' && !(popt->flags & TCC_OPTION_NOSEP)) {
|
|
|
|
|
if (optind >= argc)
|
2016-10-02 02:49:38 +08:00
|
|
|
|
arg_err:
|
2013-02-13 02:13:28 +08:00
|
|
|
|
tcc_error("argument to '%s' is missing", r);
|
|
|
|
|
optarg = argv[optind++];
|
|
|
|
|
}
|
|
|
|
|
} else if (*r1 != '\0')
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
}
|
tcc: Draft suppoprt for -MD/-MF options
In build systems, this is used to automatically collect target
dependencies, e.g.
---- 8< (hello.c) ----
#include "hello.h"
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
$ tcc -MD -c hello.c # -> hello.o, hello.d
$ cat hello.d
hello.o : \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
NOTE: gcc supports -MD only for .c -> .o, but in tcc, we generate
dependencies for whatever action is being taken. E.g. for .c -> exe, the
result will be:
$ tcc -MD -o hello hello.c # -> hello, hello.d
hello: \
/usr/lib/crt1.o \
/usr/lib/crti.o \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
/usr/lib/libc.so \
/lib/libc.so.6 \
/usr/lib/ld-linux.so.2 \
/lib/ld-linux.so.2 \
/usr/lib/libc_nonshared.a \
/lib/libc.so.6 \
/usr/lib/libc_nonshared.a \
/home/kirr/local/tcc/lib/tcc/libtcc1.a \
/usr/lib/crtn.o \
So tcc dependency generator is a bit more clever than one used in gcc :)
Also, I've updated TODO and Changelog (in not-yet-released section).
v2:
(Taking inputs from grischka and me myself)
- put code to generate deps file into a function.
- used tcc_fileextension() instead of open-coding
- generate deps only when compilation/preprocessing was successful
v3:
- use pstrcpy instead of snprintf(buf, sizeof(buf), "%s", ...)
2010-06-21 00:08:12 +08:00
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
|
switch(popt->index) {
|
|
|
|
|
case TCC_OPTION_HELP:
|
2017-02-18 16:55:34 +08:00
|
|
|
|
return OPT_HELP;
|
2017-02-18 16:55:46 +08:00
|
|
|
|
case TCC_OPTION_HELP2:
|
|
|
|
|
return OPT_HELP2;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
case TCC_OPTION_I:
|
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
|
|
|
|
tcc_add_include_path(s, optarg);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_D:
|
|
|
|
|
parse_option_D(s, optarg);
|
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_U:
|
|
|
|
|
tcc_undefine_symbol(s, optarg);
|
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_L:
|
|
|
|
|
tcc_add_library_path(s, optarg);
|
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_B:
|
|
|
|
|
/* set tcc utilities path (mainly for tcc development) */
|
|
|
|
|
tcc_set_lib_path(s, optarg);
|
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_l:
|
2018-06-01 05:51:59 +08:00
|
|
|
|
args_parser_add_file(s, optarg, AFF_TYPE_LIB | (s->filetype & ~AFF_TYPE_MASK));
|
2013-02-13 02:13:28 +08:00
|
|
|
|
s->nb_libraries++;
|
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_pthread:
|
|
|
|
|
parse_option_D(s, "_REENTRANT");
|
2017-12-23 21:46:27 +08:00
|
|
|
|
s->option_pthread = 1;
|
|
|
|
|
break;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
case TCC_OPTION_bench:
|
|
|
|
|
s->do_bench = 1;
|
|
|
|
|
break;
|
|
|
|
|
#ifdef CONFIG_TCC_BACKTRACE
|
|
|
|
|
case TCC_OPTION_bt:
|
2019-12-11 07:37:18 +08:00
|
|
|
|
s->rt_num_callers = atoi(optarg);
|
2020-01-18 05:58:39 +08:00
|
|
|
|
s->do_backtrace = 1;
|
|
|
|
|
s->do_debug = 1;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
|
|
|
|
case TCC_OPTION_b:
|
|
|
|
|
s->do_bounds_check = 1;
|
2020-01-18 05:58:39 +08:00
|
|
|
|
s->do_backtrace = 1;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
s->do_debug = 1;
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
case TCC_OPTION_g:
|
|
|
|
|
s->do_debug = 1;
|
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_c:
|
2016-10-02 02:19:37 +08:00
|
|
|
|
x = TCC_OUTPUT_OBJ;
|
|
|
|
|
set_output_type:
|
2015-05-13 17:16:00 +08:00
|
|
|
|
if (s->output_type)
|
2016-10-02 02:19:37 +08:00
|
|
|
|
tcc_warning("-%s: overriding compiler action already specified", popt->name);
|
|
|
|
|
s->output_type = x;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
break;
|
2015-05-13 17:16:00 +08:00
|
|
|
|
case TCC_OPTION_d:
|
2016-05-05 20:12:53 +08:00
|
|
|
|
if (*optarg == 'D')
|
|
|
|
|
s->dflag = 3;
|
|
|
|
|
else if (*optarg == 'M')
|
|
|
|
|
s->dflag = 7;
|
2017-07-21 04:21:27 +08:00
|
|
|
|
else if (*optarg == 't')
|
|
|
|
|
s->dflag = 16;
|
2017-07-15 01:26:01 +08:00
|
|
|
|
else if (isnum(*optarg))
|
2019-12-14 19:31:03 +08:00
|
|
|
|
s->g_debug |= atoi(optarg);
|
2016-05-05 20:12:53 +08:00
|
|
|
|
else
|
|
|
|
|
goto unsupported_option;
|
2015-05-13 17:16:00 +08:00
|
|
|
|
break;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
case TCC_OPTION_static:
|
|
|
|
|
s->static_link = 1;
|
|
|
|
|
break;
|
2015-03-03 21:25:02 +08:00
|
|
|
|
case TCC_OPTION_std:
|
2019-01-10 21:41:54 +08:00
|
|
|
|
if (*optarg == '=') {
|
2019-01-11 21:26:17 +08:00
|
|
|
|
if (strcmp(optarg, "=c11") == 0) {
|
2019-01-12 17:41:56 +08:00
|
|
|
|
tcc_undefine_symbol(s, "__STDC_VERSION__");
|
|
|
|
|
tcc_define_symbol(s, "__STDC_VERSION__", "201112L");
|
|
|
|
|
/*
|
|
|
|
|
* The integer constant 1, intended to indicate
|
|
|
|
|
* that the implementation does not support atomic
|
|
|
|
|
* types (including the _Atomic type qualifier) and
|
|
|
|
|
* the <stdatomic.h> header.
|
|
|
|
|
*/
|
|
|
|
|
tcc_define_symbol(s, "__STDC_NO_ATOMICS__", "1");
|
|
|
|
|
/*
|
|
|
|
|
* The integer constant 1, intended to indicate
|
|
|
|
|
* that the implementation does not support complex
|
|
|
|
|
* types or the <complex.h> header.
|
|
|
|
|
*/
|
|
|
|
|
tcc_define_symbol(s, "__STDC_NO_COMPLEX__", "1");
|
|
|
|
|
/*
|
|
|
|
|
* The integer constant 1, intended to indicate
|
|
|
|
|
* that the implementation does not support the
|
|
|
|
|
* <threads.h> header.
|
|
|
|
|
*/
|
|
|
|
|
tcc_define_symbol(s, "__STDC_NO_THREADS__", "1");
|
|
|
|
|
/*
|
|
|
|
|
* __STDC_NO_VLA__, tcc supports VLA.
|
|
|
|
|
* The integer constant 1, intended to indicate
|
|
|
|
|
* that the implementation does not support
|
|
|
|
|
* variable length arrays or variably modified
|
|
|
|
|
* types.
|
|
|
|
|
*/
|
|
|
|
|
#if !defined(TCC_TARGET_PE)
|
|
|
|
|
/*
|
|
|
|
|
* An integer constant of the form yyyymmL (for
|
|
|
|
|
* example, 199712L). If this symbol is defined,
|
|
|
|
|
* then every character in the Unicode required
|
|
|
|
|
* set, when stored in an object of type
|
|
|
|
|
* wchar_t, has the same value as the short
|
|
|
|
|
* identifier of that character.
|
|
|
|
|
*/
|
2019-06-11 19:43:24 +08:00
|
|
|
|
#if 0
|
|
|
|
|
/* on Linux, this conflicts with a define introduced by
|
|
|
|
|
* /usr/include/stdc-predef.h included by glibc libs;
|
|
|
|
|
* clang doesn't define it at all so it's probably not necessary
|
|
|
|
|
*/
|
2019-01-12 17:41:56 +08:00
|
|
|
|
tcc_define_symbol(s, "__STDC_ISO_10646__", "201605L");
|
2019-06-11 19:43:24 +08:00
|
|
|
|
#endif
|
2019-01-12 17:41:56 +08:00
|
|
|
|
/*
|
|
|
|
|
* The integer constant 1, intended to indicate
|
|
|
|
|
* that values of type char16_t are UTF−16
|
|
|
|
|
* encoded. If some other encoding is used, the
|
|
|
|
|
* macro shall not be defined and the actual
|
|
|
|
|
* encoding used is implementation defined.
|
|
|
|
|
*/
|
|
|
|
|
tcc_define_symbol(s, "__STDC_UTF_16__", "1");
|
|
|
|
|
/*
|
|
|
|
|
* The integer constant 1, intended to indicate
|
|
|
|
|
* that values of type char32_t are UTF−32
|
|
|
|
|
* encoded. If some other encoding is used, the
|
|
|
|
|
* macro shall not be defined and the actual
|
|
|
|
|
* encoding used is implementationdefined.
|
|
|
|
|
*/
|
|
|
|
|
tcc_define_symbol(s, "__STDC_UTF_32__", "1");
|
|
|
|
|
#endif /* !TCC_TARGET_PE */
|
|
|
|
|
s->cversion = 201112;
|
2019-01-10 21:41:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-11 21:26:17 +08:00
|
|
|
|
/*
|
|
|
|
|
* silently ignore other values, a current purpose:
|
|
|
|
|
* allow to use a tcc as a reference compiler for "make test"
|
|
|
|
|
*/
|
2015-03-03 21:25:02 +08:00
|
|
|
|
break;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
case TCC_OPTION_shared:
|
2016-10-02 02:19:37 +08:00
|
|
|
|
x = TCC_OUTPUT_DLL;
|
|
|
|
|
goto set_output_type;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
case TCC_OPTION_soname:
|
|
|
|
|
s->soname = tcc_strdup(optarg);
|
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_o:
|
2015-05-10 15:13:35 +08:00
|
|
|
|
if (s->outfile) {
|
|
|
|
|
tcc_warning("multiple -o option");
|
|
|
|
|
tcc_free(s->outfile);
|
|
|
|
|
}
|
2013-02-13 02:13:28 +08:00
|
|
|
|
s->outfile = tcc_strdup(optarg);
|
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_r:
|
|
|
|
|
/* generate a .o merging several output files */
|
|
|
|
|
s->option_r = 1;
|
2016-10-02 02:19:37 +08:00
|
|
|
|
x = TCC_OUTPUT_OBJ;
|
|
|
|
|
goto set_output_type;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
case TCC_OPTION_isystem:
|
|
|
|
|
tcc_add_sysinclude_path(s, optarg);
|
|
|
|
|
break;
|
2019-01-11 21:26:17 +08:00
|
|
|
|
case TCC_OPTION_include:
|
2019-12-14 19:31:03 +08:00
|
|
|
|
cstr_printf(&s->cmdline_incl, "#include \"%s\"\n", optarg);
|
2019-01-11 21:26:17 +08:00
|
|
|
|
break;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
case TCC_OPTION_nostdinc:
|
|
|
|
|
s->nostdinc = 1;
|
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_nostdlib:
|
|
|
|
|
s->nostdlib = 1;
|
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_run:
|
2016-10-02 02:04:33 +08:00
|
|
|
|
#ifndef TCC_IS_NATIVE
|
|
|
|
|
tcc_error("-run is not available in a cross compiler");
|
|
|
|
|
#endif
|
2017-02-14 01:23:43 +08:00
|
|
|
|
run = optarg;
|
2016-10-02 02:19:37 +08:00
|
|
|
|
x = TCC_OUTPUT_MEMORY;
|
|
|
|
|
goto set_output_type;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
case TCC_OPTION_v:
|
|
|
|
|
do ++s->verbose; while (*optarg++ == 'v');
|
2017-02-18 16:55:34 +08:00
|
|
|
|
++noaction;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_f:
|
2016-12-19 05:57:03 +08:00
|
|
|
|
if (set_flag(s, options_f, optarg) < 0)
|
|
|
|
|
goto unsupported_option;
|
|
|
|
|
break;
|
|
|
|
|
#ifdef TCC_TARGET_ARM
|
|
|
|
|
case TCC_OPTION_mfloat_abi:
|
|
|
|
|
/* tcc doesn't support soft float yet */
|
|
|
|
|
if (!strcmp(optarg, "softfp")) {
|
|
|
|
|
s->float_abi = ARM_SOFTFP_FLOAT;
|
|
|
|
|
tcc_undefine_symbol(s, "__ARM_PCS_VFP");
|
|
|
|
|
} else if (!strcmp(optarg, "hard"))
|
|
|
|
|
s->float_abi = ARM_HARD_FLOAT;
|
|
|
|
|
else
|
|
|
|
|
tcc_error("unsupported float abi '%s'", optarg);
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
case TCC_OPTION_m:
|
2017-02-18 16:55:34 +08:00
|
|
|
|
if (set_flag(s, options_m, optarg) < 0) {
|
|
|
|
|
if (x = atoi(optarg), x != 32 && x != 64)
|
|
|
|
|
goto unsupported_option;
|
|
|
|
|
if (PTR_SIZE != x/8)
|
|
|
|
|
return x;
|
|
|
|
|
++noaction;
|
|
|
|
|
}
|
2013-02-13 02:13:28 +08:00
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_W:
|
2019-12-17 01:51:28 +08:00
|
|
|
|
s->warn_none = 0;
|
|
|
|
|
if (optarg[0] && set_flag(s, options_W, optarg) < 0)
|
2013-02-13 02:13:28 +08:00
|
|
|
|
goto unsupported_option;
|
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_w:
|
|
|
|
|
s->warn_none = 1;
|
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_rdynamic:
|
|
|
|
|
s->rdynamic = 1;
|
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_Wl:
|
2016-10-02 02:49:38 +08:00
|
|
|
|
if (linker_arg.size)
|
|
|
|
|
--linker_arg.size, cstr_ccat(&linker_arg, ',');
|
|
|
|
|
cstr_cat(&linker_arg, optarg, 0);
|
|
|
|
|
if (tcc_set_linker(s, linker_arg.data))
|
|
|
|
|
cstr_free(&linker_arg);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
break;
|
2019-01-11 21:26:17 +08:00
|
|
|
|
case TCC_OPTION_Wp:
|
|
|
|
|
r = optarg;
|
|
|
|
|
goto reparse;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
case TCC_OPTION_E:
|
2016-10-02 02:19:37 +08:00
|
|
|
|
x = TCC_OUTPUT_PREPROCESS;
|
|
|
|
|
goto set_output_type;
|
2015-03-03 19:19:14 +08:00
|
|
|
|
case TCC_OPTION_P:
|
|
|
|
|
s->Pflag = atoi(optarg) + 1;
|
|
|
|
|
break;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
case TCC_OPTION_MD:
|
|
|
|
|
s->gen_deps = 1;
|
|
|
|
|
break;
|
|
|
|
|
case TCC_OPTION_MF:
|
|
|
|
|
s->deps_outfile = tcc_strdup(optarg);
|
|
|
|
|
break;
|
2013-02-14 15:24:51 +08:00
|
|
|
|
case TCC_OPTION_dumpversion:
|
|
|
|
|
printf ("%s\n", TCC_VERSION);
|
|
|
|
|
exit(0);
|
2015-04-10 11:53:48 +08:00
|
|
|
|
break;
|
2015-04-12 20:35:37 +08:00
|
|
|
|
case TCC_OPTION_x:
|
2018-06-01 05:51:59 +08:00
|
|
|
|
x = 0;
|
2015-04-12 20:35:37 +08:00
|
|
|
|
if (*optarg == 'c')
|
2018-06-01 05:51:59 +08:00
|
|
|
|
x = AFF_TYPE_C;
|
2016-10-02 02:46:16 +08:00
|
|
|
|
else if (*optarg == 'a')
|
2018-06-01 05:51:59 +08:00
|
|
|
|
x = AFF_TYPE_ASMPP;
|
|
|
|
|
else if (*optarg == 'b')
|
|
|
|
|
x = AFF_TYPE_BIN;
|
2016-10-02 02:46:16 +08:00
|
|
|
|
else if (*optarg == 'n')
|
2018-06-01 05:51:59 +08:00
|
|
|
|
x = AFF_TYPE_NONE;
|
2015-04-12 20:35:37 +08:00
|
|
|
|
else
|
|
|
|
|
tcc_warning("unsupported language '%s'", optarg);
|
2018-06-01 05:51:59 +08:00
|
|
|
|
s->filetype = x | (s->filetype & ~AFF_TYPE_MASK);
|
2015-04-12 20:35:37 +08:00
|
|
|
|
break;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
case TCC_OPTION_O:
|
2016-10-18 02:50:54 +08:00
|
|
|
|
last_o = atoi(optarg);
|
2015-05-10 15:21:37 +08:00
|
|
|
|
break;
|
2017-02-18 16:55:34 +08:00
|
|
|
|
case TCC_OPTION_print_search_dirs:
|
|
|
|
|
x = OPT_PRINT_DIRS;
|
|
|
|
|
goto extra_action;
|
|
|
|
|
case TCC_OPTION_impdef:
|
|
|
|
|
x = OPT_IMPDEF;
|
|
|
|
|
goto extra_action;
|
|
|
|
|
case TCC_OPTION_ar:
|
|
|
|
|
x = OPT_AR;
|
|
|
|
|
extra_action:
|
|
|
|
|
arg_start = optind - 1;
|
|
|
|
|
if (arg_start != noaction)
|
|
|
|
|
tcc_error("cannot parse %s here", r);
|
|
|
|
|
tool = x;
|
|
|
|
|
break;
|
2016-10-02 02:54:45 +08:00
|
|
|
|
case TCC_OPTION_traditional:
|
2013-02-13 02:13:28 +08:00
|
|
|
|
case TCC_OPTION_pedantic:
|
|
|
|
|
case TCC_OPTION_pipe:
|
2016-10-02 02:48:01 +08:00
|
|
|
|
case TCC_OPTION_s:
|
2013-02-13 02:13:28 +08:00
|
|
|
|
/* ignored */
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2016-05-05 20:12:53 +08:00
|
|
|
|
unsupported_option:
|
|
|
|
|
if (s->warn_unsupported)
|
2013-02-13 02:13:28 +08:00
|
|
|
|
tcc_warning("unsupported option '%s'", r);
|
|
|
|
|
break;
|
|
|
|
|
}
|
tcc: Draft suppoprt for -MD/-MF options
In build systems, this is used to automatically collect target
dependencies, e.g.
---- 8< (hello.c) ----
#include "hello.h"
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
$ tcc -MD -c hello.c # -> hello.o, hello.d
$ cat hello.d
hello.o : \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
NOTE: gcc supports -MD only for .c -> .o, but in tcc, we generate
dependencies for whatever action is being taken. E.g. for .c -> exe, the
result will be:
$ tcc -MD -o hello hello.c # -> hello, hello.d
hello: \
/usr/lib/crt1.o \
/usr/lib/crti.o \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
/usr/lib/libc.so \
/lib/libc.so.6 \
/usr/lib/ld-linux.so.2 \
/lib/ld-linux.so.2 \
/usr/lib/libc_nonshared.a \
/lib/libc.so.6 \
/usr/lib/libc_nonshared.a \
/home/kirr/local/tcc/lib/tcc/libtcc1.a \
/usr/lib/crtn.o \
So tcc dependency generator is a bit more clever than one used in gcc :)
Also, I've updated TODO and Changelog (in not-yet-released section).
v2:
(Taking inputs from grischka and me myself)
- put code to generate deps file into a function.
- used tcc_fileextension() instead of open-coding
- generate deps only when compilation/preprocessing was successful
v3:
- use pstrcpy instead of snprintf(buf, sizeof(buf), "%s", ...)
2010-06-21 00:08:12 +08:00
|
|
|
|
}
|
2016-10-18 02:50:54 +08:00
|
|
|
|
if (last_o > 0)
|
|
|
|
|
tcc_define_symbol(s, "__OPTIMIZE__", NULL);
|
2016-10-02 02:49:38 +08:00
|
|
|
|
if (linker_arg.size) {
|
|
|
|
|
r = linker_arg.data;
|
|
|
|
|
goto arg_err;
|
2016-09-30 04:23:11 +08:00
|
|
|
|
}
|
2017-02-18 16:55:34 +08:00
|
|
|
|
*pargc = argc - arg_start;
|
|
|
|
|
*pargv = argv + arg_start;
|
|
|
|
|
if (tool)
|
|
|
|
|
return tool;
|
|
|
|
|
if (optind != noaction)
|
|
|
|
|
return 0;
|
|
|
|
|
if (s->verbose == 2)
|
|
|
|
|
return OPT_PRINT_DIRS;
|
|
|
|
|
if (s->verbose)
|
|
|
|
|
return OPT_V;
|
|
|
|
|
return OPT_HELP;
|
2013-02-13 02:13:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-18 16:55:34 +08:00
|
|
|
|
LIBTCCAPI void tcc_set_options(TCCState *s, const char *r)
|
2013-02-13 02:13:28 +08:00
|
|
|
|
{
|
2017-02-18 16:55:34 +08:00
|
|
|
|
char **argv = NULL;
|
|
|
|
|
int argc = 0;
|
|
|
|
|
args_parser_make_argv(r, &argc, &argv);
|
|
|
|
|
tcc_parse_args(s, &argc, &argv, 0);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
dynarray_reset(&argv, &argc);
|
tcc: Draft suppoprt for -MD/-MF options
In build systems, this is used to automatically collect target
dependencies, e.g.
---- 8< (hello.c) ----
#include "hello.h"
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
$ tcc -MD -c hello.c # -> hello.o, hello.d
$ cat hello.d
hello.o : \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
NOTE: gcc supports -MD only for .c -> .o, but in tcc, we generate
dependencies for whatever action is being taken. E.g. for .c -> exe, the
result will be:
$ tcc -MD -o hello hello.c # -> hello, hello.d
hello: \
/usr/lib/crt1.o \
/usr/lib/crti.o \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
/usr/lib/libc.so \
/lib/libc.so.6 \
/usr/lib/ld-linux.so.2 \
/lib/ld-linux.so.2 \
/usr/lib/libc_nonshared.a \
/lib/libc.so.6 \
/usr/lib/libc_nonshared.a \
/home/kirr/local/tcc/lib/tcc/libtcc1.a \
/usr/lib/crtn.o \
So tcc dependency generator is a bit more clever than one used in gcc :)
Also, I've updated TODO and Changelog (in not-yet-released section).
v2:
(Taking inputs from grischka and me myself)
- put code to generate deps file into a function.
- used tcc_fileextension() instead of open-coding
- generate deps only when compilation/preprocessing was successful
v3:
- use pstrcpy instead of snprintf(buf, sizeof(buf), "%s", ...)
2010-06-21 00:08:12 +08:00
|
|
|
|
}
|
2013-02-10 07:38:40 +08:00
|
|
|
|
|
2019-12-14 19:31:03 +08:00
|
|
|
|
PUB_FUNC void tcc_print_stats(TCCState *s1, unsigned total_time)
|
2013-02-10 07:38:40 +08:00
|
|
|
|
{
|
2016-10-18 05:24:01 +08:00
|
|
|
|
if (total_time < 1)
|
|
|
|
|
total_time = 1;
|
2013-02-10 07:38:40 +08:00
|
|
|
|
if (total_bytes < 1)
|
|
|
|
|
total_bytes = 1;
|
2017-02-18 16:55:34 +08:00
|
|
|
|
fprintf(stderr, "* %d idents, %d lines, %d bytes\n"
|
|
|
|
|
"* %0.3f s, %u lines/s, %0.1f MB/s\n",
|
2019-12-14 19:31:03 +08:00
|
|
|
|
total_idents, total_lines, total_bytes,
|
2016-10-18 05:24:01 +08:00
|
|
|
|
(double)total_time/1000,
|
|
|
|
|
(unsigned)total_lines*1000/total_time,
|
|
|
|
|
(double)total_bytes/1000/total_time);
|
2017-02-18 16:55:34 +08:00
|
|
|
|
#ifdef MEM_DEBUG
|
|
|
|
|
fprintf(stderr, "* %d bytes memory used\n", mem_max_size);
|
|
|
|
|
#endif
|
2013-02-10 07:38:40 +08:00
|
|
|
|
}
|