Commit Graph

365 Commits (meesbs)

Author SHA1 Message Date
grischka 096125d963 win32: adjust new unicode support
- lib/Makefile: add (win)crt1_w.o

- crt1.c/_runtmain: return to tcc & only use for UNICODE
  (because it might be not 100% reliable with for example
  wildcards (tcc *.c -run ...)

- tccrun.c/tccpe.c: load -run startup_code only if called
  from tcc_run(). Otherwise main may not be defined.  See
  libtcc_test.c

- tests2/Makefile: pass extra options in FLAGS to allow
  overriding TCC

Also:
- tccpe.c: support weak attribute.  (I first tried to solve
  the problem above by using it but then didn't)
2017-02-18 09:51:23 +01:00
Christian Jullien 39b2afeb7c Temporary remove 76_dollards_in_identifiers when run on Windows as this test failes. To be checked why. 2017-02-18 08:12:00 +01:00
Christian Jullien 7b99c3ac2c Fix wrong name for 85 test. 2017-02-15 09:00:38 +01:00
grischka 43d9a7de9b updates & cleanups (tcc-doc/Changelog/TODO ...)
- tcc-doc.texi: commandline option info update
- Changelog/TODO: update
- tests/tcctest.py: removed
- tests/Makefile: weaktest fixed
- tests/tests2: some files renamed and/or converted to unix LF
- configure/Makefile: --enable-static option (no dll on win32)
- win32/build-tcc.bat: msvc support
- win32/tcc-win32.txt: build info update
- win32/vs2015/: VS solution removed
- win32/include/tcc/tcc_libm.h: #include statement fixed
- tcc.c: -include <file> option help info
- .gitignore: cleanup
2017-02-13 19:03:29 +01:00
Michael Matz 15f990bf71 Fix testsuite invocations
The return code of $(FILTER) clobbers the return code of
TCC itself.  So just prepend messages to the generated output file
and ignore return codes.
2017-02-11 14:27:21 +01:00
grischka 5efa75d9b8 update VERSION to 0.9.27
Also:
- in tests: generate .expect files only if not yet present,
  because
  1) some files were adjusted manually
  2) switching git branche might change timestamps and
     cause unwanted update
2017-02-08 19:56:15 +01:00
Avi Halachmi (:avih) 9b3e4c5895 tests: don't assume $(CC) is gcc
This also allows self hosting + testing when $(CC) is tcc.
2016-12-24 20:59:10 +02:00
grischka 71c5ce5ced tests: OOT build fixes etc.
tests/Makefile: fix out-of-tree build issues

Also:

- win64: align(16) MEM_DEBUG user memory
  on win64 the struct jmp_buf in the TCCState structure which we
  allocate by tcc_malloc needs alignment 16 because the msvcrt
  setjmp uses MMX instructions.

- libtcc_test.c: win32/64 need __attribute__((dllimport)) for
  extern data objects

- tcctest.c: exclude stuff that gcc does not compile
  except for relocation_test() the other issues are mostly ASM
  related.  We should probably check GCC versions but I have
  no idea which mingw/gcc versions support what and which don't.

