Commit Graph

593 Commits (dd70d19267ac343adae7bf15fe15c08fa604e5e1)
 

Author SHA1 Message Date
grischka dd70d19267 #define __TINYC__ = version-number 2009-11-13 17:11:52 +01:00
Shinichiro Hamaji 5dadff3de5 x86-64: Fix stab debug information.
We need 32bit relocations for code and 64bit for debug info.
Introduce a new macro R_DATA_PTR to distinguish the two usages.
2009-08-24 13:30:03 +02:00
Shinichiro Hamaji 3a1380120d x86-64: change the type of size_t and ptrdiff_t.
size_t and ptrdiff_t should be unsigned long and long, respectively.
2009-08-24 13:30:03 +02:00
grischka 834b782a9c tccpe: fill checksum header field 2009-08-24 13:30:02 +02:00
grischka 569c20f104 tccpp: fix quirk with cached headers and #else
Such as with

    #ifndef FOO_H
    ...
    #else
    ...
    #endif
2009-08-24 13:30:01 +02:00
grischka 1026ca5888 fix "symbol not defined" if symbol has offset 0 2009-08-24 13:30:01 +02:00
grischka d923e652f2 tccpp: avoid double free with macro_ptr_allocated (after errors) 2009-08-24 13:30:00 +02:00
grischka 0d34c2136e tccgen: free inline functions correctly 2009-08-24 13:30:00 +02:00
grischka 697f9e305d win64: fix bat 2009-08-24 13:28:02 +02:00
grischka b08dfb8273 tcc: optionally build using libtcc 2009-07-18 22:08:01 +02:00
grischka f88350b611 fix some warning 2009-07-18 22:07:51 +02:00
grischka c998985c74 cleanup: constify some global data 2009-07-18 22:07:42 +02:00
grischka 94ae3984b0 tccpe: set tcc_lib_path from DLL 2009-07-18 22:07:33 +02:00
grischka 1df662c1b0 tccpe: load dll on the fly 2009-07-18 22:07:25 +02:00
grischka 9fda4f4248 win32: treat long double as double 2009-07-18 22:07:17 +02:00
grischka 97738d1ae9 win32: reformat examples, crt etc 2009-07-18 22:07:10 +02:00
grischka bb5e0df79a x86-64: fix load() for const pointers: (void*)-2 2009-07-18 22:07:03 +02:00
grischka fc977d56c9 x86-64: chkstk, alloca 2009-07-18 22:06:54 +02:00
grischka c0fc0fa0c4 win64: add x64 target to build-tcc.bat 2009-07-18 22:06:46 +02:00
grischka dc251a7d8d win64: use new headers from mingw 2009-07-18 22:06:37 +02:00
grischka 06aed3d171 win64: update tiny_impdef, tiny_libmaker (Elf64) 2009-07-18 22:06:14 +02:00
grischka 09ac9faf59 win64: align jmp_buf 2009-07-18 22:06:07 +02:00
grischka 035918ef2f win64: fix pointer <-> unsigned long typecast issues 2009-07-18 22:05:58 +02:00
grischka 459875796b pe32+ target: adjust x86_64-gen.c
- calling conventions are different:
  * only 4 registers
  * stack "scratch area" is always reserved
  * doubles are mirrored in normal registers
