Commit Graph

2781 Commits

Author SHA1 Message Date
grischka
53d815b8a0 win32/tccpe: use full dll-path with -run
This allows for example this scenario:

- A dll to be linked with is specified in file.c, where file.c
  and the dll exist in the same directory:
    #pragma comment(lib, "txml")
    #pragma comment(option, "-L{f}")

- tcc is called to run file.c from other, varying directories:
    $ tcc -run some/dir/file.c <args...>

Note that tcc replaces {f} by the currently compiled file's
directory ('some/dir' in this example).

Also:
- tccgen.c: fix last commit for gen_cast.
2020-08-21 22:47:56 +02:00
grischka
d746e32349 tests2: rework 117..119 to follow our conventions
Please respect some conventions:

- tests2 filenames don't end with '..._test'

- tests2 tests are meant to produce some output

- the output should be somehow informative, not just
  "error" or "dummy". Because other people would want to
  know where it fails if it does.

- tests2 tests should work with both GCC and TCC, except
  if there are specifc reasons (like testing tcc-only
  feature such as bounds checking)

- tests2 tests should never crash or abort.  Because that
  would cause gui dialogs to pop up on windows, and because
  other people would not know where it fails if it does.

- tests2 tests should be somehow specific, in general.
  (rather than just collections of random stuff)

- in general, do not use 'long' if you mean 'larger than int'
  Because it isn't on many platforms.

- use four (4) spaces for block indention.  Do not insert
  tab characters in files if possible.

Also:
- tccgen.c:gen_cast() simplify last fix.
2020-08-21 21:44:11 +02:00
grischka
f9870f7860 bcheck: remove static (compile-time) control
Providing both run-time and compile-time control for bounds
checking as an user interface appears unnecessary and confusing.

Also:
- replace 'bound_...' by 'bounds_...' for consistency
- tcc-doc: put related info into one place and cleanup

The __bounds_checking(x) function is still missing explanation.
(I.e. what happens if the accumulated value drops below zero.)
2020-08-21 20:26:36 +02:00
herman ten brugge
a34a9775ba Fix char to ushort cast
tccgen.c:
- gen_cast: add check for char to ushort cast

tests/bug.c:
- remove tst1

tests/tests2/117_gcc_test.c:
- add tst_cast
2020-08-21 19:35:30 +02:00
herman ten brugge
696b765437 Fix switch/case
Fix switch for signed/unsigned switch
Also add new testcase 118
2020-08-18 20:05:53 +02:00
Willy Tarreau
b107f7bdd9 Fix switch/case on uint64_t
The switch/case operation was entirely performed on int64_t, resulting
in a warning and bad code to be emitted on 64 bit machines when used on
an unsigned long with a case range whose signed representation starts
positive and ends negative like in the example below:

  #include <limits.h>
  #include <stdio.h>
  #include <stdlib.h>

  int nbdg(unsigned long n)
  {
  	switch (n) {
  	case                    1UL ...                   9UL: return 1;
  	case                   10UL ...                  99UL: return 2;
  	case                  100UL ...                 999UL: return 3;
  	case                 1000UL ...                9999UL: return 4;
  	case                10000UL ...               99999UL: return 5;
  	case               100000UL ...              999999UL: return 6;
  	case              1000000UL ...             9999999UL: return 7;
  	case             10000000UL ...            99999999UL: return 8;
  	case            100000000UL ...           999999999UL: return 9;
  	case           1000000000UL ...          9999999999UL: return 10;
  	case          10000000000UL ...         99999999999UL: return 11;
  	case         100000000000UL ...        999999999999UL: return 12;
  	case        1000000000000UL ...       9999999999999UL: return 13;
  	case       10000000000000UL ...      99999999999999UL: return 14;
  	case      100000000000000UL ...     999999999999999UL: return 15;
  	case     1000000000000000UL ...    9999999999999999UL: return 16;
  	case    10000000000000000UL ...   99999999999999999UL: return 17;
  	case   100000000000000000UL ...  999999999999999999UL: return 18;
  	case  1000000000000000000UL ... 9999999999999999999UL: return 19; // this one
  	case 10000000000000000000UL ...             ULONG_MAX: return 20;
  	}
  	return 0;
  }

  int main(int argc, char **argv)
  {
  	unsigned long v = strtoul(argc > 1 ? argv[1] : "1111", NULL, 0);
  	printf("%lu : %d\n", v, nbdg(v));
  	return 0;
  }

  $ tcc dg.c
  dg.c:26: warning: empty case range
  $ x="";for i in 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0; do x=$x$i; ./a.out $x;done
  1 : 1
  12 : 2
  123 : 3
  1234 : 4
  12345 : 5
  123456 : 6
  1234567 : 7
  12345678 : 8
  123456789 : 9
  1234567890 : 10
  12345678901 : 11
  123456789012 : 12
  1234567890123 : 13
  12345678901234 : 14
  123456789012345 : 15
  1234567890123456 : 16
  12345678901234567 : 17
  123456789012345678 : 18
  1234567890123456789 : 0
  12345678901234567890 : 20

