Commit Graph

2869 Commits

Author SHA1 Message Date
Ole André Vadla Ravnås 722c253d8d Windows: Add basic arm64 support
The PE file bits are incomplete/incorrect for now though.
2024-07-18 14:57:25 +02:00
Ole André Vadla Ravnås a438164dd4 meson: Restore softfloat detection on QNX
Now that we have cherrypicked upstream patches to make it work.
2022-04-01 19:08:51 +00:00
herman ten brugge 23de9d234a OpenBSD: arm fix
Disable warning softfloat. OpenBSD works fine.
save/restore s0-s15 during memcpy call for structs
update configure script. Works now on raspberry pi/All BSD
Add eabi_mem.. functions in armeabi.c for OpenBSD
Fix fp register in tccrun.c for OpenBSD
2022-04-01 19:06:40 +00:00
herman ten brugge aefbb5274d BSD: arm support
Support OpenBSD/FreeBSD/NetBSD on asm.

move PAGESIZE to tcc.h and use _SC_PAGESIZE (netbsd/arm has 8192 pagesize)

arm:
- fix cmp instruction for qemu (raspberry pi works without patch?)
- increase start address/size
- use large plt size
- add return R_ARM_PREL31
- add R_ARM_TARGET1 to prepare_dynamic_rel
- add gcc_s to FreeBSD (unwind code)
- do not use __clear_cache on bsd (sometimes bad system call)
- do stack unwinding on bsd
- test/tcctest.c: use %lld %llu on bsd
2022-04-01 19:06:37 +00:00
Christian Jullien 48bc44c5e6 NetBSD: Trying to fix reloc error 38 on arm - WIP 2022-04-01 19:06:37 +00:00
Ole André Vadla Ravnås c3b596afb7 portability: Add support for QNX 2022-03-24 01:33:06 +03:00
Ole André Vadla Ravnås 4a87cff803 arm64: Add support for FreeBSD 2022-01-19 16:56:48 +01:00
Ole André Vadla Ravnås d0e5d115cf tccrun: Ensure `environ` is declared before use
It may not be declared by system headers.
2022-01-12 02:13:22 +01:00
Ole André Vadla Ravnås c420c41a1b meson: Override provided dependency
For convenience when used as a subproject.
2021-12-22 01:31:26 +01:00
Ole André Vadla Ravnås 3a12fb9371 tccelf: Ensure `libname` fits in `filename`
Caught by GCC 11.
2021-12-16 20:55:44 +01:00
Ole André Vadla Ravnås eb66d1acda meson: Fix usage of deprecated pkgconfig convention 2021-12-16 20:19:31 +01:00
meme 4c8e8bf419
meson: Add missing deps (#5)
Also noted by @QuLogic in GitHub comments prior.
2021-12-15 19:08:48 +01:00
Ole André Vadla Ravnås 71c2e2c3d5 Add Meson build system 2020-11-14 19:16:52 +01:00
Ole André Vadla Ravnås 263232e8cf Improve support for Apple's ABIs
- i386: Align first argument on a 16 byte boundary.
- arm64: Support Apple's version of the AArch64 ABI, including zero-
  extension of variadic arguments smaller than 32 bits.
- arm64e: Make all indirect branches authenticated, and sign function
  pointer values both from the perspective of the C code and when
  looking up symbols.
- arm64e: Support signing and stripping pointers.
- Query page size to support text segments larger than 4096 bytes on
  i/macOS systems with 16K pages.
- Avoid RWX page allocations on most platforms as they're off limits on
  modern Apple platforms.
- Split relocation and marking pages executable to avoid crashing when
  marking fails.

Co-authored-by: Francesco Tamagni <mrmacete@protonmail.ch>
2020-11-14 19:16:48 +01:00
Ole André Vadla Ravnås 7e6ed199c2 Add tcc_set_linker_resolve_func()
Useful for resolving symbols dynamically.
2020-11-12 23:36:58 +01:00
Ole André Vadla Ravnås 949e096b02 Add tcc_set_cpp_load_func()
Useful for loading preprocessor inputs from memory.
2020-11-12 23:36:58 +01:00
Ole André Vadla Ravnås 640e1a7827 Remove dangerous predefined macros
As macros without underscore prefix may easily conflict with identifiers
in source code.
2020-11-12 23:36:58 +01:00
Ole André Vadla Ravnås 7ba7c0d9ae Namespace “pstr” functions to avoid conflicts
E.g. when linking QuickJS into the same program or library.
2020-11-12 23:36:58 +01:00
Ole André Vadla Ravnås bd4332733d Rename filenames prone to include path conflicts
E.g. when used uninstalled as a submodule.
2020-11-12 23:34:32 +01:00
Ole André Vadla Ravnås 62cce2d421 Fix inconsistent TCC_TARGET_MACHO check 2020-11-12 23:34:32 +01:00
Ole André Vadla Ravnås d5c1aee8f1 Explicitly use Windows ANSI APIs
To avoid issues when building with unicode as the default character set.
2020-11-12 23:34:32 +01:00
Ole André Vadla Ravnås 2f72e38d60 Merge remote-tracking branch 'upstream/mob' 2020-11-10 20:57:11 +01:00
herman ten brugge 08d8015750 Fix fork problem 114_bound_signal
There is a race condition in old libc in fork().
The result was that 'end' was sometimes printed twice.

This did not happen with glibc-2.32.
2020-11-10 10:08:30 +01:00
herman ten brugge 54b4aa3cd6 Disable signals in bcheck.c pthread_create
glibc-2.32 contains new code to prevent a race conditions with signals
in pthread_create.
2020-11-09 10:57:14 +01:00
Ole André Vadla Ravnås ccd8d612e9 Revert to using RWX pages on Windows
Due to the function table being filled in right after.
2020-11-05 02:16:05 +01:00
Ole André Vadla Ravnås aef0cbabb4 Avoid RWX page allocations on all platforms
As they're off limits on some Apple platforms and we want to have the
same behavior on all platforms supported by Frida.

At some point it would be good to evolve TinyCC to support putting
writable data on separate pages.
2020-11-05 01:28:20 +01:00
grischka 8b69059f66 three small fixes & three reverts
- tcc.h: msvc doesn't grok __func__ (reverts previous commit)

- tccgen.c: fortify tcc against bogus code:
  - n[sizeof({3;})]; // statement expression outside of function
  - f(){"123"4}; // tokens with values following each other
  (also, add "type defaults to int" warning for variables)

- tccpe.c: removed a check that caused BSS symbols not to be
  exported.  Whatever that check was meant to prevent.

- win32/build-tcc.bat: cmd.exe sometimes doesn't grok '-' in labels

- Revert "libtcc: no need to undef"
  This reverts commit 2b7aa2a1e1.
- Revert "tcc.h libtcc.c: remove unused defines"
  This reverts commit 985d963745.

The point of these "unused defines" is to be unused,  that is
to remind people not to use malloc but please to "use_tcc_malloc",
instead.
2020-11-02 18:08:56 +01:00
Kyryl Melekhin 2b7aa2a1e1 libtcc: no need to undef 2020-11-01 15:51:50 +00:00
Kyryl Melekhin 985d963745 tcc.h libtcc.c: remove unused defines
pretty sure that functions with use_* do not exist
and attempts to use the macros will fail to link
I could rename them to be more up to date like tcc_malloc,
but to me overloading the std calls with macros is
probably taking away control from the programmer,
so for the best is to just get rid of them.
2020-11-01 15:24:45 +00:00
Ole André Vadla Ravnås 9c62e25b8b Add missing casts to fix compiler warnings 2020-10-31 04:48:17 +01:00
John Scott 53587ee415
tcc_internal_error: print function with __func__.
Though __func__ was introduced in C99, this is
preferable to __FUNCTION__, an obsolete GCC extension.
Found with gcc -Wpedantic.
2020-10-18 17:54:01 -04:00
John Scott 558c6f56e2
tcc_mallocz: clear with memset only if nonzero size
Even if non-NULL, dereferencing the pointer from malloc(0)
or passing it to memset() may invoke undefined behavior.
2020-10-16 21:20:33 -04:00
Ole André Vadla Ravnås c93d276e82 Namespace “pstr” functions to avoid conflicts
E.g. when linking QuickJS into the same program or library.
2020-10-15 22:38:45 +02:00
Ole André Vadla Ravnås 57e351b2dd Rename elf.h to avoid conflicts
E.g. when used as a submodule on the include path.
2020-10-15 21:49:59 +02:00
grischka 72b520e709 tccgen: flex arrays etc.
Fixes potential writes past the allocated space with mostly
illegal flex array initializers. (60_errors_and_warnings.c
:test_var_array)

In exchange suspicious precautions such as section_reserve
or checks with sec->data_allocated were removed.  (There is
an hard check 'init_assert()' for now but it's meant to be
just temporary)

Also, instead of filling holes, always memset(0) structures
& arrays on stack.  Sometimes more efficient, sometimes isn't.
At least we can omit putting null initializers.

About array range inititializers:  Reparsing tokens has a
small problem with sideeffects, for example

   int c = 0, dd[] = { [0 ... 1] = ++c, [2 ... 3] = ++c };

Also, instead of 'squeeze_multi_relocs()', delete pre-existing
relocations in advance. This works even if secondary initializers
don't even have relocations, as with
    [0 ... 7] = &stuff,
    [4] = NULL

Also, in tcc.h: new macro "tcc_internal_error()"
2020-10-03 18:12:46 +02:00
grischka 40395511d7 Revert "function pointer compare"
Always fine to try out things but not everything must be shown
to the public. ;)