- no GOT or PIC there
2009-07-18 22:05:49 +02:00
grischka 3ba1532cfb pe32+ target: add to makefile 2009-07-18 22:05:40 +02:00
grischka 3ea4acb9b9 pe32+ target: add in various #define's 2009-07-18 22:05:27 +02:00
grischka 719ba918dd tccpe: use more official structs 2009-07-18 21:55:32 +02:00
grischka f366cb20fe tccpe: support pe32+ (x86_64) target 2009-07-18 21:55:28 +02:00
grischka fe8def3303 tccpe: use ElfW macros 2009-07-18 21:55:25 +02:00
grischka dcfad3af49 tccpe: get rid of kludgy export-symbol sort 2009-07-18 21:55:20 +02:00
grischka 370cdeb628 tccpe: build IAT vector with with -run too
This prepares for x86_64 where we need the vector
for far jumps.  Also, resolve DLL symbols in place
2009-07-18 21:55:15 +02:00
grischka bed17847bd cleanup: stop abuse of sym->c for #define tokenstreams 2009-07-18 21:55:10 +02:00
grischka d0b432ab38 cleanup: stop abuse of sym->r for inline functions 2009-07-18 21:55:06 +02:00
grischka 5e83b64dae cleanup: put prototypes in front of libtcc.c 2009-07-18 21:55:02 +02:00
grischka 85e481b66e pp: return newline after directive 2009-07-18 21:54:58 +02:00
grischka fcdb663dde pp: simplify pasting, enable L ## number 2009-07-18 21:54:55 +02:00
grischka 045cff28fe fix asmtest (somehow), update Makefiles 2009-07-18 21:54:51 +02:00
grischka 0085c648f6 bcheck: restore malloc hooks when done 2009-07-18 21:54:47 +02:00
grischka c93ddac9aa configure: support DESTDIR for RPM packagers etc.
Suggested by Shlomi Fish
2009-07-18 21:54:43 +02:00
grischka ec4a350620 win32: guard va_list typedef 2009-06-17 02:11:40 +02:00
grischka c4b7e77bbe accept option -x <lang> 2009-06-17 02:11:27 +02:00
grischka 610fd47510 win32: structure return GCC compatible (ret 4 with cdecl) 2009-06-17 02:11:13 +02:00
grischka ec54c34b9e error messages: print "error: ..." 2009-06-17 02:10:56 +02:00
grischka e4ae77c7bb tcc_preprocess: add gcc-style include-depth flags
# 1 "main.c"
    # 1 "include/stdio.h" 1
    # 123 "include/stdio.h" 3
    # 10 "main.c" 2

flags: 1: level++; 3: same-level  2: level--
2009-06-17 02:10:42 +02:00
grischka 956b4beec1 incompatible function ptr assignment: just warn
void fn_1(int i) {}
    void (*fn_2)(char*) = fn_1;
2009-06-17 02:10:24 +02:00
grischka 6a004ed19f allow redefinition of func_old_type functions
void *memcpy(void*, const void*, unsigned);

This gave an error if memcpy() has been used before
implicitely,  e.g. for structure passing etc.
2009-06-17 02:09:52 +02:00
Soloist Deng c3701df16c trying to fix the bug of unclean FPU st(0)
Date: Mon, 8 Jun 2009 19:06:56 +0800
From: Soloist Deng <soloist.deng-gmail-com>
Subject: [Tinycc-devel] trying to fix the bug of unclean FPU st(0)

Hi all:

   I  am using  tcc-0.9.25, and the FPU bug brought a big trouble to