What this patch does is to use a separate set of signed and unsigned
case_cmp functions depending on whether the expression is signed or
unsigned, and also does this to decide when to emit the warning.

The bad code on output was caused by the removal of the unsigned bit
resulting from the signed sort, which causes only signed comparisons
to be emitted in the asm code. As such some sets could not match.

Note that there is no way to rely on the values only to sort properly
nor to emit the warning because we're effectively dealing with 65-bit
arithmetic here and any two values will have a different behavior
depending on the signed or unsigned expectation.

For unsigned expressions now the warning only happens when bounds are
switched, For signed expressions (e.g. if the input is signed long
above), the warning remains and the abnormal output as well. In both
cases this remains consistent with what gcc produces.
2020-08-18 11:27:27 +02:00
wanjochan
3613a11454 rm helper scripts newly added by me 2020-08-16 10:46:19 +08:00
wanjochan
777c017034 cleanup win32/tccwin_build.sh 2020-08-15 11:13:10 +08:00
Thomas Preud'homme
62c30a4a13 Fix typo in tcc-doc 2020-08-14 22:54:51 +01:00
herman ten brugge
4c9e3a5988 Update attribute bound_no_checking
tcctok.h:
- Add CONFIG_TCC_BCHECK  arround TOK_NO_BOUND_CHECK1/TOK_NO_BOUND_CHECK2

tccgen.c:
- Add CONFIG_TCC_BCHECK  arround TOK_NO_BOUND_CHECK1/TOK_NO_BOUND_CHECK2
- Undo alias definition in tccpp.c when function bound checking if off

tests/tests2/114_bound_signal.c:
- Test alias undo
- fix sleep problem
2020-08-14 06:35:47 +02:00
herman ten brugge
c740fa2795 Fix attribute patch for windows 2020-08-13 11:26:59 +02:00
herman ten brugge
50fe33f880 Add attribute bound_no_checking
tcc-doc.texi:
- Document attribute bound_no_checking

tcctok.h:
- Add bound_no_checking attribute

tcc.h:
- Add no_bcheck function attribute

tccgen.c:
- Use function attribute no_bcheck in merge_funcattr/parse_attribute/gen_function

bcheck.c:
- Fix no_checking in __bound_new_region/__bound_free/__bound_check

tests/tests2/114_bound_signal.c:
- Fix code with new attribute bound_no_checking