Also, AFAIK pointers must compare equal only if derived directly
from each other (for example by cast to void* and back).

This reverts commit 8f9bf3f223.
2020-10-03 17:40:22 +02:00
grischka cdc3df949b tcc -bench: show text/data/bss binary output sizes 2020-10-02 19:50:45 +02:00
herman ten brugge ae1796fc34 Fix testcase 114 for arm and apple
Arm has a problem with tls after a fork. The pthread_key_create seems to
be forgotten?

Apple has a problem with the exit(0) code in do_fork(). An IO mutex
is still held after a fork().
2020-10-02 17:50:31 +02:00
Michael Matz 78da4586a0 Fix tests2/120_alias.c on macos
While MacOS doesn't natively support the alias attribute, let's support
it with TCC anyway.  This means we need to make a decision if the
string in the alias attribute is decorated or not due to the implicit
underscore on MacOS.  To make life easier we decide that it's the C name,
i.e. without underscore, and so TCC needs to emit alias names with
underscore handling.

Irrespective of that the test case needs to deal with the underscore
itself for __asm__ renaming which is always requiring the assembler name.
2020-10-01 18:03:56 +02:00
herman ten brugge 0da93838c1 Init range wth symbols
The init range with symbols did only init the first value.
The relocation for all other symbols was missing.
Also see testcase.