me. I read the source and tried to fix it.
Below is my solution.

 There are two places where program(`o(0xd9dd)') will generates `fstp
%st(1)': vpop() in tccgen.c:689 and save_reg() in tccgen.c:210.
We should first change both of them to `o(0xd8dd) // fstp %st(0)'.
But these changes are not enough.  Let's check the following code.

void foo()
{
 double var = 2.7;
 var++;
}

Using  the changed tcc will generate following machine code:

.text:08000000                 public foo
.text:08000000 foo             proc near
.text:08000000
.text:08000000 var_18          = qword ptr -18h
.text:08000000 var_10          = qword ptr -10h
.text:08000000 var_8           = qword ptr -8
.text:08000000
.text:08000000                 push    ebp
.text:08000001                 mov     ebp, esp
.text:08000003                 sub     esp, 18h
.text:08000009                 nop
.text:0800000A                 fld     L_0
.text:08000010                 fst     [ebp+var_8]
.text:08000013                 fstp    st(0)
.text:08000015                 fld     [ebp+var_8]
.text:08000018                 fst     [ebp+var_10]
.text:0800001B                 fstp    st(0)
.text:0800001D                 fst     [ebp+var_18]
.text:08000020                 fstp    st(0)
.text:08000022                 fld     L_1
.text:08000028                 fadd    [ebp+var_10]
.text:0800002B                 fst     [ebp+var_8]
.text:0800002E                 fstp    st(0)
.text:08000030                 leave
.text:08000031                 retn
.text:08000031 foo             endp
.text:08000031
.text:08000031 _text           ends
--------------------------------------------------
.data:08000040 ; Segment type: Pure data
.data:08000040 ; Segment permissions: Read/Write
.data:08000040 ; Segment alignment '32byte' can not be represented in assembly
.data:08000040 _data           segment page public 'DATA' use32
.data:08000040                 assume cs:_data
.data:08000040                 ;org 8000040h
.data:08000040 L_0             dq 400599999999999Ah
.data:08000048 L_1             dq 3FF0000000000000h
.data:08000048 _data           ends

Please notice the code snippet from 0800000A  to 08000020
// double var = 2.7; load constant to st(0)
.text:0800000A                 fld     L_0
// double var = 2.7; store st(0) to `var'
.text:08000010                 fst     [ebp+var_8]
// double var = 2.7; poping st(0)  will empty the floating registers stack
.text:08000013                 fstp    st(0)

  After that ,tcc will call `void inc(int post, int c)" in
tccgen.c:2150, and produce 08000015 to 0800001B through the calling
chain (inc ->gv_dup)
// load from `var' to st(0)
.text:08000015                 fld     [ebp+var_8]
// store st(0) to a temporary location
.text:08000018                 fst     [ebp+var_10]
// poping st(0)  will empty the floating registers stack
.text:0800001B                 fstp    st(0)

  And the calling chain
(gen_op('+')->gen_opif('+')->gen_opf('+')->gv(rc=2)->get_reg(rc=2)->save_reg(r=3))
will produce 0800001D to 08000020 .
// store st(0) to a temporary location, but floating stack is empty!
.text:0800001D                 fst     [ebp+var_18]
// poping st(0)  will empty the floating registers stack
.text:08000020                 fstp    st(0)

   The `0800001D   fst     [ebp+var_18]' will store st(0) to a memory
location, but st(0) is empty. That will cause  FPU invalid operation
exception(#IE).
Why does tcc do that? Please read `gv_dup' called by `inc' carefully.
Notice these lines:

(1):        r = gv(rc);
(2):        r1 = get_reg(rc);
(3):        sv.r = r;
            sv.c.ul = 0;
(4)         load(r1, &sv); /* move r to r1 */
(5)         vdup();
            /* duplicates value */
(6)         vtop->r = r1;

 (1)  let the vtop occupy TREG_ST0, and `r' will be TREG_ST0.  (2)
try to get a free floating register,but tcc assume
there is only one, so it wil force vtop goto memory and assign `r1'
with TREG_ST0. When executing (3), it will do nothing
because `r' equals `r1'. (5) duplicates vtop.  Then (6) let the new
vtop occupy TREG_ST0, but this will cause problem
because the old vtop has been moved to memory, so the new duplicated
vtop does not reside in TREG_ST0 but also
in memory after that. TREG_ST0 is not occupied but freely availabe
now.   `gen_op('+')'  need at least one oprand in register,
so it will incorrectly think TREG_ST0 is occupied by vtop and produce
instructions(0800001D and 08000020) to store it to
a temporary memory location.

  According program above, if `r' == `r1' it is impossible for the old
vtop to still occupy the `r' register .  And `load' will do nothing
too at this condition.
So the `gv_dup' can not promise the semantics that old vtop in one
register and the new duplicated vtop in another register at the same
time.

  I changed (6) to
if (r != r1)
{
 vtop->r = r1;
}

  Then the new generated machine code will be :

.text:08000000                 push    ebp
.text:08000001                 mov     ebp, esp
.text:08000003                 sub     esp, 10h
.text:08000009                 nop
.text:0800000A                 fld     L_0
.text:08000010                 fst     [ebp+var_8]
.text:08000013                 fstp    st(0)
.text:08000015                 fld     [ebp+var_8]
.text:08000018                 fst     [ebp+var_10]
.text:0800001B                 fstp    st(0)
.text:0800001D                 fld     L_1
.text:08000023                 fadd    [ebp+var_10]
.text:08000026                 fst     [ebp+var_8]
.text:08000029                 fstp    st(0)
.text:0800002B                 leave
.text:0800002C                 retn

 It works well, and will clean the floating registers stack when return.
 Finally, I want to know there is any potential problem of this fixing ?

soloist
2009-06-17 02:09:26 +02:00
grischka a342bbadc8 use static declaration from prototype
static int func();
    ...
    int func() { }

As result, func needs to be static.
2009-06-17 02:09:20 +02:00
grischka 69fdb57edd 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.
2009-06-17 02:09:07 +02:00
grischka bba515afe5 tccelf: accept BSS symbol with same name from other module
... such as 'int baz;' in two files at the same time
2009-06-17 02:08:54 +02:00