Commit Graph

1556 Commits

Author SHA1 Message Date
seyko
8764993c0d Makefile: install tcc$(EXESUF) as symlink to the $(ARCH)-tcc 2015-03-06 17:13:45 +03:00
seyko
65a4fbd1d4 Makefile: add dependencies for $($(I386_CROSS)_LINK), ...
This is another solution for the make process.
    Commit 4b92dbf923 is reverted.
2015-03-06 16:19:10 +03:00
Roy
883aafc6bb Makefile leftover of rev 44c6e99 2015-03-06 10:25:47 +08:00
seyko
d9b87c087c fixing decl_initializer() for size_only: don't eat ')'
a test program:

    struct { int c[1]; } s1[] = { (int)0       }; /* OK */
    struct { int c[1]; } s2[] = { { ((int)0) } }; /* OK */
    struct { int c[1]; } s3[] = { 0            }; /* OK */
    struct { int c[1]; } sx[] = { ((int)0)     }; /* error: ')' expected (got "}") */
    int main() { return 0; }
2015-03-05 20:18:25 +03:00
seyko
4b92dbf923 Add a dependency for a PROGS and TCCLIBS to a Makefile
Simply assume this is all *.c and *.h files in a tcc top directory.
    Now a tcc compiler is recompiled if any of this files is changed.
2015-03-05 16:39:25 +03:00
Roy
44c6e992bd Fix compiling in MinGW/MSYS 2015-03-05 09:12:42 +08:00
Edmund Grimley Evans
3fb8b14806 tccelf.c: File path component is "arm64", not "ARM64". 2015-03-04 19:43:29 +00:00
seyko
664c19ad5e partial revert of the commit 4ad186c5ef
A test program:

    /* result of the new version inroduced in 4ad186c5ef: t2a = 44100312 */
    #include<stdio.h>
    int main() {
	int t1 = 176401255;
	float f = 0.25f;
	int t2a = (int)(t1 * f); // must be 44100313
	int t2b = (int)(t1 * (float)0.25f);
	printf("t2a=%d t2b=%d \n",t2a,t2b);
	return 0;
    }
2015-03-04 16:25:51 +03:00
seyko
bfb7b0d959 --enable-tcc32-mingw option: build windows version on linux with i386-win-tcc
--enable-tcc64-mingw option: build windows version on linux with x86_64-win-tcc
2015-03-04 12:02:13 +03:00
seyko
48d12e42ad gcc options and mingw: move a gcc options detection from a makefile to the configure
+ define XCC and XAR if mingw32 defined
    + use XCC and XAR in lib/Makefile if defined
    Try "./configure --enable-mingw32; make". This must work
2015-03-04 11:47:52 +03:00
seyko
76af948623 install-clean-tuning
* Don't use /usr/local/lib/tcc/libtcc1.a for i386 and x86_64
      A $(tccdir)/i386 directory was used to install a libtcc1.a
      but only when cross compiling. And no x86_64 directory.

    * Build/install i386-tcc/x86_64-tcc and not a tcc
    * Build/install i386-win-tcc/x86_64-win-tcc and not a i386-win-mingw32-tcc/...
    * DEFINES = -DTCC_TARGET_I386... also for i386-tcc and i386-win-tcc
    * Make a symlink tcc to the i386-tcc/x86_64-tcc for a "make test"
    * Build a $(ARCH) directory with a symlink to the libtcc1.a for a "make test"
    * Remove a /usr/local/lib/tcc directory on uninstall
    * Remove a /usr/local/share/doc/tcc directory on uninstall
    * Remove a $(ARCH) directory on "make clean"
    * Remove a *-tcc files on "make clean"
