Commit Graph

299 Commits (da8c62f75d893449e232944fc62566c020b4d010)

Author SHA1 Message Date
Avi Halachmi (:avih) acbab220c8 win: fix dir comparison during include dirs processing
Use native Windows API via wrapper with stat-like API.
2015-11-08 03:56:25 +02:00
seyko a6276b7a78 normalize inc dirs, symplify include_next
include dirs are prepared as in gcc
    - for each duplicate path keep just the first one
    - remove each include_path that exists in sysinclude_paths

    include_next streamlined by introducing inc_path_index
    in the BufferedFile
2015-11-05 19:52:49 +03:00
Kamil Rytarowski 6cb74ecacf Define __WINT_TYPE__ as int in NetBSD 2015-10-11 11:59:20 +02:00
Kamil Rytarowski 5860b639c6 Add support for -D__NetBSD__ 2015-10-11 03:12:35 +02:00
gus knight 89ad24e7d6 Revert all of my changes to directories & codingstyle. 2015-07-29 16:57:12 -04:00
gus knight 47e06c6d4e Reorganize the source tree.
* Documentation is now in "docs".
 * Source code is now in "src".
 * Misc. fixes here and there so that everything still works.

I think I got everything in this commit, but I only tested this
on Linux (Make) and Windows (CMake), so I might've messed
something up on other platforms...
2015-07-27 16:03:25 -04:00
gus knight d6b64e2574 Clean up lots of rogue tabs.
Still some more tabs to be taken care of. arm-gen.c and tcccoff.c
have so many style issues that I'm just going to throw clang-format
at them.
2015-07-27 14:14:41 -04:00
gus knight 41031221c8 Trim trailing spaces everywhere. 2015-07-27 12:43:40 -04:00
seyko 80322adaa0 redo of the -dD option
functionality was broken some time ago and was removed
    by the "tccpp: fix issues, add tests"

    fix: LINE_MACRO_OUTPUT_FORMAT_NONE in pp_line()
    means: output '\n' and not "don't output at all"
2015-05-13 12:16:00 +03:00
seyko cf92f7aacb some -bench fixes
print stats to stderr, not to stdout
2015-05-12 22:02:51 +03:00
seyko 06e0753fce minor pp optimizations
* remove free_defines() from tcc_preprocess()
        all cleanup will be done in tcc_delete
    * move a preprocessor file closing to tcc_delete too