tests/tests2/103_implicit_memmove.c:
- Fix memmove prototype
2020-08-13 11:19:11 +02:00
wanjochan
5aaed43efd tune win32/tccwin_build.sh for libtccXX.dll 2020-08-13 12:34:03 +08:00
wanjochan
a06e8350aa helper script: build tcc32.exe tcc64.exe libtcc32.dll libtcc64.dll 2020-08-12 18:30:14 +08:00
wanjochan
cdf001c296 helper scripts for windows 2020-08-12 10:21:19 +08:00
herman ten brugge
70b16cb7f8 Fix argv/environ bound checking 2020-08-11 08:39:12 +02:00
herman ten brugge
8b8e714517 Fix bound checking for packed struct 2020-08-11 07:33:11 +02:00
herman ten brugge
09ed7e9557 Add bool debug type 2020-08-11 07:23:01 +02:00
herman ten brugge
e5da657c85 Fix testcase 95 for windows 2020-08-09 08:28:45 +02:00
herman ten brugge
dcb87d36fe Fix long bitfield
The fix is avoiding a core dump for radare2 project.
2020-08-09 07:50:34 +02:00
wanjochan
9085b38a71 add "libtcc.osx" entry to Makefile, for programs who need more pure libtcc.dylib without "@rpath/" config 2020-08-07 21:10:39 +08:00
herman ten brugge
3cfaaaf1eb Fix dll on arm.
Do not output the arm stack unwinding section (SHT_ARM_EXIDX).
2020-08-05 13:55:11 +02:00
herman ten brugge
a0a0f4d029 Add riscv dll support
Most support was already present.

riscv64-link.c:
- create_plt_entry:
 - remove DLLs unimplemented!
- relocate:
 - Add TCC_OUTPUT_DLL for R_RISCV_32, R_RISCV_64

tccelf.c:
- prepare_dynamic_rel:
 - Add R_RISCV_32, R_RISCV_64
2020-08-04 10:36:47 +02:00
herman ten brugge
b8fb2b02d9 Add arm dll support
Most support was already present.

arm-link.c:
- set RELOCATE_DLLPLT to 1
- create_plt_entry:
 - remove DLLs unimplemented!
 - leave code gen to relocate_plt. only set got_offset
- relocate_plt:
 - create code for got entry
- relocate:
 - Add TCC_OUTPUT_DLL for R_ARM_ABS32

tccelf.c:
- prepare_dynamic_rel:
 - Add R_ARM_ABS32
- alloc_sec_names:
 - Always add SHT_ARM_ATTRIBUTES section
- New function create_arm_attribute_section
- elf_output_file:
 - call create_arm_attribute_section
2020-08-04 09:15:42 +02:00
herman ten brugge
1da7159689 Add arm64 dll support
Most support was already present.

arm64-link.c:
- create_plt_entry:
 - remove DLLs unimplemented!
- relocate:
 - Add TCC_OUTPUT_DLL for R_AARCH64_ABS64/R_AARCH64_ABS32/R_AARCH64_PREL32

tccelf.c:
- prepare_dynamic_rel:
 - Add R_AARCH64_ABS64/R_AARCH64_ABS32/R_AARCH64_PREL32
- fill_got_entry:
 - Change 'TCC_TARGET_X86_64' into 'PTR_SIZE == 8'
2020-08-01 19:44:49 +02:00
herman ten brugge
d55a3f3362 Fix riscv64 compare problem.
Fix 64->32 bits sign/zero extention for riscv64.
2020-07-30 09:40:35 +02:00
herman ten brugge
d1ce34448f Faster load/store arm64
The load/store code is optimized to make better use of the offsets
present in the load/store instructions.
Also use GOT reloc's instead of ABS64 relocs.

arm64-gen.c/arm64_check_offset:
- New function to split offset used by load/store and by arm64_sym.

arm64-gen.c/arm64_sym:
- Use GOT reloc's instead of ABS64 relocs.

arm64-gen.c/load arm64-gen.c/store:
- Use new arm64_check_offset function.