- lib/Makefile: use tcc to compile libtcc1.a (except on arm
  which needs arm-asm
2016-12-20 18:05:33 +01:00
Michael Matz 42e2a67f23 Fix some code suppression fallout
Some more subtle issues with code suppression:
- outputting asms but not their operand setup is broken
- but global asms must always be output
- statement expressions are transparent to code suppression
- vtop can't be transformed from VT_CMP/VT_JMP when nocode_wanted

Also remove .exe files from tests2 if they don't fail.
2016-12-20 04:58:34 +01:00
grischka a1c12b9fb9 tests: add memory leak test
Also ...

tcctest.c:
- exclude stuff that gcc doesn't compile on windows.

libtcc.c/tccpp.c:
- use unsigned for memory sizes to avoid printf format warnings
- use "file:line: message" to make IDE error parsers happy.

tccgen.c: fix typo
2016-12-18 22:05:42 +01:00
Michael Matz 77d7ea04ac Fix gawk miscompile
See testcase.  Function pointer use was hosed when the destination
function wasn't also called normally by the program.
2016-12-18 05:20:14 +01:00
Michael Matz cd9514abc4 i386: Fix various testsuite issues
on 32bit long long support was sometimes broken.  This fixes
code-gen for long long values in switches, disables a x86-64 specific
testcase and avoid an undefined shift amount.  It comments out
a bitfield test involving long long bitfields > 32 bit; with GCC layout
they can straddle multiple words and code generation isn't prepared
for this.
2016-12-15 17:53:09 +01:00
Michael Matz f5ae4daa5f struct-layout: Allow lowering of member alignment
when an alignment is explicitely given on the member itself,
or on its types attributes then respect it always.  Was only
allowed to increase before, but GCC is allowing it.
2016-12-15 17:49:56 +01:00
Michael Matz 8859dc9e6d Support large alignment requests
The linux kernel has some structures that are page aligned,
i.e. 4096.  Instead of enlarging the bit fields to specify this,
use the fact that alignment is always power of two, and store only
the log2 minus 1 of it.  The 5 bits are enough to specify an alignment
of 1 << 30.
2016-12-15 17:49:56 +01:00
Michael Matz 78c7096162 Fix struct layout some more
Anonymous sub-sub-members weren't handled correctly.  Bit-fields
neither: this implements PCC layout for now.  It temporarily disables
MS-compatible bit-field layout.
2016-12-15 17:49:56 +01:00
Michael Matz ddecb0e685 Split off record layouting
Such struct decl:

  struct S { char a; int i;} __attribute__((packed));

should be accepted and cause S to be five bytes long (i.e.
the packed attribute should matter).  So we can't layout
the members during parsing already.  Split off the offset
and alignment calculation for this.
2016-12-15 17:49:56 +01:00
Michael Matz 22f5fccc2c Fix 64bit enums and switch cases
See testcases.  We now support 64bit case constants.  At the same time
also 64bit enum constants on L64 platforms (otherwise the Sym struct
isn't large enough for now).  The testcase also checks for various
cases where sign/zero extension was confused.
2016-12-15 17:49:56 +01:00
Michael Matz 3e77bfb6e9 tccpp: Fix token pasting
See testcase.  We must always paste tokens (at least if not
currently substing a normal argument, which is a speed optimization
only now) but at the same time must not regard a ## token
coming from argument expansion as the token-paste operator, nor
if we constructed a ## token due to pasting itself (that was already
checked by pp/01.c).
2016-12-15 17:49:56 +01:00
Michael Matz d042e71e9f Fix miscompile with dead switches
In certain very specific situations (involving switches
with asms inside dead statement expressions) we could generate
invalid code (clobbering the buffer so much that we generated
invalid instructions).  Don't emit the decision table if the
switch itself is dead.
2016-12-15 17:49:55 +01:00
Michael Matz 235711f3d3 64bit: Fix addends > 32 bits
If a symbolic reference is offsetted by a constant > 32bit
the backends can't deal with that, so don't construct such
values.
2016-12-15 17:49:55 +01:00
Michael Matz a2a596e767 x86-64-asm: Accept high register in clobbers
The callee saved registers (among them r12-r15) really need
saving/restoring if mentioned in asm clobbers, even if TCC
itself doesn't use them.  E.g. the linux kernel relies on that
in its switch_to() implementation.
2016-12-15 17:49:55 +01:00
Michael Matz ddd461dcc8 Fix initializing members multiple times
When intializing members where the initializer needs relocations
and the member is initialized multiple times we can't allow
that to lead to multiple relocations to the same place.  The last
one must win.
2016-12-15 17:49:53 +01:00
Michael Matz f081acbfba Support local register variables
Similar to GCC a local asm register variable enforces the use of a
specified register in asm operands (and doesn't otherwise
matter).  Works only if the variable is directly mentioned as
operand.  For that we now generally store a backpointer from
an SValue to a Sym when the SValue was the result of unary()
parsing a symbol identifier.
2016-12-15 17:47:13 +01:00
Michael Matz 3bc9c325c5 Fix const folding of 64bit pointer constants
See testcase.
2016-12-15 17:47:12 +01:00
Michael Matz 0b0e64c2c9 x86-asm: Correct register size for pointer ops
A pointer is 64 bit as well, so it needs a full
register for register operands.
2016-12-15 17:47:12 +01:00
Michael Matz 7ab35c6265 struct-init: Copy relocs for compound literals
When copying the content of compound literals we must
include relocations as well.
2016-12-15 17:47:12 +01:00
Michael Matz 0bca6cab06 x86_64-asm: fix copy-out registers
If the destination is an indirect pointer access (which ends up
as VT_LLOCAL) the intermediate pointer must be loaded as VT_PTR,
not as whatever the pointed to type is.
2016-12-15 17:47:12 +01:00
Michael Matz ad8e14b740 opt: Don't emit inline functions from dead code
Inside dead code don't regard inline functions as being
referenced.
2016-12-15 17:47:12 +01:00
Michael Matz ce55d03eef Handle __builtin_extract_return_addr
Our architectures don't need anything special for this
builtin, just pass through the argument.
2016-12-15 17:47:12 +01:00
Michael Matz fb933ae0eb opt: constprop also 'cond && 0'
We didn't handle constants in logical expressions when they weren't
the first operand.  Some reordering in the loop structure is enough
to handle them.
2016-12-15 17:47:12 +01:00
Michael Matz ca435dc2e3 opt: Make break and goto not fallthrough
As we can optimize dead code a bit already it's fitting
to disable code emission after break and goto.
2016-12-15 17:47:12 +01:00
Michael Matz 31c7ea0165 opt: Start optimizing dead code a bit
If a condition is always zero/non-zero we can omit the
then or else code.  This is complicated a bit by having to
deal with labels that might make such code reachable without
us yet knowing during parsing.
2016-12-15 17:47:12 +01:00
Michael Matz 1602998751 Fix more nocode_wanted jump problems
In statement expression we really mustn't emit backward jumps
under nocode_wanted (they will form infinte loops as no expressions
are evaluated).  Do-while and explicit loop with gotos weren't
handled.
2016-12-15 17:47:11 +01:00
Michael Matz f2a071e808 Fix aliases on 64 bit
Use correct width ELF structure.
2016-12-15 17:47:11 +01:00
Michael Matz 9656560f14 Fix sizeof(char[a])
The sizes of VLAs need to be evaluated even inside sizeof,
i.e. when nocode_wanted is set.
2016-12-15 17:47:11 +01:00
Michael Matz 49bb5a7e06 Fix __builtin_constant_p(1000/x)
was incorrectly treated as constant because the vpop removed
all traces of non-constness.
2016-12-15 17:47:11 +01:00
Michael Matz 5bd8aeb917 tccasm: Support refs to anon symbols from asm
This happens when e.g. string constants (or other static data)
are passed as operands to inline asm as immediates.  The produced
symbol ref wouldn't be found.  So tighten the connection between
C and asm-local symbol table even more.
2016-12-15 17:47:11 +01:00
Michael Matz dd57a34866 tccasm: Don't ignore # in preprocessor directives
Our preprocessor throws away # line-comments in asm mode.
It did so also inside preprocessor directives, thereby
removing stringification.  Parse defines in non-asm mode (but
retain '.' as identifier character inside macro definitions).
2016-12-15 17:47:11 +01:00
Michael Matz e7ef087598 x86-asm: Accept all 32bit immediates
In particular don't care if they're signed or unsigned, they're all
acceptable as immediates.
2016-12-15 17:47:11 +01:00
Michael Matz 372f4b6a4e Fix enum bitfields passed to stdarg functions
VT_ENUM types use the .ref member and can be VT_BITFIELD,
so we need to copy it as well.  Simply do it always.
2016-12-15 17:47:11 +01:00
Michael Matz d720865fb6 Addresses of non-weak symbols are non-zero
Use this fact in some foldings of comparisons.  See testcase.
2016-12-15 17:47:10 +01:00
Michael Matz be6d8ffc10 Fix access-after-free with statement expressions
The return value of statement expressions might refer to local
symbols, so those can't be popped.  The old error message always
was just a band-aid, and since disabling it for pointer types it
wasn't effective anyway.  It also never considered that also the
vtop->sym member might have referred to such symbols (see the
testcase with the local static, that used to segfault).

For fixing this (can be seen better with valgrind and SYM_DEBUG)
simply leave local symbols of stmt exprs on the stack.
2016-12-15 17:47:10 +01:00
Michael Matz d0d25ec7df tccpp: Allow computed include like 42.h
The include directive needs to be parsed as pp-tokens, not
as token (i.e. no conversion to TOK_STR or TOK_NUM).  Also fix
parsing computed includes using quoted strings.
2016-12-15 17:47:10 +01:00
Michael Matz 0381387640 x86-asm: Correctly infer register size for bools
Register operands of type _Bool weren't correctly getting
the 8-bit sized registers (but rather used the default 32-bit
ones).
2016-12-15 17:47:10 +01:00
Michael Matz 9e0af6d2b5 x86-64-asm: Implement cmpxchg16b 2016-12-15 17:47:10 +01:00
Michael Matz ca8c1cd643 x86-64: Allow loads from some structs/unions
GCC allows register loads for asms based on type mode,
and correctly sized structs/union have an allowed mode
(basically 1,2,4,8 sized aggregates).
2016-12-15 17:47:10 +01:00
Michael Matz 9ae10cad1f tccasm: Lookup C symbols from ASM blocks
It's now possible to use symbols defined in C code to be used
from later inline asm blocks.  See testcase.
2016-12-15 17:47:10 +01:00
Michael Matz c4edfb4e08 tccasm: Implement .set sym, expr
That, as well as "sym = expr", if expr contains symbols.
Slightly tricky because a definition from .set is overridable,
whereas proper definitions aren't.

This doesn't yet allow using this for override tricks from C
and global asm blocks because the symbol tables from C and asm
are separate.
2016-12-15 17:47:10 +01:00
Michael Matz 34fc6435ee enums and ints are compatible
But like GCC do warn about changes in signedness.  The latter
leads to some changes in gen_assign_cast to not also warn about
  unsigned* = int*
(where GCC warns, but only with extra warnings).
2016-12-15 17:47:10 +01:00
Michael Matz b1a906b970 enums and ints are compatible 2016-12-15 17:47:10 +01:00
Michael Matz c0368604e1 x86-64-asm: Fix ltr/str and push/pop operands
str accepts rm16/r32/r64, and push/pop defaults to 64 when given
memory operands (to 32 on i386).
2016-12-15 17:47:10 +01:00
Michael Matz 45b24c37a0 x86-64-asm: Implement high %cr registers 2016-12-15 17:47:09 +01:00
Michael Matz 4e46c22d5c struct-init: Support range inits for local vars
Implement missing support for range init for local variables.
2016-12-15 17:47:09 +01:00
Michael Matz 4cb7047f0f x86-64-asm: Support high registers %r8 - %r15
This requires correctly handling the REX prefix.
As bonus we now also support the four 8bit registers
spl,bpl,sil,dil, which are decoded as ah,ch,dh,bh in non-long-mode
(and require a REX prefix as well).
2016-12-15 17:47:09 +01:00
Michael Matz 8765826465 inline-asm: Accept "flags" clobber 2016-12-15 17:47:09 +01:00
Michael Matz b7ca74577b struct-init: Allow member initialization from qualified lvalues
See testcase.
2016-12-15 17:47:09 +01:00
Michael Matz 9e86ebee94 struct-init: Correctly parse unnamed member initializers
For
  union U { struct {int a,b}; int c; };
  union U u = {{ 1, 2, }};
The unnamed first member of union U needs to actually exist in the
structure so initializer parsing isn't confused about the double braces.
That means also the a and b members must be part of _that_, not of
union U directly.  Which in turn means we need to do a bit more work
for field lookup.

See the testcase extension for more things that need to work.
2016-12-15 17:47:09 +01:00
Michael Matz 7bf323843e struct-init: Cleanup
Remove dead code and variables.  Properly check for unions when
skipping fields in initializers.  Make tests2/*.expect depend
on the .c files so they are automatically rebuilt when the latter
change.
2016-12-15 17:47:09 +01:00
Michael Matz ed7d54651d struct-init: Implement initializing subaggregates
E.g. "struct { struct S s; int a;} = { others, 42 };"
if 'others' is also a 'struct S'.  Also when the value is a
compound literal.  See added testcases.
2016-12-15 17:47:09 +01:00
Michael Matz 5d0c16a884 Support attribute between double pointer stars
"int * __attribute__((something)) *" is supported by GCC.
2016-12-15 17:47:09 +01:00
Michael Matz 662338f116 Fix function to pointer conversion
This snippet is valid:
  void foo(void);
  ... foo + 42 ...
the function designator is converted to pointer to function
implicitely.  gen_op didn't do that and bailed out.
2016-12-15 17:47:08 +01:00
Michael Matz e034853b38 Fix parsing array typedefs of unknown size
This must compile:
 typedef int arrtype1[];
 arrtype1 sinit19 = {1};
 arrtype1 sinit20 = {2,3};
and generate two arrays of one resp. two elements.  Before the fix
the determined size of the first array was encoded in the type
directly, so sinit20 couldn't be parsed anymore (because arrtype1
was thought to be only one element long).
2016-12-15 17:47:08 +01:00
Michael Matz b7e0b693a6 tccpp: Implement __BASE_FILE__ macro
Like __FILE__ but always refers to the command line file name also
from inside headers.
2016-12-15 17:47:08 +01:00
Michael Matz 8a1a2a6033 Implement __builtin_choose_expr
Follows GCC implementation.
2016-12-15 17:47:08 +01:00
Michael Matz 10e4db45dc x86-asm: Implement prefetchw opcode 2016-12-15 17:47:08 +01:00
Michael Matz 5692716770 x86-asm: Fix lar opcode operands
lar can accept multiple sizes as well (wlx), like lsl.  When using
autosize it's important to look at the destination operand first;
when it's a register that one determines the size, not the input
operand.
2016-12-15 17:47:08 +01:00
Michael Matz 6a5ec8cb3c x86-asm: More opcodes
Some new opcodes and some aliases: ljmp[wl], prefetch{nta,t0,t1,t2},
bswap[lq], sysretq, swapgs.
2016-12-15 17:47:08 +01:00
Michael Matz d9d029006c x86-asm: Add [sl][ig]dtq opcodes
GAS has alias lgdtq for lgdt (similar for saves and GDT).  It doesn't
have the same for LDT.
2016-12-15 17:47:08 +01:00
Michael Matz f6c1eb10e2 x86-asm: Implement fxrstorq and fxsaveq 2016-12-15 17:47:08 +01:00
Michael Matz 2b618c1ab4 Fix parsing attributes for struct decls
Given this code:

  struct __attribute__((...)) Name {...};

TCC was eating "Name", hence generating an anonymous struct.
It also didn't apply any packed attributes to the parsed
members.  Both fixed.  The testcase also contains a case
that isn't yet handled by TCC (under a BROKEN #define).
2016-12-15 17:47:08 +01:00
Michael Matz 7e51546624 x86-asm: Implement clflush opcode 2016-12-15 17:47:08 +01:00
Michael Matz bbce31552e inline asm: accept concatenated strings in constraints
This really should be handled implicitly in the preprocessor,
but for now this is enough.
2016-12-15 17:47:08 +01:00
Michael Matz 10c3514889 Accept symbols in initializers also on 64 bit
Those should use long or long long type, and generate a 64bit reloc.
2016-12-15 17:47:07 +01:00
Michael Matz 920474115c x86-64-asm: More opcodes
Implement some more opcodes, syscall, sysret, lfence, mfence, sfence.
2016-12-15 17:47:07 +01:00
Michael Matz 1a5eacb445 tccasm: Implement compare expressions
I.e. implement < > <= >= == !=.  Comparisons are signed and result
is -1 if true, 0 if false.
2016-12-15 17:47:07 +01:00
Michael Matz ff5561ff7d x86-64-asm: Accept expressions for .quad
The x86-64 target has 64bit relocs, and hence can accept
generic expressions for '.quad'.
2016-12-15 17:47:07 +01:00
Michael Matz 253afeed1e inline asm: Accept 'p' constraint and 'P' template mod
'p' is conservatively the same as 'r' and 'P' as template
modifier can be ignored in TCC.
2016-12-15 17:47:07 +01:00
Michael Matz 63e3ff7cca tccasm: Accept .balign 2016-12-15 17:47:07 +01:00
Michael Matz 8e4da42384 Accept more asm expressions
In particular subtracting a defined symbol from current section
makes the value PC relative, and .org accepts symbolic expressions
as well, if the symbol is from the current section.
2016-12-15 17:47:07 +01:00
Michael Matz c82e52d55b tccasm: Implement .pushsection and .popsection 2016-12-15 17:47:06 +01:00
Michael Matz 6763b02abc Accept empty struct member decls
struct S { /*nothing*/; int a; };