2015-05-12 21:32:32 +03:00
seyko 1234beccb8 restore a max memory usage printing for a new MEM_DEBUG when -bench 2015-05-12 16:07:09 +03:00
seyko 121e95d115 a new version of the MEM_DEBUG 2015-05-12 11:56:39 +03:00
seyko ae09051c81 allow to use MEM_DEBUG with libtcc 2015-05-11 18:05:31 +03:00
seyko cb7e820eae tcc_add_dll is not used if TCC_TARGET_PE
after "tccpp: fix issues, add tests"
2015-05-10 11:37:36 +03:00
seyko ff06d4258e define __OPTIMIZE__ if -ON (N != 0)
this is gcc behaviour
2015-05-10 10:21:37 +03:00
seyko c497f9c82c warn if multile -o option is given 2015-05-10 10:13:35 +03:00
grischka 30df3189b1 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
    a3fc543459
    a715d7143d
    (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 14:29:39 +02:00
seyko fca58734fb -traditional and -iwithprefix options 2015-05-03 20:10:57 +03:00
seyko 576aeb3aa9 fix "tcc test.c -Wl,,--oformat,binary"
set linker options only when "s->output_type == TCC_OUTPUT_EXE"
    otherwise tcc will produce a wrong object file
2015-05-03 14:17:18 +03:00
seyko 2ba219f781 fix "tcc test.c -UAAA -UBBB"
no need to call tcc_free() inside tcc_undefine_symbol()
    Otherwise we get segmentation fault inside tcc_delete()
2015-05-03 13:58:27 +03:00
seyko bbcb54a1f4 replace PARSE_FLAG_ASM_COMMENTS with PARSE_FLAG_ASM_FILE
after "assign PARSE_FLAG_ASM_COMMENTS only for asm files"
    functions of this flags are identical
2015-04-27 16:36:58 +03:00
seyko 2df290073b preprocess: "assign PARSE_FLAG_ASM_COMMENTS only for asm files"
resolve a problem with the following test.c program, tcc -E test.c

    #ifdef	_XOPEN_SOURCE
    # define __USE_XOPEN	1
    # if (_XOPEN_SOURCE - 0) >= 500
    #  define __USE_XOPEN_EXTENDED	1
    #  define __USE_UNIX98	1
    #  undef _LARGEFILE_SOURCE
    #  define _LARGEFILE_SOURCE	1
    #  if (_XOPEN_SOURCE - 0) >= 600
    #   define __USE_XOPEN2K	1
    #   undef __USE_ISOC99
    #   define __USE_ISOC99		1
    #  endif
    # else
    #  ifdef _XOPEN_SOURCE_EXTENDED
    #   define __USE_XOPEN_EXTENDED	1
    #  endif
    # endif
    #endif

    int main() {}

    // # 17 "aaa.c"
    // aaa.c:17: error: #endif without matching #if
2015-04-27 15:25:49 +03:00
seyko b472d53672 clarify error message when library not found
a prior error message: cannot find 'program_resolve_lib'
    after a patch: cannot find library 'libprogram_resolve_lib'
2015-04-16 07:30:24 +03:00
Steven G. Messervey aeaff94ec1 implement #pragma comment(lib,...) 2015-04-15 22:56:21 -04:00
Steven G. Messervey e50d68e417 Revert "implement #pragma comment(lib,...)"
This reverts commit 8615bb40fb.

Reverting as it breaks on MinGW targets
2015-04-15 21:24:15 -04:00
Steven G. Messervey 8615bb40fb implement #pragma comment(lib,...) 2015-04-15 17:00:26 -04:00
seyko 0536407204 ability to specify a type of the input file with the -x switch
Usage example: tcc -xc ex5.cgi
    From a gcc docs:

    You can specify the input language explicitly with the -x option:

    -x language
    Specify explicitly the language for the following input files
    (rather than letting the compiler choose a default based on the file
    name suffix). This option applies to all following input files until
    the next -x option. Possible values for language are:

        c  c-header  c-cpp-output
        c++  c++-header  c++-cpp-output
        objective-c  objective-c-header  objective-c-cpp-output
        objective-c++ objective-c++-header objective-c++-cpp-output
        assembler  assembler-with-cpp
        ada
        f77  f77-cpp-input f95  f95-cpp-input
        java

    -x none
    Turn off any specification of a language, so that subsequent files
    are handled according to their file name suffixes (as they are if -x
    has not been used at all)
2015-04-12 15:35:37 +03:00
seyko dcb36587b5 -fdollar-in-identifiers switch which enables '$' in identifiers
library Cello: http://libcello.org/ which uses `$` and several
    variations of as macros.

    There is also RayLanguage which also uses it as a macro for a kind of
    ObjC style message passing: https://github.com/kojiba/RayLanguage

    This is a patch from Daniel Holden.
2015-04-12 15:32:03 +03:00
seyko e7a60e4d01 replace a method to force bcheck.o linking
* define __bound_init as external_global_sym insteed of the compiling
      a tiny program
    * remove warning about buf[] when CONFIG_TCC_BCHECK is not defined
2015-04-12 04:47:15 +03:00
seyko 4bb9dd44f1 Fix for Microsoft compilers
Correction for the commit db08122d31
    As pointed Thomas Preud'homme buf[] may be used outside of the block
    whit code:
        name = block;
2015-04-11 16:22:34 +03:00
seyko 5c9dde7255 option to use an old algorithm of the array in struct initialization
This is for a case when no '{' is used in the initialization code.
    An option name is -fold-struct-init-code. A linux 2.4.26 can't
    find initrd when compiled with a new algorithm.
2015-04-10 23:44:10 +03:00
seyko d81611b641 fix a preprocessor for .S
Lets assume that in *.S files a preprocessor directive
    follow '#' char w/o spaces between. Otherwise there is
    too many problems with the content of the comments.
2015-04-10 16:53:29 +03:00
seyko 70dbe169b2 fix a preprocessor for .S
* tell a right line number in error message
      if a #line directive is wrong

    * don't print an error message if we preprocess a .S file
      and #line directive is wrong. This is the case of
      the
        # 4026 bytes
      comment in *.S file.

    * preprocess_skip: skip a line with
	    if (parse_flags & PARSE_FLAG_ASM_COMMENTS)
       		p = parse_line_comment(p);
      if line starts with # and a preprocessor command not found.

      A test program:
      #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
	# This repeats until either a device doesn't exist, or until
      #endif

    * remove a second definition of the TOK_FLAG_* and PARSE_FLAG_*
      from the tccpp.c
2015-04-10 16:31:12 +03:00
seyko 7e7e6148fd fix installation amd bcheck for Windows
* define targetos=Windows when --enable-tcc32-mingw, --enable-cygwin, ...
    * use TARGETOS insteed HOST_OS when selecting PROGS
    * use "$(tccdir)" insteed $(tccdir) on install (spaces in path)
    * install tcc.exe too
    * produce bcheck.o when cross-compiling too (lib/Makefile)
    * force bcheck.o linking by compiling inside tcc_set_output_type()
      a dummy program with local array. Otherwise bcheck.o may be not linked.
    * replace %xz format specifier with %p in bcheck (don't supported on
      Windows)
    * call a __bound_init when __bound_ptr_add, __bound_ptr_indir,
      __bound_new_region, __bound_delete_region called.
      This is because a __bound_init inside ".init" section is not called
      on Windows for unknown reason.
    * print on stderr a message when an illegal pointer is returned:
        there is no segmentation violation on Windows for a program
        compiled with "tcc -b"
    * remove "C:" subdir on clean if $HOST_OS = "Linux"
    * default CFLAGS="-Wall -g -O0" insteed CFLAGS="-Wall -g -O2"
      to speed up compilation and more precise debugging.
2015-04-10 07:37:31 +03:00
seyko 5cd4393a54 handle a -s option by executing sstrip/strip program 2015-04-10 06:53:48 +03:00
seyko dec959358a fix the bug #31403: parser bug in structure
- a warning: unnamed struct/union that defines no instances
    - allow a nested named struct declaration w/o identifier
      only when option -fms-extensions is used
2015-04-10 06:31:58 +03:00
seyko db08122d31 Fix for Microsoft compilers
Miccrosoft Visual Sudio (Express) 2008 and 2010 do not accept variable
    definitions C99 style, reported by Fabio <oldfaber@gmail.com>
2015-03-29 11:52:16 +03:00
seyko 3b7f5008fd fix for the previous commit (compilation on RPi) 2015-03-26 11:28:11 +03:00
seyko acef4ff244 make a bound checking more compatible with Windows 64
On Linux 32:   sizeof(long)=32 == sizeof(void *)=32
    on Linux 64:   sizeof(long)=64 == sizeof(void *)=64
    on Windows 64: sizeof(long)=32 != sizeof(void *)=64
2015-03-26 07:47:45 +03:00
seyko 724425addf fix for a -dumpversion option: move it before -dD
Options must be sorted and a long one must preceed a short one.
What was before:
    tcc -dumpversion
    tcc: error: invalid option -- '-dumpversion'
2015-03-23 20:58:27 +03:00
seyko 8f6390061d fix for: x86_64-tcc compiled by i386-tcc is wrong
A test program (must be compiled by the above version of the tcc):

    /* Tickle a bug in TinyC on 64-bit systems:
     * the LSB of the top word or ARGP gets set
     * for no obvious reason.
     *
     * Source: a legacy language interpreter which
     * has a little stack / stack pointer for arguments.
     *
     * Output is: 0x8049620 0x10804961c
     * Should be: 0x8049620 0x804961c
     */
    #include <stdio.h>
    #define NARGS 20000
    int ARG[NARGS];
    int *ARGSPACE = ARG;
    int *ARGP = ARG - 1;
    main() { printf("%p %p\n", ARGSPACE, ARGP); }
2015-03-23 19:24:55 +03:00
seyko e2650608cd fix to allow build tcc by build-tcc.bat
move call to print_defines() from tcc.c to the libtcc.c
    define a print_defines() as a ST_FUNC
2015-03-19 08:07:35 +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 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 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 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 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
Edmund Grimley Evans b14ef0e24b Add arm64 (AArch64) as a target architecture. 2015-02-23 22:51:03 +00:00
Edmund Grimley Evans 738606dbd5 Use RELA relocations properly for R_DATA_PTR on x86_64.
libtcc.c: Add greloca, a generalisation of greloc that takes an addend.
tcc.h: Add greloca and put_elf_reloca.
tccelf.c: Add put_elf_reloca, a generalisation of put_elf_reloc.
tccgen.c: On x86_64, use greloca instead of greloc in init_putv.
2015-02-21 21:29:03 +00:00
seyko c334b59142 Warn about a conflicting compile options spectified on the command line.
Try "tcc -E -c tccasm.c -o tccasm.o"
2015-01-06 22:19:45 +03:00
seyko b93179f3c0 .i as file extension
Add a ".i" extension as alias for ".c"
 GCC and file extensions:
 .i C source code which should not be preprocessed.

Before a patch:
 ./tcc -E tccasm.c -o tccasm.i
 ./tcc -c tccasm.i -o tccasm.o
 tccasm.i:1: error: unrecognized file type
2015-01-06 16:01:41 +03:00
Lee Duhem f1703e2b2f libtcc.c (put_extern_sym2): Extend the scope of buf to match its use
After leaving the code block that `buf' is defined, `buf' will not
exist, so `name' will point to a variable that does not exist.
2014-12-11 10:04:22 +08:00
grischka 14745bdeb7 tccgen: nocode_wanted: do not output constants
This for example suppresses string constants such as with

    int main()
    {
        return sizeof "foo";
    }

Actually, setting

    nocode_wanted = 1;

in libtcc.c for the initial global level seemed wrong, since
obviously "nocode_wanted" means code as any side effects, also
such as string constants.

This reverts a part of 2de1b2d14c
(documented as "Some in-between fixes" in Changelog)
2014-08-01 10:59:38 +02:00
grischka 6e0a658e96 win64: try to fix linkage
- revert to R_X86_64_PC32 for near calls on PE
- revert to s1->section_align set to zero by default

Untested. Compared to release_0_9_26 the pe-image looks back to
normal.  There are some differences in dissassembly (r10/r11 usage)
but maybe that's ok.
2014-06-24 22:09:12 -04:00
grischka 2ac238fc50 tccpe: adjust for new 'hidden' symbols feature
in order to avoid conflicts with windows specific (ab)usage
of the Elf32_Sym -> st_other field.
2014-04-17 17:01:28 +02:00
Michael Matz a9fda392a0 Parse assembler .hidden directive
This makes TCCs assembler understand the '.hidden symbol' directive
(and emits a STV_HIDDEN ELF symbol then).
2014-04-14 03:33:50 +02:00
minux df0267b287 tcc, libtcc: fix build on windows with latest mingw. 2014-04-11 23:49:53 -04:00
grischka f90bad0925 tests2: cleanup
- remove -norunsrc switch
  Meaning and usage (-run -norun...???) look sort of screwed.  Also
  general usefulness is unclear, so it was actually to support exactly
  one (not even very interesting) test

This partially reverts e31579b076
2014-04-07 11:20:45 +02:00
Michael Matz 0961a38493 Declare wint_t in <stddef.h> when needed
Some old glibcs <wctype.h> require <stddef.h> to provide
wint_t, accomodate them.
2014-04-07 00:27:46 +02:00
mingodad 700c2f769b Remove the fix from my last commit, it was pointed by scan-build and is a false positive, thanks to grischka for pointing it. 2014-03-28 20:25:39 +00:00
mingodad 14bb8302c4 Fix a incorrect size for malloc. 2014-03-27 22:15:45 +00:00
mingodad ad9568060e A possible fix for the memory leak reported by valgrind when running tcctest.c with tcc. 2014-03-25 18:06:14 +00:00
Austin English ba286136bf libtcc: ignore linker optizimization and as-needed options. This allows compiling some packages from Gentoo's portage 2014-03-06 12:29:19 -08:00
Thomas Preud'homme b6247d1f3c Add support for runtime selection of float ABI 2014-01-08 15:00:52 +08:00
grischka 3fe2a95d7f be stricter with aliasing
Refactoring (no logical changes):
- use memcpy in tccgen.c:ieee_finite(double d)
- use union to store attribute flags in Sym
Makefile: "CFLAGS+=-fno-strict-aliasing" basically not necessary
anymore but I left it for now because gcc sometimes behaves
unexpectedly without.

Also:
- configure: back to mode 100755
- tcc.h: remove unused variables tdata/tbss_section
- x86_64-gen.c: adjust gfunc_sret for prototype
2014-01-07 14:57:07 +01:00
grischka 2bd0daabbe misc. fixes
- tccgen: error out for cast to void, as in
      void foo(void) { return 1; }
  This avoids an assertion failure in x86_64-gen.c, also.
  also fix tests2/03_struct.c accordingly

- Error: "memory full" - be more specific

- Makefiles: remove circular dependencies, lookup tcctest.c from VPATH

- tcc.h: cleanup lib, include, crt and libgcc search paths"
  avoid duplication or trailing slashes with no CONFIG_MULTIARCHDIR
  (as from 9382d6f1a0)

- tcc.h: remove ";{B}" from PE search path
  in ce5e12c2f9 James Lyon wrote:
  "... I'm not sure this is the right way to fix this problem."
  And the answer is: No, please. (copying libtcc1.a for tests instead)

- win32/build_tcc.bat: do not move away a versioned file
2014-01-06 19:56:26 +01:00
Thomas Preud'homme 3676f61983 Define __ARM_EABI__ and __ARMEL__ when applicable 2013-11-26 12:06:21 +08:00
Joseph Poirier 0650ab01c8 struct variable behind guard, proper macro check, and remove some whitespace.
Wrap runtime_main as per its declaration in tcc.h.
Fix preprocessor check for TCC_ARM_EABI macro definition.

Signed-off-by: Joseph Poirier <jdpoirier@gmail.com>
2013-11-08 13:24:15 -06:00
Thomas Preud'homme cf02f920c1 Revert "Add support for thread-local storage variables"
TLS support in tinyCC is absolutely not ready:
- segment register not select in load and store
- no relocation added for computing offset of per-thread symbol
- no support for TLS-specific relocations
- no program header added as per Drepper document about TLS

This reverts commit 1c4afd1350.
2013-11-03 18:55:54 +08:00
Thomas Preud'homme 1c4afd1350 Add support for thread-local storage variables 2013-10-29 22:10:02 +08:00
Vittorio Giovara 45b35a3d66 set the user-defined library search paths first 2013-09-23 09:40:06 +02:00
grischka 73faaea227 i386-gen: preserve fp control word in gen_cvt_ftoi
- Use runtime function for conversion
- Also initialize fp with tcc -run on windows

This fixes a bug where
  double x = 1.0;
  double y = 1.0000000000000001;
  double z = x < y ? 0 : sqrt (x*x - y*y);
caused a bad sqrt because rounding precision for the x < y comparison
was different to the one used within the sqrt function.

This also fixes a bug where
  printf("%d, %d", (int)pow(10, 2), (int)pow(10, 2));
would print
  100, 99

Unrelated:
  win32: document relative include & lib lookup
  win32: normalize_slashes: do not mirror silly gcc behavior
  This reverts part of commit 8a81f9e103
  winapi: add missing WINAPI decl. for some functions
2013-08-28 22:55:05 +02:00
Thomas Preud'homme 37b0348993 Define __ARM_PCS_VFP in hardfloat compilation mode 2013-06-15 00:26:07 +02:00
James Lyon 1caee8ab3b Sorted out CMake on x86-64 and fixed silly XMM# bug introduced when working on Win64 stdargs.
I removed the XMM6/7 registers from the register list because they are not used
on Win64 however they are necessary for parameter passing on x86-64. I have now
restored them but not marked them with RC_FLOAT so they will not be used except
for parameter passing.
2013-04-25 22:30:53 +01:00
James Lyon 8a81f9e103 Added CMake build system (to facilitate Win64 builds)
Win32 build and tests work under CMake, however I haven't added
install code yet. Win64 build fails due to chkstk.S failing to
assemble.
2013-04-21 11:20:20 +01:00
James Lyon e31579b076 Fixed tests on Windows (including out-of-tree problems)
Modified tcctest.c so that it uses 'double' in place of 'long double'
with MinGW since this is what TCC does, and what Visual C++ does. Added
an option -norunsrc to tcc to allow argv[0] to be set independently of
the compiled source when using tcc -run, which allows tests that rely on
the value of argv[0] to work in out-of-tree builds.

Also added Makefile rules to automatically update out-of-tree build
Makefiles when in-tree Makefiles have changed.
2013-04-17 20:32:07 +01:00
Urs Janssen 183b2ab14c don't confuse LD_LIBRARY_PATH (run time) with LIBRARY_PATH (link time) 2013-02-19 14:41:58 +01:00
Andrew Aladjev 0ad857c80e added CPATH, C_INCLUDE_PATH and LD_LIBRARY_PATH 2013-02-19 14:47:36 +03:00
Urs Janssen 0db7f616ad remove doubled prototype
fix documentation about __TINYC__
define __STDC_HOSTED__ like __STDC__
2013-02-18 15:44:18 +01:00
Roy 322743eef8 libtcc: tcc_define_symbol() uses strings, fix segfault 2013-02-18 08:32:03 +08:00
Thomas Preud'homme 3ad64ffe2e Define __STDC_HOSTED__ to a sane value
Define __STDC_HOSTED__ to one as the correct values should be either 1
or 0. Since tinycc is hosted, it should be set to 1.

Thanks Christian Jullien for the report.
2013-02-17 22:13:41 +01:00
Thomas Preud'homme fe64a4d005 Define __STDC_HOSTED__
Quoting Michael Matz on tinycc-devel:

"__STDC_HOSTED__  : not set (incorrectly, it should probably be set to 1
                    given that tcc assumes a normal main() and that the
                    rest of the provided facilities is provided by the C
                    library not under tcc control)"
2013-02-17 19:44:55 +01:00
Urs Janssen 0bdbd49eac add version number to manpage
avoid c++/c99 style comments in preprocessor directives
avoid leadings whitespaces in preprocessor directives
mention implemented variable length arrays in documentation
fixed ambiguous option in texi2html call (Austin English)
2013-02-17 00:48:51 +01:00
Urs Janssen 108b287665 - don't use GCC_MAJOR to see if we're not using gcc as GCC_MAJOR might be set
during configure even with --cc=notgcc as long as gcc is installed.
2013-02-15 00:53:33 +01:00
Urs Janssen 062efe6ab8 - make clang accept unportable code in libtcc1.c
- add -dumpversion cmd.line opt
2013-02-14 08:24:51 +01:00
grischka 944627c479 configure: cleanup
- add quotes: eval opt=\"$opt\"
- use $source_path/conftest.c for OOT build
- add fn_makelink() for OOT build
- do not check lddir etc. on Windows/MSYS
- formatting

config-print.c
- rename to conftest.c (for consistency)
- change option e to b
- change output from that from "yes" to "no"
- remove inttypes.h dependency
- simpify version output

Makefile:
- improve GCC warning flag checks

tcc.h:
- add back default CONFIG_LDDIR
- add default CONFIG_TCCDIR also (just for fun)

tccpp.c:
- fix Christian's last warning
  tccpp.c: In function ‘macro_subst’:
  tccpp.c:2803:12: warning: ‘*((void *)&cval+4)’ is used uninitialized
     in this function [-Wuninitialized]
  That the change fixes the warning doesn't make sense but anyway.

libtcc.c:
- tcc_error/warning: print correct source filename/line for
  token :paste: (also inline :asm:)

lddir and multiarch logic still needs fixing.
2013-02-14 06:53:07 +01:00
grischka 05108a3b0a libtcc: new LIBTCCAPI tcc_set_options(TCCState*, const char*str)
This replaces       -> use instead:
-----------------------------------
- tcc_set_linker    -> tcc_set_options(s, "-Wl,...");
- tcc_set_warning   -> tcc_set_options(s, "-W...");
- tcc_enable_debug  -> tcc_set_options(s, "-g");

parse_args is moved to libtcc.c (now tcc_parse_args).

Also some cleanups:
- reorder TCCState members
- add some comments here and there
- do not use argv's directly, make string copies
- use const char* in tcc_set_linker
- tccpe: use fd instead of fp

tested with -D MEM_DEBUG: 0 bytes left
2013-02-12 19:13:28 +01:00
grischka 8042121d74 tcc -vv/--print-search-dirs: print more info
tests/Makefile:
- print-search-dirs when 'hello' fails
- split off hello-run

win32/include/_mingw.h:
- fix for compatibility with mingw headers
  (While our headers in win32 are from mingw-64 and don't have
  the problem)

tiny_libmaker:
- don't use "dangerous" mktemp
2013-02-10 00:38:40 +01:00
grischka d6d7686b60 tcc.h: declare CValue.tab[LDOUBLE_SIZE/4]
Should fix some warnings wrt. access out of array bounds.

tccelf.c: fix "static function unused" warning
x86_64-gen.c: fix "ctype.ref uninitialzed" warning and cleanup
tcc-win32.txt: remove obsolete limitation notes.
2013-02-08 19:07:11 +01:00
grischka 7a477d70ca lib/Makefile: use CC, add bcheck to libtcc1.a
Also:
- fix "make tcc_p" (profiling version)
- remove old gcc flags:
  -mpreferred-stack-boundary=2 -march=i386 -falign-functions=0
- remove test "hello" for Darwin (cannot compile to file)
2013-02-06 19:01:07 +01:00
grischka 82bcbd027f portability: fix void* <-> target address conversion confusion
- #define addr_t as ElfW(Addr)
- replace uplong by addr_t
- #define TCC_HAS_RUNTIME_PLTGOT and use it
2013-02-04 16:24:59 +01:00
grischka 263dc93cfa c67: remove global #define's for TRUE/FALSE/BOOL
Also use uppercase TRUE/FALSE instead of true/false
2013-02-04 16:24:56 +01:00
grischka 2f6b8469cc safety: replace occurrences of strcpy by pstrcpy 2013-01-31 13:23:19 +01:00
Thomas Preud'homme 8c56b0cf90 Revert "Added what I call virtual io to tinycc this way we can make a monolitic executable or library that contains all needed to compile programs, truly tinycc portable."
This reverts commit 59e18aee0e.
tcc is being stabilized now in order to do a new release soon.
Therefore, such a change is not appropriate now.
2013-01-14 17:34:07 +01:00
mingodad 59e18aee0e Added what I call virtual io to tinycc this way we can make a monolitic executable or library that contains all needed to compile programs, truly tinycc portable.
Tested under linux exec the "mk-it" shell script and you'll end up with a portable tinycc executable that doesn't depend on anything else.
2013-01-11 00:04:38 +00:00
grischka 2358b378b3 tccpp: alternative fix for #include_next infinite loop bug
This replaces commit 3d409b0889

- revert old fix in libtcc.c
- #include_next: look up the file in the include stack to see
  if it is already included.
Also:
- streamline include code
- remove 'type' from struct CachedInclude (obsolete because we check
  full filename anyway)
- remove inc_type & inc_filename from struct Bufferedfile (obsolete)
- fix bug with TOK_FLAG_ENDIF not being reset
- unrelated: get rid of an 'variable potentially uninitialized' warning
2013-01-06 17:20:44 +01:00
Sergey Vinokurov 3d409b0889 fix #include_next infinite loop bug, see http://savannah.nongnu.org/bugs/?31357 2012-09-20 22:12:05 +03:00
Michael Matz 0394caf784 Emit spaces for -MD
TCCs make dependency generator is incompatible with the GNU
depcomp script which is widely used.  For TCC it has to go over
the output of -MD, (it detects it as ICC compatible), but the
sed commands it uses are confused by tabs in the output, so that
some rewrites aren't done.

Those tabs will then finally confuse make itself when the
generated .d files are included.  It reads them as goal commands
(leading tab), and is totally lost then.

Short of changing depcomp (hard because distributed with all kinds
of software), simply emit spaces for -MD.
2012-05-13 02:03:47 +02:00
Michael Matz 718fd591fa Make sizeof() be of type size_t
This matters when sizeof is directly used in arithmetic,
ala "uintptr_t t; t &= -sizeof(long)" (for alignment).  When sizeof
isn't size_t (as it's specified to be) this masking will truncate
the high bits of the uintptr_t object (if uintptr_t is larger than
uint).
2012-04-18 20:57:14 +02:00
grischka f98c2306a0 libtcc: tcc_get_symbol uses the TCCState parameter
This allows using tcc_get_symbol on some other than the
current TCCState. (Suggested by David Mertens)
2012-04-18 18:48:26 +02:00
grischka f1b5c2ef4f tcc_realloc: auto "memory full" error 2012-04-18 18:43:55 +02:00
Gabriel Corneanu 176876e5de add "nostdlib" option to libtcc 2012-04-18 09:48:57 +02:00
Thomas Preud'homme 7fb0482a46 Support linker options passed in several -Wl param
ld support arguments to multiple-letter options being passed in two
ways:
* -opt=arg
* -opt arg

libtool generate command line of the second form. This commit add
support for the second form so that libtool works with tcc. The way it
is done is to concatenate all -Wl options into one and then pass it to
set_linker.
2012-03-15 00:25:40 +01:00
Andrew Mulbrook a0db7162af Fix assumption of 32bit long on portions of Elf
Modify tcc to accept convert full 64bits of specified text section
when converting on Win64. Write high bytes to the elf section address
as well. This allows creation of elf binaries located in offsets using
full 64 bit addresses.

Signed-off-by: Andrew Mulbrook <andrew262@gmail.com>
2012-03-03 11:10:15 -06:00
Andrew Mulbrook 5775911dad Revert "Multiple fixes for 64 bit sections"
This reverts commit d7a7c3769d.
2012-03-03 10:12:06 -06:00
Ramsay Jones e343b1dfd4 Add __REDIRECT needed for Large File Support API on linux
Since commit 9b09fc3 ("Add support of asm label for functions",
05-09-2010) tcc has had the capability to rename functions at the
assembly level. This capability was subsequently used by commit
2596273 ("Add support for __REDIRECT_NTH needed with eglibc",
11-09-2010) to redirect long double functions on platforms which
did not support long double.

Here we add the companion macro __REDIRECT which is used (along
with __REDIRECT_NTH) in the glibc headers on Linux to support the
Large File API (when _FILE_OFFSET_BITS is set to 64).

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2012-02-29 16:38:24 +00:00
mob d7a7c3769d Multiple fixes for 64 bit sections
This changeset attempts to fix a few problems when giving using
the high 32bits of a 64bit section offset. There are likely more
issues (or perhaps regressions) lurking in the muck here. In general,
this moves a few data type declarations to use uplong.  Also, add
support for 64bit mingw32 building under cygwin.  Because native
types are used for 64 bit offsets, this won't fix challenges with
cross compiling from 32bit -> 64bit.

Tested under cygwin, against binary compiled with
-Wl,-Ttext=0xffffff8000000000

Signed-off-by: Andrew Mulbrook <andrew262@gmail.com>
2012-02-26 19:02:51 -06:00
Nicolas Limare 5f99fe2ff1 libtcc: add missing tcc_enable_debug() 2011-10-03 22:36:16 +02:00
grischka bf374a5f23 rename error/warning -> tcc_(error/warning) 2011-08-11 17:07:56 +02:00
grischka 74a24d77fd libtcc: minor adjustments
- use {B} to substitute tcc_lih_path (instead of \b)

- expand CONFIG_TCC_CRTPREFIX in CONFIG_TCC_LIBPATHS
  which fixes duplicate CONFIG_SYSROOT.

- put default CONFIG_SYSROOT ("") into tcc.h

- remove hack from commit db6fcce78f
  because $(tccdir)/include is already in sysincludes

- configure: error out for unrecognized options.

- win32/build-tcc.bat: put libtcc into base dir where it will
  find lib/include automatically, and build libtcc_test example.
2011-08-11 16:55:30 +02:00
grischka e844fb11c2 libtcc: support more than one crtprefix
Looks like gcc has that.  Oh Deer!
2011-08-06 16:49:30 +02:00
grischka e6f3bf7f08 libtcc: cleanup the 'gen_makedeps' stuff 2011-08-06 16:11:58 +02:00
grischka 81cd0cf6fd configure: add switches to set search paths
--sysincludepaths=.. specify system include paths, colon separated"
     Sets CONFIG_TCC_SYSINCLUDEPATHS

   --libpaths=...       specify system library paths, colon separated"
     Sets CONFIG_TCC_LIBPATHS

   --crtprefix=...      specify location of crt?.o"
     Sets CONFIG_TCC_CRTPREFIX

   --elfinterp=...      specify elf interpreter"
     Sets CONFIG_TCC_ELFINTERP

Also the CONFIG_TCC_XXX were renamed to make them look
more consistent.

Also move the elf_interp definitions to tcc.h.
2011-08-06 16:11:12 +02:00
Thomas Preud'homme 0b6652003c Revert "Add a --multiarch-triplet switch to configure"
This reverts commit 76adc5770f.
2011-08-03 22:26:39 +02:00
Thomas Preud'homme 76adc5770f Add a --multiarch-triplet switch to configure
Add a --multiarch-triplet switch to configure. The switch will allow
files to be search for each default path in path/<triplet> and then
path.
Default paths handled that way:
- CONFIG_TCC_SYSINCLUDE_PATHS
- CONFIG_TCC_LIBPATH
- path to crt*.o
- path to libgcc_s.so.1

Path missing: elf interpreter path (will be handled in another commit)
2011-08-02 00:31:17 +02:00
Thomas Preud'homme 5e954fef32 Set CONFIG_TCC_CRT_PREFIX relative to CONFIG_SYSROOT
Set CONFIG_TCC_CRT_PREFIX relative to CONFIG_SYSROOT for consistency
with CONFIG_TCC_LDDIR.
2011-08-01 15:39:38 +02:00
grischka df9cce24a8 Accept colon separated paths with -L and -I
This allows passing colon separated paths to
  tcc_add_library_path
  tcc_add_sysinclude_path
  tcc_add_include_path

Also there are new configure variables
  CONFIG_TCC_LIBPATH
  CONFIG_TCC_SYSINCLUDE_PATHS
which define the lib/sysinclude paths all in one and can
be overridden from configure/make

For TCC_TARGET_PE semicolons (;) are used as separators

Also, \b in the path string is replaced by s->tcc_lib_path
(CONFIG_TCCDIR rsp. -B option)
2011-08-01 01:10:36 +02:00
Joe Soroka 339f961c11 fixed Makefile test targets 2011-07-22 02:12:49 -07:00
grischka 5280293d6b make: create native tcc from separate objects
This was already possible using
    make NOTALLINONE=1
and is now the default.

To build as previously from one big source, use
    make ONE_SOURCE=1

Cross compilers are still build from one source because using
separate objects requires separate build directories one per
platform which currently is not (yet) supported by the makefile.

We could probably use gnu-makeish target variables like
    $(I386_CROSS): OUTDIR=build/i386
    $(X64_CROSS): OUTDIR=build/x86-64
and so on ...

Also NEED_FLOAT_TYPES for arm-gen is removed.  It was about
variables that are referenced from outside (libtcc, tccgen).
We could declare them in tcc.h (as with reg_classes) or have
them twice in arm-gen.c.  I chose option 2.
2011-07-14 18:45:37 +02:00
grischka 45184e01d8 win32: add -Wl,--stack=xxx switch
For example:

    $ tcc -Wl,--stack=4194309

which means 4 MB.  Default is 1 MB.
2011-07-11 18:47:16 +02:00
Thomas Preud'homme 13121e220c Fix problem spotted in <4E15F966.4090102@gmx.de>
* Rename tcc_split_path_components
* Move tcc_split_path below memory wrapper section
* Ident tcc_split_path by 4
* Remove prefix and suffix clutter in tcc_split_path
* Don't dereference beyond the end of the search paths string
2011-07-08 10:51:26 +02:00
Thomas Preud'homme 4d6a4a26e0 Add configuration of include subdirectories
Add the possibility to search headers in several subdirectories of
/usr/local/include and /usr/include. A possible use case would be for
tcc to search for headers in /usr/local/include/x86_64-linux-gnu,
/usr/local/include, /usr/include/x86_64-linux-gnu and /usr/include in
turn.
2011-07-07 12:10:57 +02:00
Thomas Preud'homme a6775fc154 Introduce tcc_split_path_component for 31ca000d
Rewrite code introduced by 31ca000d and following commits around a new
function tcc_split_path_component.
2011-07-07 11:48:37 +02:00
Thomas Preud'homme ca6ff4fada Free extra_libdir_str after use. 2011-07-06 10:26:46 +02:00
Thomas Preud'homme 31ca000d72 Add multiarch dirs to linker search path
By default, tcc search libraries in /lib and /usr/local/lib while crt*.o
files are searched in /usr/lib and ld.so is searched in /lib.
Unfortunetely the path are hardcoded in source code. This patch allow
tcc to look in an other directory and also to look in extra directories.
It's then possible to make tcc search libraries in /lib/x86_64-linux-gnu
and /usr/local/lib/x86_64-linux-gnu while crt*.o files are searched in
/usr/lib/x86_64-linux-gnu and ld.so is searched in
/lib/x86_64-linux-gnu.
2011-07-05 11:16:12 +02:00
Thomas Preud'homme 66d992d883 Remove unused variables
Declare float type conditionally to not declare them conditionally when
they are not used.
2011-05-16 15:21:25 +02:00
Joe Soroka 7391cf01a7 fix spurious vstack-leak warnings on error 2011-05-02 00:05:36 -07:00
Joe Soroka 48d81a796e libtcc.c: report vstack "leaks" only if compile succeeded 2011-04-14 01:02:42 -07:00
Joe Soroka 6eb97c70b7 VLA leaks vstack. added warning to detect future leaks 2011-04-08 00:41:55 -07:00
grischka a3ebdd0aeb tccpe: support leading underscore for symbols
To make this the default, enable this line in libtcc.c:tcc_new:

    #if defined(TCC_TARGET_PE) && 0
        s->leading_underscore = 1;

and then recompile tcc and also libtcc1.a
2011-02-13 17:44:12 +01:00
Thomas Preud'homme 32a682b88f Fix fct asm label: only valid for declaration
- Fix function assembly label mechanism introduced in commit
  9b09fc376e to only accept alternative
  name for function declaration.
- merge the code with the one introduced in commit
  264a103610.
- Don't memorize token for asm label but directly the asm label.
2011-02-09 00:12:57 +01:00
Joe Soroka e939c4072c add -isystem cmdline option 2011-02-01 23:32:53 -08:00
Joe Soroka a25325e9be tccasm: define __ASSEMBLER__ for .S files, like gcc does 2011-02-01 15:26:21 -08:00
Joe Soroka 4d5105c8f1 support weak attribute on variables 2011-02-01 00:37:53 -08:00
grischka 86ffc48129 make: new lib/Makefile for libtcc1.a on more platforms
win32/64 cross-compilers now build libtcc1.a and install it
together with the windows headers in a 'win32' sub-directory
of TCCDIR.
2010-12-04 16:47:08 +01:00
Henry Kroll III a2779556b4 split cross libtcc1.a to separate directories 2010-12-02 03:08:57 -08:00
grischka c4eef48025 libtcc: fix s->include_stack_ptr used uninitialized in tcc_open 2010-11-26 20:46:50 +01:00
Henry Kroll III 77e4679aec x86_64: finish biarch path fixup 2010-11-25 10:08:58 -08:00
grischka e97bf88bad libtcc: new function tcc_open_bf to create BufferedFile
Use it in:
- tcc_open
- tcc_compile_string
- tcc_define_symbol
- tcc_assemble_inline
2010-11-25 13:29:15 +01:00
Henry Kroll III f1c9f649da x86_64: fix --with-libgcc and simplify biarch paths 2010-11-25 02:57:19 -08:00
Thomas Preud'homme b8adf0090e Move asm label functions from tccasm.c to tccgen.c
* Move functions parse_asm_str and asm_label_instr from tccasm.c to
  tccgen.c
* Remove CONFIG_TCC_ASM_LABEL macro as asm label are available on all
  archs.
See:
http://lists.nongnu.org/archive/html/tinycc-devel/2010-09/msg00026.html
for the rationale.
2010-09-14 23:21:15 +02:00
Thomas Preud'homme 2596273fce Add support for __REDIRECT_NTH needed with eglibc.
Add support for __REDIRECT_NTH as eglibc makes use of this macro to
redirect long double functions to long functions on arch not supporting
long double.
2010-09-12 01:19:19 +02:00
Thomas Preud'homme 776364f395 Add support for __FreeBSD_kernel__ kernel
Add support for kfreebsd-i386 and kfreebsd-amd64 Debian arch with
thanks to Pierre Chifflier <chifflier@cpe.fr>.
2010-09-10 21:09:07 +02:00
Thomas Preud'homme 9b09fc376e Add support of asm label for functions.
Add support for asm labels for functions, that is the ability to rename
a function at assembly level with __asm__ ("newname") appended in
function declaration.
2010-09-10 20:15:03 +02:00
Kirill Smelkov 7901d1e3ad tcc_set_linker: mimic all option forms as supported by GNU ld
Namely

 *  `-option' or `--option'  (start with double or single dash)
 *  `-param=val' or `-param,val'

See GNU ld manual (2.1 Command Line Options)
2010-08-12 23:30:21 +04:00
grischka 82c5edb31c Avoid crash with "Avoid a crash with weak symbols for "make test""
This fixes commit 197a6acb30
which fixed commit 95b9a477b6

Also remove useless example files
2010-06-30 20:25:04 +02:00
Kirill Smelkov 441a089aa4 Document what tcc_fileextension does
This is evident, but won't hurt
2010-06-21 20:49:46 +04:00