Commit Graph

1256 Commits

Author SHA1 Message Date
Daniel Glöckner
9e9e5c2929 Relicensing TinyCC 2014-01-04 10:59:04 +01:00
Thomas Preud'homme
3eed3506b4 Fix negation of 0.0 and -0.0 2014-01-04 17:07:58 +08:00
Thomas Preud'homme
0382131c6f Provide install-strip target in Makefile 2014-01-04 09:48:45 +08:00
Thomas Preud'homme
9e79b18bca Use libtcc.a for static link even with USE_LIBGCC
When statically linking, runtime library should be static as well. tcc
could link with libgcc.a but it's in a gcc version specific directory.
Another solution, followed by this patch, is to use libtcc.a when
statically linking, even if USE_LIBGCC was configured.
2014-01-03 18:20:51 +08:00
Thomas Preud'homme
e0e9a2a295 Report error on NaN comparison
Use comisd / fcompp for float comparison (except TOK_EQ and TOK_NE)
instead of ucomisd / fucompp to detect NaN comparison.

Thanks Vincent Lefèvre for the bug report and for also giving the
solution.
2014-01-03 10:19:38 +08:00
Thomas Preud'homme
59b8007f98 Always set *palign in classify_x86_64_arg
Set *palign for VT_BITFIELD and VT_ARRAY types in classify_x86_64_arg as
else you happen to have in *palign what was already there. This can
cause gfunc_call on !PE systems to consider an array as 16 bytes align
and trigger the assert if the previous argument was 16 bytes aligned.
2014-01-03 10:19:38 +08:00
grischka
fbc8810334 Fix "Add support for struct > 4B returned via registers"
- avoid assumption "ret_align == register_size" which is
  false for non-arm targets
- rename symbol "sret" to more descriptive "ret_nregs"

This fixes commit dcec8673f2