2015-03-04 11:40:33 +03:00
seyko
54fc439e9e an unification of the tcc cross names for a windows
produce a
      i386-win-mingw32-tcc
      i386-win-tcc
      x86_64-win-mingw32-tcc
      x86_64-win-tcc
      arm-win-mingw32ce-tcc
      arm-win-tcc

    instead of the
      i386-w64-mingw32-tcc
      i386-win32-tcc
      x86_64-w64-mingw32-tcc
      x86_64-win32-tcc
      arm-wince-mingw32ce-tcc
      arm-win32-tcc

    Replacing a *-win32 directory names with a *-win names
    because this names are based on the names of the tcc
    	x86_64-win32-tcc, i386-win32-tcc
2015-03-04 11:19:39 +03:00
seyko
1cbb4d322b build-libtcc1-by-tcc: use a new tcc to compile a libtcc1.c and alloca.S
This will allow to build a libtcc1.a even if a bootstrap compiler
don't support a target arch.

There was alrady this feature but only for OS Darwin.
2015-03-04 11:08:16 +03:00
seyko
7ed4341538 a libraries paths
* x86_64-tcc: use /usr/lib64,.. instead of /usr/lib,..
    * don't set tcc_lddir="lib64" if cpu="x86"
    * put a definition of the CONFIG_LDDIR into config.h instead
      of the config.mak  Otherwise a "lib" string may be used by default.
      This is a usual case when building a x86_64-tcc (there was
      no -DCONFIG_LDDIR building this binary).

    * suppress -Wdeprecated-declarations for gcc which complain on malloc hooks
      in bcheck.c if glibc is quite new.
2015-03-04 10:57:13 +03:00
seyko
7ec39e2288 reverse a commit a6149c6dbb: Set CONFIG_MULTIARCHDIR for cross compilers.
Set CONFIG_MULTIARCHDIR for cross compilers.
    Chances a cross-compiler will find a working crt*.o
    in /usr/lib are more or less 0.

This commit breaks x86 / x86_64 compilres for linux. A solution for the crt*.o
must be discussed.
must be:
    # ./x86_64-tcc -vv
    tcc version 0.9.26 (x86-64, Linux)
    install: /usr/local/lib/tcc
    crt:
      /usr/lib64
    libraries:
      /usr/lib64
      /lib64
      /usr/local/lib64
    include:
      /usr/local/include
      /usr/include
      /usr/local/lib/tcc/include
    elfinterp:
      /lib64/ld-linux-x86-64.so.2

and with MULTIARCH we have:
    # ./x86_64-tcc -vv
    tcc version 0.9.26 (x86-64 Linux)
    install: /usr/local/lib/tcc/
    crt:
      /usr/lib/x86_64-linux-gnu ???????????????????
    libraries:
      /usr/lib/x86_64-linux-gnu
      /usr/lib                  ???????????????????
      /lib/x86_64-linux-gnu
      /lib                      ???????????????????
      /usr/local/lib/x86_64-linux-gnu
      /usr/local/lib            ???????????????????
    include:
      /usr/local/include/x86_64-linux-gnu
      /usr/local/include
      /usr/include/x86_64-linux-gnu
      /usr/include
      /usr/local/lib/tcc/include
    elfinterp:
      /lib64/ld-linux-x86-64.so.2

And CONFIG_MULTIARCHDIR don't handle C67.
On Linux x86 we have:
    # ./c67-tcc -vv
    tcc version 0.9.26 (C67, Linux)
    install: /usr/local/lib/tcc
    crt:
      /usr/lib
    libraries:
      /usr/lib
      /lib
      /usr/local/lib
    include:
      /usr/local/include
      /usr/include
      /usr/local/lib/tcc/include
    elfinterp:
      /lib/ld-linux.so.2
2015-03-04 10:50:33 +03:00
seyko
149c2a9cc9 a cpu option of the configure script as a method to specify a target cpu
* don't setup a cpu before scanning for --cpu=
    * --cpu= option sets a 'cpu' variable, not a 'build_cpu', 'build_cpu' was not used anywhere.
    * if cpu="" and ARCH != "" then cpu=$ARCH else cpu=`uname -m`
    * replace "Build CPU" with "Target CPU" in the output of the configure script.
      output this value only when not builing a cross compilers.
    * remove a HOST_I386, ... defines from a config.h file.
      thise defines are not used anywhere and cpu is now used to define a target cpu