arm64-gen.c/gen_bounds_prolog arm64-gen.c/gen_bounds_epilog:
- Use GOT reloc's instaed of ABS64 relocs.
2020-07-30 09:26:20 +02:00
Christian Jullien
58be11f701 Add L suffix to LDBL values. 2020-07-16 07:59:34 +02:00
Michael Matz
9b2329f66c riscv64: Work around qemu bug
old qemu (before april 2020) have a bug in the layout of
struct ucontext, so we get invalid values under qemu-userspace emulation
when inspecting the signal context.  Try to recognize this and
graciously error out instead of segfaulting in the backtracer routines.
2020-07-15 23:11:58 +02:00
Michael Matz
2e798523e4 Fix conversions of subnormals to long double
those need to be normalized when extending from float/double to
binary128.
2020-07-15 22:02:02 +02:00
Michael Matz
a614269794 riscv64: Fix a corner case
found in mpfr.  Expressions like "(longlong)i <= MAX_ULONGLONG" are
always true (not yet short-circuited in tcc), but still need to be
handled correctly in the backends.
2020-07-15 21:47:39 +02:00
Christian Jullien
92769362c7 Fix LDBL_xx values for aarch64 and riscv 2020-07-15 15:55:49 +02:00
herman ten brugge
c1e1c17c0a Move bound functions to tccgen.c
Move gen_bounded_ptr_add() and gen_bounded_ptr_deref() code to tccgen.c
No functional changes.
2020-07-12 10:55:40 +02:00
Christian Jullien
8314119662 USES: add mpc library 2020-07-11 20:00:37 +02:00
Christian Jullien
497678eee3 USES: just tested with gmp and mpfr on RPi 2020-07-11 07:42:18 +02:00
Christian Jullien
b5af2d3428 Add -C gcc compatible option which does currently nothing. This allows, among others, to compile gnumake from git ROOTB. 2020-07-11 06:41:44 +02:00
Christian Jullien
28e9fc1913 macos: 'make uninstall' also removes *.dylib 2020-07-10 10:38:36 +02:00
Christian Jullien
e19665c0d8 USES: add zlib 2020-07-10 06:35:02 +02:00
Steffen Nurpmeso
513a8b074d USES: s-nail 2020-07-09 23:52:43 +02:00
Avi Halachmi (:avih)
c69290fb0c macos: support arbitrary configure --libdir
Previously, after installation, only ../lib relative to the binary was
supported for finding libtcc.dylib, now any custom libdir.
2020-07-10 00:03:48 +03:00
Christian Jullien
6c94df6e2d macos: add path relative ../lib 2020-07-09 19:37:37 +02:00
Christian Jullien
6bd0ced239 Add USES file which list some software known to support tcc builds. 2020-07-09 17:21:23 +02:00
Christian Jullien
af0370a75d macos: add tcc version to libtcc.dylib. It can be shown with 'otool -L'. 2020-07-09 14:25:19 +02:00
Christian Jullien
b5a89c8c93 macos: tcc searches for libtcc.dyln in the same directory as its executable 2020-07-09 12:04:57 +02:00
Christian Jullien
1ea425811a macos: ldd does not exit, use otool instead 2020-07-09 08:03:31 +02:00
herman ten brugge
9d75f14107 Fix structure passing i386 PE
The orignal code does:
    push eax/edx/size
    call alloca
    pop  eax/edx/size

The pop does not work because the stack pointer has changed.
To make this also work with bound checking the code is now
using the stack probing from alloca.
2020-07-08 15:48:15 +02:00
herman ten brugge
20fa63488a Fix bounds checking
i386-gen.c:
- Fix large stack size alloca code.
  The returned value of alloca was not used corectly.

libtcc.c:
- Use __SIZE_TYPE__ for __builtin_offsetof

tccpp.c:
- Fix __MAYBE_REDIR and abort builtins.

tests/tests2/Makefile
- Run 117_gcc_test also with bound checking enabled
  This found the above problems.
2020-07-07 21:10:51 +02:00
Christian Jullien
49e2d06921 macos: initialize macho struct with memset which removes a clang warning on macOS. 2020-07-07 07:47:48 +02:00
herman ten brugge
fc05da3c0b Fix alloca and arm problems
alloca is only defined for i386 and x86_64
arm has __aeabi_ prefixes for mem... calls
2020-07-06 20:10:56 +02:00
Michael Matz
40671f76e4 Fix parsing of .s files
those aren't preprocessed, but our use of a fake file in
preprocess_start requires inline stack processing (which isn't done
without preprocessing).  Just don't try to setup anything requiring
preprocessing at all in this case.
2020-07-06 18:12:35 +02:00