is an acceptable struct declaration, there may be stray semicolons
in the member list.
2016-12-15 17:47:06 +01:00
Michael Matz d5d881d9e9 x86-asm: Accept 'q' modifier
In inline extended asm '%q1' refers to the 64bit register of operand 1.
2016-12-15 17:47:06 +01:00
Michael Matz 38e5cf0983 tccpp: Fix macro_is_equal
When tokens in macro definitions need cstr_buf inside get_tok_str,
the second might overwrite the first (happens when tokens are
multi-character non-identifiers, see testcase) in macro_is_equal,
failing to diagnose a difference.  Use a real local buffer.
2016-12-15 17:47:05 +01:00
Michael Matz 4094f7c5fc x86-64-asm: Tidy 2016-12-15 17:47:05 +01:00
Michael Matz 58963828ab x86-asm: Correct mem64->xmm movq
Now we can express prefixes with 0x0fxx opcodes we can correct the
movq mem64->xmm opcode, and restrict the movq xmm->mem64 movq to
not invalidly accept mmx.
2016-12-15 17:47:05 +01:00
Michael Matz ed35ac841b x86-asm: Add more SSE2 instructions
In particular those that are extensions of existing mmx (or sse1)
instructions by a simple 0x66 prefix.  There's one caveat for
x86-64: as we don't yet correctly handle the 0xf3 prefix
the movq mem64->xmm is wrong (tested in asmtest.S).  Needs
some refactoring of the instr_type member.
2016-12-15 17:47:05 +01:00
grischka 2b7ee000cd tests: add .so/.dll creation test
Also remove bitfield test from tcctest.c because gcc
versions don't agree among each other.
2016-12-15 17:04:07 +01:00
grischka ca92bfc3c6 tccelf: some linker cleanup
- generate and use SYM@PLT for plt addresses
- get rid of patch_dynsym_undef hack (no idea what it did on FreeBSD)
- use sym_attrs instead of symtab_to_dynsym
- special case for function pointers into .so on i386
- libtcc_test: test tcc_add_symbol with data object
- move target specicic code to *-link.c files
- add R_XXX_RELATIVE (needed for PE)
2016-12-15 17:01:22 +01:00
David Mertens d2e2f42382 Implement gcc bitfield algorithm; add -mms-bitfields 2016-11-28 09:01:12 -05:00
grischka 4a3741bf02 x86_64-asm: =m operand fixes
The problem was with tcctest.c:

    unsigned set;
    __asm__("btsl %1,%0" : "=m"(set) : "Ir"(20) : "cc");