2015-03-04 10:03:40 +03:00
seyko
d972472c53 Disable floating-point test for ARM soft-float
From: Matteo Cypriani <mcy@lm7.fr>
    Date: Fri, 5 Sep 2014 23:22:56 -0400
    Subject: Disable floating-point test for ARM soft-float

    tcc is not yet capable of doing softfloat floating-point operations on
    ARM, therefore we disable this test for these platforms. Note that tcc
    displays a warning to warn ARM users about this limitation
    (debian)
2015-03-04 09:52:47 +03:00
seyko
f1e4b2b7f3 disable-BTESTS 2015-03-04 09:49:19 +03:00
seyko
b8925960ec correct a DllMain() declaration in dllcrt1.c and dllmain.c
There is a DllMain() declaration in the mingw-runtime-4.0.3.1
and it differs from a tcc one.
2015-03-03 22:51:13 +03:00
seyko
7b96ddd045 win32/include/winsock2.h (look previous commit) 2015-03-03 22:45:50 +03:00
seyko
351e2ec334 add declaration of the "double trunc (double _x)" and winsock2.h
This allow to build a windows version of the nimrod compiler.
2015-03-03 22:41:55 +03:00
seyko
4b61f7f04b A lrint functions in win32/include/math.h are rewrittem because tcc can't handle "t" constraint 2015-03-03 22:38:31 +03:00
seyko
dfbb00c106 wincrt1.c: add definition of the __TRY__ if not defined
Some i686-pc-mingw32-gcc don't know about __TRY__
2015-03-03 22:35:33 +03:00
seyko
859ce5e47f Report a mingw as a execution environment instead of the
Win32, Win64, WinCE when executing "tcc -v". Example
	$ ./i386-win-tcc -v
	tcc version 0.9.26 (i386, mingw)
instead of the
	tcc version 0.9.26 (i386, Win32)

There is a cpu info already about bits of the excution environment
And display C67 for the TCC_TARGET_C67
2015-03-03 22:30:24 +03:00
seyko
2e6626a4b3 Don't add a slash to the install path of the tcc in display_info() 2015-03-03 21:41:22 +03:00
seyko
d70440b406 A 32/64 bit tcc on linux: an arch specific path for libtcc1.a
Don't use /usr/local/lib/tcc/libtcc1.a for i386 and x86_64
A $(tccdir)/i386 directory was used to install a libtcc1.a
but only when cross compiling. And no x86_64 directory.
And this directory location was unknown inside tccelf.c
2015-03-03 18:34:22 +03:00
seyko
43e4a406b4 Disable floating-point test for ARM soft-float
From: Matteo Cypriani <mcy@lm7.fr>
    Date: Fri, 5 Sep 2014 23:22:56 -0400
    Subject: Disable floating-point test for ARM soft-float

    tcc is not yet capable of doing softfloat floating-point operations on
    ARM, therefore we disable this test for these platforms. Note that tcc
    displays a warning to warn ARM users about this limitation
    (debian)
