Commit Graph

196 Commits (a98fd1309076ad97c672394831034fe393b39121)

Author SHA1 Message Date
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
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 999274ca90 a lot simpler VLA code
Author: Philip <pipcet@gmail.com>
    Our VLA code can be made a lot simpler (simple enough for
    even me to understand it) by giving up on the optimization idea, which
    is very tempting. There's a patch to do that attached, feel free to
    test and commit it if you like. (It passes all the tests, at least
2015-05-04 04:09:05 +03:00
Philip 2f90db434e tccpp.c: fix GNU comma handling
This requires moving TOK_PLCHLDR handling, but the new logic should make
things easier even if (when?) GNU comma handling is removed.

(Somewhat confusingly, GCC no longer supports GNU commas. See
http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html for a description
of past and current GCC behaviour.)
2015-05-02 14:27:49 +00:00
Philip 0877ba7cbf tccpp.c: parse flag to accept stray \
This adds a PARSE_FLAG_ACCEPT_STRAYS parse flag to accept stray
backslashes in the source code, and uses it for pure preprocessing.

For absolutely correct behaviour of # stringification, we need to use
this flag when parsing macro definitions and in macro arguments, as
well; this patch does not yet do so. The test case for that is something
like

    #define STRINGIFY2(x) #x
    #define STRINGIFY(x) STRINGIFY2(x)

    STRINGIFY(\n)

which should produce "\n", not a parse error or "\\n".

See http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00002.html
2015-05-02 12:58:37 +00: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
grischka 7c27186a83 Revert "* and #pragma pop_macro("macro_name")"
- pop_macro incorrect with initially undefined macro
- horrible implementation (tcc_open_bf)
- crashes eventually (abuse of Sym->prev_tok)

- the (unrelated) asm_label part is the opposite of a fix
  (Despite of its name this variable has nothing to do with
  the built-in assembler)

This reverts commit 0c8447db79.
2015-04-23 23:26:46 +02:00
seyko 0c8447db79 * and #pragma pop_macro("macro_name")
* give warning if pragma is unknown for tcc
    * don't free asm_label in sym_free(),
      it's a job of the asm_free_labels().

    The above pragmas are used in the mingw headers.
    Thise pragmas are implemented in gcc-4.5+ and current
    clang.
2015-04-21 06:34:35 +03: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 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 559675b90a a bounds checking code for the ARCH=x86_64 2015-04-10 15:17:22 +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 3b7f5008fd fix for the previous commit (compilation on RPi) 2015-03-26 11:28:11 +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
Michael Matz 50899e30ab Fix stack overwrite on structure return
The common code to move a returned structure packed into
registers into memory on the caller side didn't take the
register size into account when allocating local storage,
so sometimes that lead to stack overwrites (e.g. in 73_arm64.c),
on x86_64.  This fixes it by generally making gfunc_sret also return
the register size.
2015-03-09 00:19:59 +01:00
Edmund Grimley Evans d73b488401 arm64: Implement __clear_cache.
__clear_cache is defined in lib-arm64.c with a single call to
__arm64_clear_cache, which is the real built-in function and is
turned into inline assembler by gen_clear_cache in arm64-gen.c
2015-03-08 00:10:44 +00: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 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 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
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 e260b03686 Allow tcc to understand a setob,... opcodes as alias to seto,...
PS: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20101122/112576.html
This is fix PR8686 for llvm: accepting a 'b' suffix at the end
of all the setcc instructions.
2015-01-06 22:59:19 +03:00
Lee Duhem 20a5845a47 tcc.h (BufferedFile): Remove unnecessary static memory allocation
The memory needed by `buffer' will be allocated in `tcc_open_bf',
these is no need to allocate them in BufferedFile statically.
2014-12-11 10:04:22 +08: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 fbda78aefe Parse and emit hidden visibility
This adds parsing of (GCC compatible) visibility attribute
in order to mark selected global symbols as hidden.  The generated
.o files contain hidden symbols already, the TCC linker doesn't
yet do the right thing.
2014-04-14 02:53:11 +02:00
Thomas Preud'homme 6e56bb387d Fix preprocessor concat with empty arg 2014-04-12 16:11:42 +08:00
minux b8eb7dd8e8 tcc.h: add ELF interpreter for DragonFly BSD. 2014-04-12 01:10:12 -04:00
Michael Matz 6a947d9d26 ELF: Remove traces of old RUNTIME_PLTGOT code
The last users of it went away, no use in keeping
this code.
2014-04-06 01:59:35 +02:00
Michael Matz 01c0419234 arm: Use proper PLT/GOT for -run.
Same as with x86_64, disable the runtime_plt_and_got hack
for -run on arm as well.  For that we need to handle several
relocations as (potentially) generating PLT slots as well.
Tested with mpfr-3.1.2 and gawk (both using --disable-shared),
there are two resp. five pre-existing problems, so no regressions.

This also works toward enabling real shared libs for arm,
but it's not there yet.
2014-04-06 01:50:35 +02:00
Michael Matz 9750d0b725 x86_64: Create proper PLT and GOT also for -run
This makes us use the normal PLT/GOT codepaths also for -run,
which formerly used an on-the-side blob for the jump tables.
For x86_64 only for now, arm coming up.
2014-04-06 00:30:22 +02:00
grischka 5879c854fb tccgen: x86_64: fix garbage in the SValue upper bits
This was going wrong (case TOK_LAND in unary: computed labels)
-        vset(&s->type, VT_CONST | VT_SYM, 0);
-        vtop->sym = s;

This does the right thing and is shorter:

+        vpushsym(&s->type, s);


Test case was:

    int main(int argc, char **argv)
    {
        int x;
        static void *label_return = &&lbl_return;
        printf("label_return = %p\n", label_return);
        goto *label_return; //<<<<< here segfault on linux X86_64 without the memset on vset
        printf("unreachable\n");
    lbl_return:
        return 0;
    }


Also::
- Rename "void* CValue.ptr" to more usable "addr_t ptr_offset"
  and start to use it in obvious cases.

- use __attribute__ ((noreturn)) only with gnu compiler

- Revert CValue memsets ("After several days searching ...")
  commit 4bc83ac393

Doesn't mean that the vsetX/vpush thingy isn't brittle and
there still might be bugs as to differences in how the CValue
union  was set and is then interpreted later on.

However the big memset hammer was just too slow (-3% overall).
2014-04-04 20:20:44 +02:00
Michael Matz 0bd1282059 x86-64: shared libs improvement
This correctly resolves local references to global functions from
shared libs to their PLT slot (instead of directly to the target
symbol), so that interposition works.

This is still not 100% conforming (executables don't export symbols
that are also defined in linked shared libs, as they must), but
normal shared lib situations work.
2014-03-31 05:36:12 +02:00
mingodad 5a5fee867a Add __attribute__ ((noreturn)) to tcc_error and expect functions.
This make use of static analysis tools like scan-build report less false positives.
2014-03-30 10:18:18 +01:00
grischka 0ac8aaab1b tccpp: reorder some tokens
... and make future reordering possibly easier

related to 9a6ee577f6
2014-03-29 19:37:26 +01:00
Thomas Preud'homme aa561d7011 Simplify and fix GOT32 + PLT32 reloc commit
Introduce a new attribute to check the existence of a PLT entry for a
given symbol has the presence of an entry for that symbol in the dynsym
section is not proof that a PLT entry exists.

This fixes commit dc8ea93b13.
2014-03-26 23:13:28 +08:00
Thomas Preud'homme b0b5165d16 Def signedness != signed != unsigned for char
When checking for exact compatibility between types (such as in
__builtin_types_compatible_p) consider the case of default signedness to
be incompatible with both of the explicit signedness for char. That is,
char is incompatible with signed char *and* unsigned char, no matter
what the default signedness for char is.
2014-02-06 21:40:22 +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 8efaa71190 Fix struct ret in variadic fct with ARM hardfloat
The procedure calling standard for ARM architecture mandate the use of
the base standard for variadic function. Therefore, hgen float aggregate
must be returned via stack when greater than 4 bytes and via core
registers else in case of variadic function.

This patch improve gfunc_sret() to take into account whether the
function is variadic or not and make use of gfunc_sret() return value to
determine whether to pass a structure via stack in gfunc_prolog(). It
also take advantage of knowing if a function is variadic or not move
float result value from VFP register to core register in gfunc_epilog().
2014-01-06 22:57:05 +08:00
Thomas Preud'homme a01d83d783 Don't enable bound check if libgcc is used
Bound check rely on some functions provided by libtcc. It should
therefore not be enabled when libgcc is used.
2014-01-06 11:26:09 +08:00
Ramsay Jones d0c2f00df2 Fix CONFIG_TCC_SYSINCLUDEPATHS on !win32 systems
Commit 9382d6f1 ("Fix lib, include, crt and libgcc search paths",
07-09-2013) inadvertently included an initial empty entry to the
CONFIG_TCC_SYSINCLUDEPATHS variable (for non win32 targets). In
addition to an empty line in the 'tcc -vv' display, this leads
to the preprocessor attempting to read an include file from the
root of the filesystem (i.e. '/header.h').

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2013-10-02 21:49:55 +02:00
Thomas Preud'homme 76cb1144ef Generate an error when a function is redefined
Use one more bit in AttributeDef to differenciate between declared
function (only its prototype is known) and defined function (its body is
also known). This allows to generate an error in cases like:

int f(){return 0;}
int f(){return 1;}
2013-09-16 14:48:33 +02:00