tccgen.c:
- New function get_init_string
- Use macro processing in decl_designator for each init string
- Use get_init_string in decl_initializer_alloc

tccelf.c:
- Fix insertion sort in squeeze_multi_relocs

tests/tests2/90_struct-init.c:
- Add test case test_init_ranges
2020-10-01 17:50:20 +02:00
herman ten brugge afc0917f88 Bound checking fixes
tccgen.c:
- Fix 'tcc -b conftest.s'
- Add offset during bound checking for struct return

lib/bcheck.c:
- Check overlap when reusing vla/alloca

arm-gen.c:
arm64-gen.c:
riscv64-gen.c:
lib/alloca86-bt.S:
- add space for vla/alloca during bound checking

tests/tests2/Makefile:
tests/tests2/121_struct_return:
tests/tests2/122_vla_reuse:
- New test cases with bound checking enabled to test vla and struct return
2020-10-01 17:09:09 +02:00
Michael Matz 352e1d0fc4 Reinstate attribute alias handling
commit 2a0167a merged alias and asm symbol renaming, but broke
semantics of aliases, see testcase.  Basically the difference between
the two is that an asm rename doesn't generate a new symbol, i.e. with

  int foo __asm__("bar");

all source reference to 'foo' will be to 'bar', nothing of the name
'foo' will remain in the object file, and for instance reference to
'foo' from other compilation units won't be resolved to this one.

Aliases OTOH create an additional symbol.  With:

  void target (void) { return; }
  void afunc (void) __attribute__((alias("target")));

reference to 'afunc' will remain 'afunc' in the object file.  It will
generate two symbols, 'afunc' and 'target' referring to the same entity.
This difference matters if other compilation units make references to
'afunc'.

A side requirement of this is that for alias to work that the target
symbol needs to be defined in the same unit.  For TCC we even require a
stricter variant: it must be defined before the alias is created.

Now, with this I merely re-instated the old flow of events before above
commit.  It didn't seem useful anymore to place both names in the
asm_label member of attributes, and the asm_label member of Sym now
again only needs the hold the __asm__ rename.

It also follows that tcc_predefs.h can't make use of attribute alias to
e.g. map __builtin_memcpy to __bound_memcpy (simply because the latter
isn't defined in all units), but rather must use __asm__ renaming, which
in turn means that the underscore handling needs to be done by hand.
2020-09-30 17:46:01 +02:00
herman ten brugge 727e24cb0a Add typedef debug info
tccgen.c:
- In tcc_get_debug_info mask VT_STORAGE instead of VT_EXTERN | VT_STATIC
- New function tcc_debug_typedef
- Call tcc_debug_typedef in decl0
2020-09-27 11:13:37 +02:00
herman ten brugge 8fd7a384e2 Fix bitfields init : tiny solution
tccgen.c: Check struct/union size for bitfield.
tests/tcctest.c: Add test code.
2020-09-25 12:23:48 +02:00
herman ten brugge 89ea62481d clang7 does not support zero sized structs
This happens with aarch64 on raspberry pi.
2020-09-21 15:55:58 +02:00
herman ten brugge 8f9bf3f223 function pointer compare
tccelf.c:
- Check if symbol is in data section and UNDEF. Then generate new
  relocation and let dynamic linker solve it.

tests/tests2/42_function_pointer.c:
- Add new test code
2020-09-21 09:18:48 +02:00
Christian Jullien ffac4e7688 Herman proposed patch seems to fix clang issue on x64 Debian 2020-09-19 08:04:20 +02:00
grischka 8cb3e5368f bitfields init : tiny solution
This replaces commit 5c6356ff8e,
except the tests.
2020-09-18 23:31:34 +02:00
herman ten brugge 5c6356ff8e default-initialization of bitfields
The code:

struct bf_SS {unsigned int bit:1,bits31:31; };
void func(void) {
  struct bf_SS bf_finit = { .bit = 1 };
}

will not init bits31 to 0.

tccgen.c:
- check_bf: New function to check if bitfield is present in struct/union
- decl_initializer: Call check_bf and set value to 0 is bitfield found

tests/tcctest.c:
- Add struct bitfield test code
2020-09-18 19:20:57 +02:00
Christian Jullien 6d819d7267 Indentation was missing after empty string check was added by wanjochan. 2020-09-18 06:39:30 +02:00