2015-03-03 17:28:13 +03:00
seyko
774f0611cc arm-unused-warnings: remove problems with defined but unused wariables
arm-gen.c: In function `gfunc_call':
	arm-gen.c:1202: warning: unused variable `variadic'
	arm-gen.c: In function `gfunc_prolog':
	arm-gen.c:1258: warning: unused variable `avregs'
	arm-gen.c:1340: warning: label `from_stack' defined but not used
	arm-gen.c:222: warning: 'default_elfinterp' defined but not used
2015-03-03 17:16:52 +03:00
seyko
6cbf4fb740 tcc_add_runtime() for a CONFIG_USE_LIBGCC case: reducing a complexity 2015-03-03 17:11:18 +03:00
seyko
cd4f3d962d x86_64-win-tcc elfinterp: a bug correction
./x86_64-win-tcc -vv
Before
	elfinterp:
	  /lib64/ld-linux-x86-64.so.2
After
	elfinterp:
	  -
This output is identical to the output of the i386-win-tcc
2015-03-03 17:05:44 +03:00
seyko
2d83ec7aa3 lddir-on-x86-64: let CONFIG_LDDIR=lib64 by default if TCC_TARGET_X86_64
This is done for the case when CONFIG_LDDIR is not configured. Example:
./configure --enable-cross
2015-03-03 16:37:44 +03:00
seyko
b5f88b593a Turn on a implicit-function-declaration warning by default.
A non declared function leads to a seriuos problems. And while
gcc don't turn this warning on lets tcc do it. This warning
can be turned off by -Wno-implicit-function-declaration option.
And autor must explicitly do this if program must be compiled
with this warning off.
2015-03-03 16:32:25 +03:00
seyko
7f36abd3f2 x86_64-tcc and libtcc1.c: size_t definition is needed for a x86_64-tcc to parse memset() 2015-03-03 16:29:00 +03:00
seyko
e374a733d6 -std=c99 option for the tcc: allow to use a tcc as a reference compiler for "make test"
tcc will igmore this option.
2015-03-03 16:25:02 +03:00
seyko
4c8ffb353d remove a gcc warning for bcheck on x86_64 arch: conversion to pointer from integer of different size 2015-03-03 16:18:24 +03:00
seyko
20074d8862 Use a display_info() to output a header of the tcc help listing
tcc version 0.9.26 (i386 Linux)
    Tiny C Compiler - Copyright (C) 2001-2006 Fabrice Bellard
    Usage: tcc [options...] [-o outfile] [-c] infile(s)...
	   tcc [options...] -run infile [arguments...]
    ...

instead of the

    tcc version 0.9.26 - Tiny C Compiler - Copyright (C) 2001-2006 Fabrice Bellard
    Usage: tcc [options...] [-o outfile] [-c] infile(s)...
	   tcc [options...] -run infile [arguments...]
    ...

Displaing a "Hard Float" info for the ARM arch is restored. It was broken by the AArm64 patch.
2015-03-03 16:08:33 +03:00
seyko
2437ccdc76 A partial reverse for commit eda2c756ed
Author: Thomas Preud'homme <robotux@celest.fr>
	Date:   Tue Dec 31 23:51:20 2013 +0800

	Move logic for if (int value) to tccgen.c
	Move the logic to do a test of an integer value (ex if (0)) out of
	arch-specific code to tccgen.c to avoid code duplication. This also
        fixes test of long long value which was only testing the bottom half of
	such values on 32 bits architectures.

I don't understand why if () in gtst(i) was removed.
This patch allows to compile a linux kernel v.2.4.26
W/o this patch a tcc simply crashes.
2015-03-03 15:51:09 +03:00
seyko
c45a8695eb A reverse of the commit 14745bdeb because of the problems while compiling linux 2.4.26
A test program:
    ///////////
    typedef unsigned int __u32;
    static inline const __u32 __fswab32(__u32 x)
    {
	return ({ __u32 __tmp = (x) ; ___swab32(__tmp); });
    }
    void func()
    {
	int aaa = 1;
	int snd_wnd = 2;
	int TCP_FLAG_ACK = 3;
	int pred_flags = (__builtin_constant_p((__u32)
	    (((aaa << 26) |
	    (__builtin_constant_p((__u32)((TCP_FLAG_ACK))) ?
		({ __u32 __x = (((TCP_FLAG_ACK))); ((__u32)( (((__u32)(__x) & (__u32)0x000000ffUL) << 24) | (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | (((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); }) : __fswab32(((TCP_FLAG_ACK)))) | snd_wnd))) ? ({ __u32 __x = ((((aaa << 26) | (__builtin_constant_p((__u32)((TCP_FLAG_ACK))) ? ({ __u32 __x = (((TCP_FLAG_ACK))); ((__u32)( (((__u32)(__x) & (__u32)0x000000ffUL) << 24) | (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | (((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); }) : __fswab32(((TCP_FLAG_ACK)))) | snd_wnd))); ((__u32)( (((__u32)(__x) & (__u32)0x000000ffUL) << 24) | (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | (((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); }) : __fswab32((((aaa << 26) | (__builtin_constant_p((__u32)((TCP_FLAG_ACK))) ? ({ __u32 __x = (((TCP_FLAG_ACK))); ((__u32)( (((__u32)(__x) & (__u32)0x000000ffUL) << 24) | (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | (((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); })
		: __fswab32(((TCP_FLAG_ACK)))) | snd_wnd))));
    }
    ////////////
error: ';' expected (got "(")
2015-03-03 15:44:29 +03:00
seyko
6fd4e5bace a void to void cast.
Allow tcc to compile the following program
    ///////
	void func1() {}
	void func2() {
	  return func1();
	}
    //////
gcc accepts this program
2015-03-03 15:39:57 +03:00
seyko
09feeca5df a statement expressions with a pointer return type
A test program:
    //////////////
    int main()
    {
	void *p = ({ 0 ; ((void *)1); });
    }
    /////////////
Porblem is introduced in a commit a80acab: Display error on statement expressions with complex return type
This error is exposed when compiling a linux 2.4.26. tcc 0.9.23 can sucessfully compile
this version of the linux.
2015-03-03 15:29:14 +03:00
seyko
1a1e9548fb iitialisation of the empty struct
Current tcc don't understand an initialization of the empty struct
This problem was found trying to compile a linux kernel 2.4.26
which can be compiled by tcc 0.9.23

  A test program:
  ////////////////////
  // ./tcc -c test_3.c
  // test_3.c:31: error: too many field init
  #undef __GNUC__
  #undef __GNUC_MINOR__
  #define __GNUC__  2
  #define __GNUC_MINOR__ 95
  typedef struct { } rwlock_t;
  struct fs_struct {
   int count;
   rwlock_t lock;
   int umask;
  };
  #define INIT_FS { \
	1, \
	RW_LOCK_UNLOCKED, \
	0022, \
  }
  #if (__GNUC__ > 2 || __GNUC_MINOR__ > 91)
    typedef struct { } rwlock_t;
    #define RW_LOCK_UNLOCKED (rwlock_t) { }
  #else
    typedef struct { int gcc_is_buggy; } rwlock_t;
    #define RW_LOCK_UNLOCKED (rwlock_t) { 0 }
  #endif
  static struct fs_struct init_fs = INIT_FS;
  // static struct fs_struct init_fs = { { (1) }, (rwlock_t) { 0 }, 0022, };
  //                                                           ^ with this all Ok
  // static struct fs_struct init_fs = { { (1) }, (rwlock_t) { }, 0022, };
  //                                                          ^ current tcc don't understand, but tcc 0.9.23 can
  int main()
  {
    return 0;
  }
  ////////////////////
  A regression is detected after a patch 69fdb57edd
  ////////////////////
  // A test for patch 69fdb57edd
  // Author: grischka <grischka>
  // Date:   Wed Jun 17 02:09:07 2009 +0200
  //     unions: initzialize only one field
  //         struct {
  //           union {
  //             int a,b;
  //           };
  //           int c;
  //         } sss = { 1,2 };
  //     This had previously assigned 1,2 to a,b and 0 to c which is wrong.
  //
  // Expected: sss.a=1 sss.b=1 sss.c=2
  int main()
  {
    struct {
      union {
        int a,b;
      };
      int c;
    } sss = { 1, 2 };

    printf ("sss.a=%d sss.b=%d sss.c=%d\n", sss.a, sss.b, sss.c);
    return 0;
  }
  ////////////////////
2015-03-03 15:15:48 +03:00
seyko
bbf8221ec3 tcc don't understand am extern array of structs.
A regression was found trying to compile a linux kernel 2.4.26
  which can be compiled by tcc 0.9.23

    ///////////////////
    #include <stdio.h>

    // test for a bug:
    // compiler don't understand am extern array of structs
    // $ tcc test_1.c
    // test_1.c:8: error: unknown struct/union/enum

    extern struct FILE std_files[4];

    int main()
    {
	return 0;
    }
    //////////////////

  tcc-current
  /* enum/struct/union declaration. u is either VT_ENUM or VT_STRUCT */
  static void struct_decl(CType *type, int u, int tdef)
  ...
    if (tok != '{') {
        v = tok;
        next();
        /* struct already defined ? return it */
        if (v < TOK_IDENT)
            expect("struct/union/enum name");
        s = struct_find(v);
        if (s) {
            if (s->type.t != a)
                tcc_error("invalid type");
            goto do_decl;
        } else if (tok >= TOK_IDENT && !tdef)
            tcc_error("unknown struct/union/enum");
    } else {
        v = anon_sym++;
    }

  tcc-0.9.23 which don't have such error
  /* enum/struct/union declaration. u is either VT_ENUM or VT_STRUCT */
  static void struct_decl(CType *type, int u)
  ....
    if (tok != '{') {
        v = tok;
        next();
        /* struct already defined ? return it */
        if (v < TOK_IDENT)
            expect("struct/union/enum name");
        s = struct_find(v);
        if (s) {
            if (s->type.t != a)
                error("invalid type");
            goto do_decl;
        }
    } else {
        v = anon_sym++;
    }
2015-03-03 15:00:13 +03:00
seyko
a429d40f06 tcc_free(table_ident) in preprocess_new() if table_ident != NULL 2015-03-03 14:54:46 +03:00
seyko
e2a8fd4520 tcc_undefine_symbol(): free an alloced symbol 2015-03-03 14:50:41 +03:00
seyko
8d10c5788f Add a debug info when a #line directive is handled.
The problem was: a debug info for the file which contain a #line
directive (for example a preprocessed one) was wrong.
2015-03-03 14:46:44 +03:00
seyko
09d4e4f408 Revert a grischka patch: gdb refused to know "main"
It is a strange patch because before this commit a gdb is working well
and after this commit there is exactly the same problem on Linux:
gdb refuses to know "main"

    Author: grischka <grischka>
    Date:   Tue Feb 5 21:18:29 2013 +0100
    tccelf: fix debug section relocation
    With:
       tcc -g hello.c
       gdb a.out
         b main
    gdb refused to know "main" because of broken dwarf info.
2015-03-03 14:39:27 +03:00
seyko
252a151fc6 pp-many-files: don't drop a preprocessor defines when tcc going to preprocess a next file
in the same pass like
    tcc -E one.c two.c three.c -o combined.i
This will allow to speed up a compilation process by using a commamd like
    tcc -E *.c | tcc -o program.exe -xc -

It looks that multi-times initialization don't affect anything.
Only call to the free_defines(define_start) in tcc_preprocess()
is removed in assumption that free_defines(NULL) in
tcc_cleanup() will free all defines.
2015-03-03 14:31:47 +03:00
seyko
b7b9f9f511 A gcc preprocessor option -dD added
With this option on a defines are included into the output
(inside comments). This will allow to debug a problems like:

    In file included from math.c:8:
    In file included from /usr/include/math.h:43:
    /usr/include/bits/nan.h:52: warning: NAN redefined
2015-03-03 14:25:57 +03:00
seyko
50cdccf3ef Added a gcc preprocessor options -P, -P1
tcc -E -P
  do not output a #line directive, a gcc compatible option

tcc -E -P1
  don't follow a gcc preprocessor style and do output a standard
  #line directive. In such case we don't lose a location info when
  we going to compile a resulting file wtith a compiler not
  understanding a gnu style line info.
2015-03-03 14:19:14 +03:00
seyko
40418f87c7 Move a line_ref variable from tcc_preprocess() function into struct BufferedFile.
This id needed for a right ouput in other places,
precisely to calculate a number of empty lines which are waiting to output.
2015-03-03 14:15:28 +03:00