when with tcc compiled with the HAVE_SELINUX option, run with
tcc -run, it would use large addresses far beyond the 32bits
range when tcc did not use the pc-relative mode for accessing
'set' in global data memory.  In fact the assembler did not
know about %rip at all.

Changes:
- memory operands use (%rax) not (%eax)
- conversion from VT_LLOCAL: use type VT_PTR
- support 'k' modifier
- support %rip register
- support X(%rip) pc-relative addresses

The test in tcctest.c is from Michael Matz.
2016-11-20 14:50:56 +01:00
Christian Jullien 70dec93f2b OpenBSD does not support -v option in rm command. 2016-10-15 14:59:52 +02:00
grischka ed15cddacd tccgen: 32bits: fix PTR +/- long long
Previously in order to perform a ll+ll operation tcc
was trying to 'lexpand' PTR in gen_opl which did
not work well.  The case:


    int printf(const char *, ...);
    char t[] = "012345678";

    int main(void)
    {
        char *data = t;
        unsigned long long r = 4;
        unsigned a = 5;
        unsigned long long b = 12;

        *(unsigned*)(data + r) += a - b;

        printf("data %s\n", data);
        return 0;
    }
2016-10-13 19:21:43 +02:00
Christian Jullien 8986bc8af4 Use ISO C string functions instead of obsolete BSD ones that used to be in strings.h. It allows more systems -- i.e. Windows -- to use those tests 2016-10-12 06:18:38 +02:00
grischka 71b16f4e18 tccpp : "tcc -E -P" : suppress empty lines
Also:
- regenerate all tests/pp/*.expect with gcc
- test "insert one space" feature
- test "0x1E-1" in asm mode case
- PARSE_FLAG_SPACES: ignore \f\v\r better
- tcc.h: move some things
2016-10-09 20:33:14 +02:00
grischka b691585785 tccgen: arm/i386: save_reg_upstack
tccgen.c:gv() when loading long long from lvalue, before
was saving all registers which caused problems in the arm
function call register parameter preparation, as with

    void foo(long long y, int x);
    int main(void)
    {
      unsigned int *xx[1], x;
      unsigned long long *yy[1], y;
      foo(**yy, **xx);
      return 0;
    }

Now only the modified register is saved if necessary,
as in this case where it is used to store the result
of the post-inc:

        long long *p, v, **pp;
        v = 1;
        p = &v;
        p[0]++;
        printf("another long long spill test : %lld\n", *p);

i386-gen.c :
- found a similar problem with TOK_UMULL caused by the
  vstack juggle in tccgen:gen_opl()
  (bug seen only when using EBX as 4th register)
2016-10-04 17:36:51 +02:00
Pavlas, Zdenek da63695cf3 switch: fix label sorting 2016-10-03 00:43:28 -07:00
grischka c2ad11ac70 tccgen: fix long long -> char/short cast
This was causing assembler bugs in a tcc compiled by itself
at i386-asm.c:352 when ExprValue.v was changed to uint64_t:

    if (op->e.v == (int8_t)op->e.v)
        op->type |= OP_IM8S;

A general test case:

    #include <stdio.h>
    int main(int argc, char **argv)
    {
        long long ll = 4000;
        int i = (char)ll;
        printf("%d\n", i);
        return 0;
    }

Output was "4000", now "-96".

Also: add "asmtest2" as asmtest with tcc compiled by itself
2016-10-02 01:39:14 +02:00
Balazs Kezes 49d3118621 Incorrect function call code on ARMv6
On 2016-08-11 09:24 +0100, Balazs Kezes wrote:
> I think it's just that that copy_params() never restores the spilled
> registers. Maybe it needs some extra code at the end to see if any
> parameters have been spilled to stack and then restore them?

I've spent some time on this and I've found an alternative solution.
Although I'm not entirely sure about it but I've attached a patch
nevertheless.

And while poking at that I've found another problem affecting the
unsigned long long division on arm and I've attached a patch for that
too.

More details in the patches themselves. Please review and consider them
for merging! Thank you!

--
Balazs

[PATCH 1/2] Fix slow unsigned long long division on ARM

The macro AEABI_UXDIVMOD expands to this bit:

  #define AEABI_UXDIVMOD(name,type, rettype, typemacro)                     \
  ...
      while (num >= den) {                                                  \
  ...
          while ((q << 1) * den <= num && q * den <= typemacro ## _MAX / 2) \
              q <<= 1;                                                      \
  ...

With the current ULONG_MAX version the inner loop goes only until 4
billion so the outer loop will progress very slowly if num is large.
With ULLONG_MAX the inner loop works as expected. The current version is
probably a result of a typo.

The following bash snippet demonstrates the bug:

  $ uname -a
  Linux eper 4.4.16-2-ARCH #1 Wed Aug 10 20:03:13 MDT 2016 armv6l GNU/Linux
  $ cat div.c
  int printf(const char *, ...);
  int main(void) {
    unsigned long long num, denom;
    num = 12345678901234567ULL;
    denom = 7;
    printf("%lld\n", num / denom);
    return 0;
  }
  $ time tcc -run div.c
  1763668414462081

  real    0m16.291s
  user    0m15.860s
  sys     0m0.020s

[PATCH 2/2] Fix long long dereference during argument passing on ARMv6

For some reason the code spills the register to the stack. copy_params
in arm-gen.c doesn't expect this so bad code is generated. It's not
entirely clear why the saving part is necessary. It was added in commit
59c35638 with the comment "fixed long long code gen bug" with no further
clarification. Given that tcctest.c passes without this, maybe it's no
longer needed? Let's remove it.

Also add a new testcase just for this. After I've managed to make the
tests compile on a raspberry pi, I get the following diff without this
patch:

  --- test.ref    2016-08-22 22:12:43.380000000 +0100
  +++ test.out3   2016-08-22 22:12:49.990000000 +0100
  @@ -499,7 +499,7 @@
   2
   1 0 1 0
   4886718345
  -shift: 9 9 9312
  +shift: 291 291 291
   shiftc: 36 36 2328
   shiftc: 0 0 9998683865088
   manyarg_test:

More discussion on this thread:
https://lists.nongnu.org/archive/html/tinycc-devel/2016-08/msg00004.html
2016-10-01 23:10:11 +02:00
grischka afdbc5b815 build: restore out-of-tree support 2016-10-01 21:06:53 +02:00
grischka 0a624782df build: revert Makefiles to 0.9.26 state (mostly)
Except
- that libtcc1.a is now installed in subdirs i386/ etc.
- the support for arm and arm64
- some of the "Darwin" fixes
- tests are mosly unchanged

Also
- removed the "legacy links for cross compilers" (was total mess)
- removed "out-of-tree" build support (was broken anyway)
2016-10-01 21:06:33 +02:00