Commit Graph

2541 Commits

Author SHA1 Message Date
Ole André Vadla Ravnås
9c62e25b8b Add missing casts to fix compiler warnings 2020-10-31 04:48:17 +01: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
Ole André Vadla Ravnås
e95115b474 Remove dangerous predefined macros
As macros without underscore prefix may easily conflict with identifiers
in source code.
2020-07-23 20:22:45 +02:00
Francesco Tamagni
dbf4486c4c
Add support for signing and stripping pointers on arm64e (#4) 2020-04-10 10:41:30 +02:00
Francesco Tamagni
ebfb419a72
Query page size on Apple platforms (#3)
This fixes support for text segments larger than 4096 bytes on iOS
systems with 16K pages.
2020-03-25 02:59:15 +01:00
Ole André Vadla Ravnås
17df98d861 arm64: Adhere to the iOS/arm64e ABI
By making all indirect branches authenticated, and signing function
pointer values both from the perspective of the C code and when looking
up symbols.
2020-03-10 02:51:19 +01:00
Francesco Tamagni
cde20fcac0 Split relocation and marking pages executable (#1)
To avoid crashing when marking fails.
2019-11-25 21:20:39 +01:00
Ole André Vadla Ravnås
326ebc6f5d Suppress warnings reported by GCC
We want to keep our TinyCC patch-set minimal.
2019-10-11 19:08:38 +02:00
Ole André Vadla Ravnås
394ce61f8d arm64: Add support for iOS/arm64e 2019-10-09 17:08:21 +02:00
Ole André Vadla Ravnås
02bb3598ce arm64: Zero-extend variadic arguments smaller than 32 bits
This is required by Apple's ABI, but is also mandated by the C default
argument promotions.
2019-09-17 00:49:31 +02:00
Ole André Vadla Ravnås
1fea9172b4 arm64: Add support for Apple's ABI 2019-09-17 00:49:27 +02:00
Ole André Vadla Ravnås
c8c945f83b i386: Align first argument on a 16 byte boundary
As it is required by Apple's ABI.
2019-09-14 03:39:47 +02:00
Ole André Vadla Ravnås
ec4fb94d7d Add tcc_set_linker_resolve_func()
Useful for resolving symbols dynamically.
2019-09-13 21:29:18 +02:00
Ole André Vadla Ravnås
beb4f8bc0e Add tcc_set_cpp_load_func()
Useful for loading preprocessor inputs from memory.
2019-09-13 21:29:18 +02:00
Ole André Vadla Ravnås
62d25e4f89 Add tcc_enumerate_symbols() 2019-09-13 21:29:15 +02:00
Ole André Vadla Ravnås
8de8647c7d Port to iOS 2019-09-13 18:01:31 +02:00
Ole André Vadla Ravnås
2f2aea459c Tweak to fit into the GumJS build system 2019-09-13 18:01:26 +02:00
Siddhesh Poyarekar
7d4a71fc8b arm64: Increase page size
Fedora, RHEL and Centos have a default page size of 64K for arm64, so
bump up the page size so that ELF sections of the generated inary are
correctly aligned for 64K pages too.
2019-09-03 12:39:05 +05:30
Michael Matz
9264f06efe Improve ?: expansion a little
there's no need to prematurely convert the condition into registers
before emitting the test.
2019-09-01 23:13:21 +02:00
Michael Matz
91e297acd3 riscv: Optimize compares
don't convert to 1/0 prematurely, we can save enough info
in the VT_CMP metadata to be usable for the gtst branch expansion.
2019-09-01 23:13:21 +02:00
Michael Matz
48ba22c744 riscv: Replace RR insn emitter with specific one
instead of using o() directly.  Makes the code a little easier
to read.
2019-09-01 23:13:21 +02:00
Michael Matz
d5bb407cc4 riscv: Add special cases for const operands
RISC-V supports small immediates for some operations, let's
use them.
2019-09-01 23:13:21 +02:00
Michael Matz
f8d80464a9 riscv: factor load/store code
split out common code and tidy result.
2019-09-01 23:13:21 +02:00
Michael Matz
83cf5bf17f riscv: TLC of param passing
factor and cleanup the param passing code somewhat.
2019-09-01 23:13:21 +02:00
Michael Matz
c505074a9f riscv: rewrite parameter passing
this fixes the ret_mixed_test of abitest.c, now everything of the
testsuite works.

The generic code for returns is good enough for our use, except in
the specific case of a mixed int/float structures returned in registers,
so instead of duplicating the whole generic gfunc_return function, add
another modus for gfunc_sret: returning -1 makes the actual register
transfer by a new backend function.
2019-09-01 23:13:21 +02:00
Michael Matz
9b0efa9346 riscv: Make PLT reloc be AUTO_GOT
relocs against defined symbols are replaced by relative
relocs, when a GOT slot is created.  But code relocs (usually
calls via PLT) use the plt_offset member of attr, not the got_offset
member, so the "huh" warning was triggered in the case of calls to
static functions (the code still worked).

So, for now just use the AUTO_GOT_PLT mechanism.  We could also
emit a non-PLT reloc in the backend for calls to VT_STATIC functions
(like the x86-64 backend does) and do the same as for x86-64 in
build_got_entries (which transforms PLT32 into PC32 relocs, riscv
would transform CALL_PLT into CALL relocs).  Maybe later.
2019-09-01 23:13:21 +02:00
Michael Matz
0cb6e3fff8 riscv: Fix mixed2 and mixed3 abi tests
this was caused by a simple bug, not by the current inability
to pass a {float,int} struct per psABI.  So now only ret_mixed_test
is still broken.
2019-09-01 23:13:21 +02:00
Michael Matz
98f1b83ffe riscv: Start fixing float struct passing/returnig
this fixes ret_2float_test, ret_2double_test and
ret_8plus2double_test of abitest.c.  The common gfunc_return
actually works for these cases, so let's use that for now.

The ret_mixed_test (as well as mixed2 and mixed3) are left
broken, and tccgen.c:gfunc_return can't be used for that as is,
so I'll leave the gfunc_return implementation in riscv64-gen.c for
now, I'll have to think about this some more.
2019-09-01 23:13:20 +02:00
Michael Matz
98dc4c123d riscv: Fix stdarg_many_test
if named params are passed on stack, the va_arg area begins after
that, not at sp+0.  Fixes abitest:stdarg_many_test.
2019-09-01 23:13:20 +02:00
Michael Matz
e9c2a1996a riscv: Fix tcctest.c
this is it!  With this tcctest.c works, as well as compiling
TCC with itself.  abitest.c doesn't yet work due to known
problems, all the rest does.  There are still warnings during
linking.
2019-09-01 23:13:20 +02:00
Michael Matz
509f561823 riscv: fix more sign/zero-extension problems
see the testcase.  For the signed case this problably does
the wrong thing, and it should break other archs.  Rework once
there are testcases for this.
2019-09-01 23:13:20 +02:00
Michael Matz
1ada32900b riscv: Fix ftoi and ftof(long double->float)
float to int must be truncations, not normal rounding.
And ftof was typoed to select the wrong conversion function.

This fixes tcctest.c completely.  (make -C tests test1)
2019-09-01 23:13:20 +02:00
Michael Matz
06184aec53 riscv: fix relocs for global syms
loads and stores to global symbols need to go via the
GOT (at least for weaks), otherwise -run doesn't work.
Ideally we'd generate GOT relocs (and loads) always and replace
them with PCREL relocs and adds during linking.
2019-09-01 23:13:20 +02:00
Michael Matz
69c77d1597 riscv: Fix unsigned 32bit loads
the invariant for the risc-v codegen is, that 64bit regs
generally contain the sign-extension of a 32bit value.
This wasn't heeded by loads of 32bit values from memory, which
used lwu and ultimately caused a miscompilation in string_test
of tcctest.c.

Now most of tcctest.c works (not with -run, but with linking
a real executable), except some ftoi/ftof conversions.
2019-09-01 23:13:20 +02:00
Michael Matz
2668eda595 riscv: Implement long double support
for the implementation of operations we can reuse the ones
from lib/lib-arm64.c, risc-v long double is also float128.
Also implement ggoto, and PDIV, and use t0 in load/store as
temporary register if necessary, not one given by get_reg
(the latter can destroy assignments of long double parameters
in function calls that are already set up).

This let's us compile tcc.c and tcctest.c, though both
don't yet work.
2019-09-01 23:13:20 +02:00
Michael Matz
2616c6b230 riscv: Fix 73_arm.c
some constants were loaded wrong (e.g. 0xffffabcdU), and
risc-v needs to do explicit zero-extensions for widening from
32bit (not sign-extensions like the other 64bit targets).

This makes the whole tests2.all testsuite work.

Parameter passing is still not psABI-compliant, but internally
consistent.  (e.g. structs of two floats/doubles are passed
in integer registers, but should sit in float regs).
2019-09-01 23:13:20 +02:00
Michael Matz
982de78e8d riscv: implement stdarg functions
this also fixes passing of params > 16 bytes.  In riscv
they aren't passed by value on stack, but via reference (and
because callees are allowed to modify by-ref params the caller must
allocate an own copy per call).

This fixes the stdarg parts of 73_arm.c.
2019-09-01 23:13:20 +02:00
Michael Matz
f44df9d85b riscv: some work on large function arguments
like long double (16 bytes) and structs.  Not completely
correct, but 73_arm64 somewhat works now (when the stdarg part
is disabled), though with some errors.  What's definitely incorrect
is arguments of a mixed int/float struct.  I'm using VT_LDOUBLE
(which conveniently has to be placed in a int-reg-pair) to load/store
structure arguments of size > 8 and <= 16, and that can lead to
overreads.
2019-09-01 23:13:20 +02:00
Michael Matz
ddb0c2de92 riscv: support large stack and far jumps
for 101_cleanup we need 256kb stack (with the associated problem
of needing a larger prologue/epilogue) as well as jumps out of
range for the 21bit offsets (exactly for second part of the prologue).
2019-09-01 23:13:19 +02:00
Michael Matz
b69c2ea2cf riscv: fix 90_struct-init
indirect calls were broken.
2019-09-01 23:13:19 +02:00
Michael Matz
31ecaa7c28 riscv: GOT loads, signed remainder, ELF flags
* support loading sym addresses from GOT: important for weak syms,
  fixes 104_inline.  This is still incomplete, it only works
  for taking the sym address, not for directly loading/storing into
  such symbols (i.e. not for VT_LVAL)
* another op: '%'
* ELF flags: add EF_RISCV_FLOAT_ABI_DOUBLE, which is our ABI.
2019-09-01 23:13:19 +02:00
Michael Matz
b0329ac081 riscv: predefine more macros
RISC-V uses some more control macros for features (e.g. used
int <setjmp.h> to declare the jumpbuf contents).
2019-09-01 23:13:19 +02:00
Michael Matz
5390a729d9 riscv: Implement VLA stuff
makes 78_vla_label and 79_vla_continue work.
2019-09-01 23:13:19 +02:00
Michael Matz
9164594d1f riscv: load 64bit constants, and 32bit shifts
fixes 95_bitfields.  loading 64bit constants is suboptimal
right now.  int32_t shifts really need to use the W form,
otherwise 'x << 24 >> 24' doesn't extract the low 8 bits.
2019-09-01 23:13:19 +02:00
Michael Matz
215bc1aab4 riscv: Add sar, shr insn
fixes 92_enum_bitfield.
2019-09-01 23:13:19 +02:00
Michael Matz
f64d460d29 riscv: fix 72_long_long_constant
32bit signed constants larger than 0x7ffff800 were handled wrongly.
2019-09-01 23:13:19 +02:00
Michael Matz
5fcb87138d riscv: Handle more relocs
those happen on SUSE systems.
2019-09-01 23:13:19 +02:00
Michael Matz
9309585dbe riscv: some long double support
long double on risc-v is 128bit, but there are no registers
for that type (without the Q ISA extension).  They are passed
like two 64bit integers values (with an exception for varargs,
where it's an aligned register pair).  This all requires some
hacks in generic code as otherwise RC_FLOAT regs are tried for
holding values of long double type, but we need a RC_INT register
pair.  This really could all use some cleanup for all archs.

This doesn't implement any conversions of operations for long
double, but it's enough to get 70_floating_point_literals working.
2019-09-01 23:13:19 +02:00
Michael Matz
9c1b17407f riscv: Make 32_leds work
* more ops: umod and udiv
* large immediates: suboptimal code, e.g. when loading
  0xffffffffU (which is what a cast from long to int does).

tests2 work up to 67_macro_concat.
2019-09-01 23:13:19 +02:00