Also:
- remove multiple definitions in win32/include/math.h
2013-12-16 15:38:10 +01:00
Thomas Preud'homme
46dd2971ab make git ignore lib/arm directory 2013-12-15 09:49:20 +08:00
Thomas Preud'homme
a24e31e85d Fix signed integer division in ARM runtime ABI
- fix computation of absolute value (clearing the sign bit does not
  since integers are encoded in 2's complement)
- test sign of integer in a more conventional way (binary and with the
  high bit does not work for long long due to a bug in gtst)
- spacing in include
2013-12-15 09:44:20 +08:00
Thomas Preud'homme
f2dbcf7594 Add ARM aeabi functions needed to run tcctest
Add implementation for float / integer conversion functions:
  __aeabi_d2lz, __aeabi_d2ulz, __aeabi_f2lz, __aeabi_f2ulz, __aeabi_l2d,
  __aeabi_l2f, __aeabi_ul2d, __aeabi_ul2f

Add implementation for long long helper functions:
  __aeabi_ldivmod, __aeabi_uldivmod, __aeabi_llsl, __aeabi_llsr, __aeabi_lasr

Add implementation for integer division functions:
  __aeabi_uidiv, __aeabi_uidivmod, __aeabi_idiv, __aeabi_idivmod,
2013-12-11 10:15:30 +08:00
Thomas Preud'homme
389c25c4b9 Support special calling convention for runtime ABI
Add infrastructure to support special calling convention for runtime ABI
function no matter what is the current calling convention. This involve
2 changes:
- behave as per base standard in gfunc_call
- move result back in VFP register in gen_cvt_itof1
2013-12-11 10:15:29 +08:00
Thomas Preud'homme
3676f61983 Define __ARM_EABI__ and __ARMEL__ when applicable 2013-11-26 12:06:21 +08:00
Thomas Preud'homme
5919da6f05 Make abitest.c have predictable result
stdarg_test in abitest.c relies on a sum of some parameters made by both
the caller and the callee to reach the same result. However, the
variables used to store the temporary result of the additions are not
initialized to 0, leading to uncertainty as to the results. This commit
add this needed initialization.
2013-11-25 11:25:04 +08:00
Thomas Preud'homme
4260ce1889 Add va_* macro implementation for ARM 2013-11-25 11:24:02 +08:00
Thomas Preud'homme
82b257c29c Add comment to explain the code added by 41ce391c
Add a comment in arm-gen.c to explain how commit
41ce391c86 solves the register corruption
when passing a structure in a function call.
2013-11-25 11:00:51 +08:00
Thomas Preud'homme
48fc746652 Fix structure passing in ARM calling convention
Fix the address on stack where a structure is copied when it is a
parameter of a function call. This address must be computed from the
stack pointer and a possible padding offset.
2013-11-25 10:58:00 +08:00
Thomas Preud'homme
dcec8673f2 Add support for struct > 4B returned via registers
On ARM with hardfloat calling convention, structure containing 4 fields
or less of the same float type are returned via float registers. This
means that a structure can be returned in up to 4 double registers in a
structure is composed of 4 doubles. This commit adds support for return
of structures in several registers.
2013-11-22 09:27:15 +08:00
Thomas Preud'homme
d9d60a1ebd Remove code in arm-gen.c for struct packing in reg
Struct packing in register is now handled since commit 2bbfaf43 by
tccgen.c proper.
2013-11-22 00:15:34 +08:00
Thomas Preud'homme
63a84713ee Correctly identify homogeneous float aggregate
First related symbol of a structure justs indicate its size. This first
member is the second related symbol.
2013-11-22 00:13:05 +08:00
Thomas Preud'homme
c3e7c725b5 Fix counting of VFP regs in ARM's gfunc_prolog
Fix in gfunc_prolog for ARM the counting of the highest numbered VFP
float register used for parameter passing, rounded to 2. It can be
computed from the range of VFP float register with the highest range
start and adding the number of VFP float register occupied. This ensure
that parameter of type struct that spans over more than 2 float
registers are correctly taken into account.
2013-11-21 22:27:15 +08:00
Thomas Preud'homme
41ce391c86 Fix register corruption at function call on ARM
Prior to this commit, params could use some registers that do not appear
in the value stack. Therefore when generating function call, one of such
register could be reused, leading to wrong parameter content. This
happens when a structure is passed via core register, as only the first
register would appear in the value stack.
2013-11-21 21:09:44 +08:00
Thomas Preud'homme
1b606d1884 Allow thumb transition for R_ARM_PC24
Allow bl -> blx conversion in the case of R_ARM_PC24 relocation with
instruction being an unconditional bl. Also make spacing more uniform.
2013-11-18 00:03:38 +08:00
Thomas Preud'homme
0c40bc8982 Correctly align and reclaim stack at function call
* Correctly align stack in case of structure split between core
  registers and stack
* Correctly reclaim stack space after function call in the case where
  the stack needed padding to be aligned at function call.
2013-11-17 18:26:56 +08:00
Thomas Preud'homme
1528a08540 Refactor and simplify gfunc_call() on arm 2013-11-15 17:57:31 +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
fbb4841606 Add __clear_cache implementation in libtcc1
Add __clear_cache function for flushing caches to libtcc1.
2013-11-05 19:29:43 +08:00
Thomas Preud'homme
b7d017dec8 Fix allocation of struct in registers on ARM
Allocation of struct in core and/or VFP registers on ARM is made by
manipulating the value stack to create 3 distinct zones: parameters
allocated on stack, parameters of type struct allocated in core
registers and parameters of type struct allocated in VFP registers.
Parameters of primitive type can be in any zone. This commit change the
order of the zones from stack, VFP, core to stack, core, VFP (from
highest addresses to lowest ones) in order to correctly deal the
situation when structures are allocated both in core and VFP registers.
2013-11-05 17:50:30 +08: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
Amine Najahi
3b07a15fd1 Detect usage of incomplete types inside struct/union
Make sure the only exception is for a flexible array member
as the last element of a structure
2013-10-06 14:51:29 +02: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
385a86b000 Fix commit 0f5942c6b3 2013-10-01 17:11:44 +02:00
Thomas Preud'homme
0f5942c6b3 Avoid warnings with gcc 4.8 + default CFLAGS 2013-09-24 15:37:12 +02:00
Thomas Preud'homme
a1a691a030 Detect correct instruction with incorrect operands
Display a different warning when an instruction is recognized by tcc but
the operands found do not correspond to the constraints of the
instruction.
2013-09-24 15:37:11 +02:00
Vittorio Giovara
45b35a3d66 set the user-defined library search paths first 2013-09-23 09:40:06 +02:00
Thomas Preud'homme
673befd2d7 Report error when redefining enumerator
Prevent the following code from compiling:

enum color {RED, GREEN, BLUE};
enum rgb {RED, G, B};
2013-09-20 22:49:49 +02:00
Thomas Preud'homme
82969f045c Report error when using undefined enum
Prevent the following code from compiling:

int main(void)
{
	enum rgb c = 42;
	return c;
}

Reported-by: John Haque <j.eh@mchsi.com>
2013-09-20 21:22:11 +02:00
Thomas Preud'homme
0f522fb32a Forbid enum redefinition.
Prevent the following code from compiling:

enum color {RED, GREEN, BLUE};
enum color {R, G, B};

int main()
{
        return R;
}

Reported-by: John Haque <j.eh@mchsi.com>
2013-09-20 01:06:43 +02:00
Thomas Preud'homme
a465b7f58f Forbid the use of array of functions
Prevent the following code from compiling:

int (*fct)[42](int x);

Reported-by: Abdul Wadud Mohammad Mohibur Rashid <mohibur_rashid@yahoo.com>
2013-09-19 18:58:46 +02:00
YX Hao
642b6d0f50 Add the possibility to use noname functions by ordinal
tcc.c:
process.h:177:20: note: expected 'char * const*' but argument is of type 'char const*const*'

tccpe.c:
Add the possibility to use noname functions by ordinal.
use def file: "AliasName @n"

build-tcc.bat:
1. Enable 32 bits mode on 64 bits OS.
2. build doc.

_parseLibs.bat:
Convenient to use "*.def + *.c" instead of *.a, just use -l*

_tcc.bat:
a practice of _parseLibs.bat

Signed-off-by: YX Hao <lifenjoiner@163.com>
2013-09-19 21:50:38 +08: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
grischka
13b997668e win32: fix libtcc support
For "tcc -run file.c", I was trying to initialize the FP control
in a function in libtcc1.a (_runmain) before calling main.

Unfortunately that turned out to cause problems with for example
libtcc_test since such usage doesn't necessarily define a 'main'
function.

So for tcc -run we're back to relying on the FP control word
that is set in the startup code of tcc.exe rsp. libtcc.dll.

This fixes part of commit 73faaea227
2013-09-10 15:36:56 +02:00
Ramsay Jones
235a65033f libtcc1.c: Fix __asm__() in __tcc_fpinit and __tcc_cvt_ftol
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2013-09-09 23:59:09 +02:00
Thomas Preud'homme
9382d6f1a0 Fix lib, include, crt and libgcc search paths 2013-09-07 19:28: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
grischka
69c2e7f96c tccgen: fix crash with undeclared struct
... as in:
    #include<stdio.h>
    int main()
    {
        struct asdasd x;
        printf("%d\n", sizeof(x));
    }
This fixes commit 17571298f3
2013-07-24 17:06:13 +02:00
Frédéric Féret
8c033a1461 Relicensing TinyCC 2013-06-22 16:18:49 +02:00
Thomas Preud'homme
37b0348993 Define __ARM_PCS_VFP in hardfloat compilation mode 2013-06-15 00:26:07 +02:00
Thomas Preud'homme
f6b50558fc Add support for load/store of _Bool value
Add support for loading _Bool value in i386, x86_64 and arm as well as
support for storing _Bool value on arm.
2013-06-14 16:19:51 +02:00
Roy
807dc7c8de tccpe: pstrcpy() will truncate .stabstr section name, use strncpy() instead. 2013-06-06 09:26:31 +08:00