Commit Graph

424 Commits

Author SHA1 Message Date
Anthony Green
01db31d94e Update moxie sub opcode 2018-03-13 20:41:55 -04:00
Stef O'Rear
3840d49aaa New RISC-V port (#281)
* Add RISC-V support

This patch adds support for the RISC-V architecture (https://riscv.org).

This patch has been tested using QEMU user-mode emulation and GCC 7.2.0
in the following configurations:

* -march=rv32imac -mabi=ilp32
* -march=rv32g -mabi=ilp32d
* -march=rv64imac -mabi=lp64
* -march=rv64g -mabi=lp64d

The ABI currently can be found at
https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md .

* Add RISC-V to README

* RISC-V: fix configure.host
2018-03-11 08:55:15 -04:00
Anthony Green
dca52b55bc Merge pull request #406 from trofi/master
ia64: fix variadic function closures with FP arguments
2018-03-11 08:50:01 -04:00
Anthony Green
83d9aba3a4 Merge pull request #407 from trofi/ia64-small-struct
ia64: fix small struct return
2018-03-11 08:48:42 -04:00
Andreas Schwab
e66fd67820 Revert "Fix passing struct by value on aarch64"
This reverts commit 482b37f004.

That was actually a bug in python, see <https://bugs.python.org/issue30353>.
2018-02-20 10:47:09 +01:00
Sergei Trofimovich
b58caef7fd ia64: fix small struct return
This change fixes libffi.call/struct10.c failure on ia64:
FAIL: libffi.call/struct10.c -W -Wall -Wno-psabi -O0 execution test

.Lst_small_struct handles returns for structs less than 32 bytes
(following ia64 return value ABI [1]). Subroutine does roughly the
following:

```
    mov [sp+0]  = r8
    mov [sp+8]  = r9
    mov [sp+16] = r10
    mov [sp+24] = r11
    memcpy(destination, source=sp, 12);
```

The problem: ia64 ABI guarantees that top 16 bytes of stack are
scratch space for callee function. Thus it can clobber it. [1]
says (7.1 Procedure Frames):
"""
* Scratch area. This 16-byte region is provided as scratch storage
  for procedures that are called by the current procedure. Leaf
  procedures do not need to allocate this region. A procedure may
  use the 16 bytes at the top of its own frame as scratch memory,
  but the contents of this area are not preserved by a procedure call.
"""

In our case 16 top bytes are clobbered by a PLT resolver when memcpy()
is called for the first time. As a result memcpy implementation reads
already clobbered data frop top of stack.

The fix is simple: allocate 16 bytes of scrats space prior to memcpy()
call.

[1]: https://www.intel.com/content/dam/www/public/us/en/documents/guides/itanium-software-runtime-architecture-guide.pdf

Bug: https://bugs.gentoo.org/634190
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2018-02-17 19:01:29 +00:00
Sergei Trofimovich
11de69ddb7 ia64: fix variadic function closures with FP arguments
libffi test framework already flagged failures as:

```
    FAIL: libffi.call/cls_double_va.c -W -Wall -Wno-psabi -O0 output pattern test, is 7.0
    res: 4
    0.0
    res: 4
    ? should match 7.0
    ?es: 4
    ?.0
    res: 4
```

Failure happens here at

```c
    // testsuite/libffi.call/cls_double_va.c
    ...
    char*  format    = "%.1f\n";
    double doubleArg = 7;
    ...
    CHECK(ffi_prep_closure_loc(pcl, &cif, cls_double_va_fn, NULL,
                               code) == FFI_OK);
    res = ((int(*)(char*, ...))(code))(format, doubleArg);
```

libffi expects 'doubleArg' to be located in 'f9' (second FP argument) but
gcc placed it to 'r33' (second GR).

ia64 software [1] manual described argument passing ABI in
"8.5.2 Register Parameters" as:

"""
    If an actual parameter is known to correspond to a floating-point
    formal parameter, the following rules apply:
    a) The actual parameter is passed in the next available floating-point
       parameter register, if one is available. Floating-point parameter
       registers are allocated as needed from the range f8-f15, starting
       with f8.
    b) If all available floating-point parameter registers have been used,
       the actual parameter is passed in the appropriate general register(s).
       (This case can occur only as a result of homogeneous floating-point
       aggregates, described below.)

    If a floating-point actual parameter is known to correspond to
    a variable-argument specification in  the formal parameter list,
    the following rule applies:
    c) The actual parameter is passed in the appropriate general
       register(s).

    If the compiler cannot determine, at the point of call,
    whether the corresponding formal parameter is a varargs parameter,
    it must generate code that satisfies both of the above conditions.
    (The compiler’s determination may be based on prototype declarations,
    language standard assumptions,  analysis, or other user options or
    information.)
"""

We have [c] case here and gcc uses only GR for parameter passing.

The change binds known variadic arguments ro GRs instead of FPs as those
are always expected to be initialized for all variadic call types.

This fixes all 10 failures on ia64-unknown-linux-gnu:

```
                 === libffi Summary ===
    -# of expected passes            1945
    -# of unexpected failures        10
    +
    +# of expected passes            1955
```

[1]: https://www.intel.com/content/dam/www/public/us/en/documents/guides/itanium-software-runtime-architecture-guide.pdf

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2018-02-11 12:17:32 +00:00
Anthony Green
9429968b82 Merge pull request #403 from frida/fix/x86-sysv-pic-closure-regression
Fix x86 SysV closure in PIC mode
2018-02-10 23:23:33 -05:00
Andreas Schwab
482b37f004 Fix passing struct by value on aarch64
This fixes the ctypes test in the python testsuite.
2018-02-07 12:50:14 +01:00
Ole André Vadla Ravnås
28d3b61bdd Fix x86 SysV closure in PIC mode
The assembly single-line comments swallowed up the remaining assembly
code of the macros due to lack of line-endings.

This is a regression introduced in b7f6d7a.
2018-01-21 01:27:22 +01:00
Anthony Green
bec6135dff Merge pull request #393 from thejunkjon/master
Linker error "recompile with -fPIC" for x86_64
2018-01-10 07:20:04 -05:00
YunQiang Su
746dbe3a6a mips/ffi.c: fix encoding for jr on r6
mips/ffi.c: instruction jr has a different encoding for r6
2018-01-03 10:07:41 +08:00
YunQiang Su
94c102aa69 Not set mips on mips r6
MIPS release changed encodes of some instructions, include ll/sc etc.

if .set mips4 on mips r6, as will generate some wrong encode of some instructions.
2017-12-10 14:25:01 +08:00
jon
d15581c696 Updating calls to ffi_closure_unix64_inner and ffi_closure_win64_inner to use PLT. Without this fix, statically linking libffi causes the linker error i.e. 'requires dynamic R_X86_64_PC32 reloc against ffi_closure_unix64_inner which may overflow at runtime; recompile with -fPIC)' 2017-12-01 00:34:30 -08:00
Anthony Green
4fdbb0578e Merge pull request #320 from 0-wiz-0/master
Support NetBSD with mprotect.
2017-11-03 07:05:31 -04:00
Anthony Green
b302bc3dfe Merge pull request #322 from compnerd/aarch64-base
aarch64: fix index base register for AArch64
2017-11-03 07:03:55 -04:00
Yen Chi Hsuan
9fc9dc535e Fix linux detection (closes #303) 2017-10-27 16:12:56 +08:00
Saleem Abdulrasool
1fb788ac89 aarch64: fix index base register for AArch64
The base is passed in `x3`, not in `x2`.  This fixes the indexing base
so that the right value is used.
2017-10-26 19:13:10 -07:00
Anthony Green
dc2ff5baab Merge pull request #323 from compnerd/x86-alloca-alignment
x86: align alloca to 16-byte boundary
2017-10-25 13:11:40 -04:00
Anthony Green
927da71662 Merge pull request #379 from jlj/master
Xcode build improvements
2017-10-25 13:05:53 -04:00
Anthony Green
a0455c0318 Merge pull request #383 from hjl-tools/hjl/master
Hjl/master
2017-10-25 13:04:23 -04:00
H.J. Lu
9d9d92b47f Skip WIN64/EFI64 support for x32
Since x32 doesn't support WIN64/EFI64, skip it if __ILP32__ is defined.
2017-10-25 05:37:30 -07:00
Saleem Abdulrasool
3c372c384a arm: fix a level of indirection issue
Rather than relying on the stack being 0'ed out always, do it manually.
The stack generally happened to be zero, and because the compiler
realizes that the tests are dealing with chars truncates the read value.
However, the top 3 nibbles of the value are undefined and may be
non-zero.  The indirection level caused a null-pointer dereference.

Explicitly scribbling on the stack during the allocation causes test
failures without the original zexting behaviour.
2017-10-24 16:44:54 -07:00
Jean-Luc Jumpertz
181fc4cc9c Merge branch 'master' based on ksjogo/libffi
Added a tvOS target in Xcode project. Misc Xcode project cleanup.
  Fix macOS build target in Xcode project.

# Conflicts:
#	src/aarch64/ffi.c
#	src/x86/ffi64.c
2017-10-23 15:02:29 +02:00
Saleem Abdulrasool
79d1509cb0 x86: align alloca to 16-byte boundary
Align the stack allocation to a 16-byte boundary.  This ensures that the
stack parameters are 16-byte aligned which is needed for some
instructions.
2017-10-22 14:09:51 -07:00
Sergei Trofimovich
ed7488c003 src/ia64/unix.S: unbreak small struct handling
commit 6e8a446083
added FFI_TYPE_COMPLEX value type (comes after FFI_TYPE_POINTER)

ia64 ffi_closure_unix reiles on the ordering of
FFI_ enums as ia64 has ia64-specific FFI types:
small struct and FPU extesions.

As a result all tests handling small structs broke.

The change fixes dispatch table by adding (no-op)
FFI_TYPE_COMPLEX entry
This has positive effect of unbreaking most tests
on ia64:

                 === libffi Summary ===

-# of expected passes            1595
-# of unexpected failures        295
+# of expected passes            1930
+# of unexpected failures        10
 # of unsupported tests          30

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2017-10-17 13:00:51 +01:00
Saleem Abdulrasool
7ad0ae7f42 arm: zext return value parameters
The closure function (invoked as closure->fun in ffi_closure_XXX_inner)
will only populate the actual number of bytes for the true return type,
which may be a character.  This leaves garbage on the stack when the
assembly closure function (i.e. ffi_closure_XXX) reads the return value
off of the stack into r0 as a 4-byte value.  ffi_closure_XXX always
leaves room for at least 4 bytes here, so we can safely set them to 0.
Otherwise, if there is garbage in any of these bytes, these end up in r0
and in the returned value as well.
2017-10-10 11:46:20 -07:00
Joerg Sonnenberger
2bfcd29955 Support NetBSD with mprotect.
Signed-off-by: Thomas Klausner <wiz@NetBSD.org>
2017-10-02 15:34:03 +02:00
Anthony Green
93d8e7dd17 Fix #265 2017-09-27 21:51:34 -04:00
Anthony Green
02a5145abb Merge pull request #263 from ksjogo/master
fix ios builds
2017-09-27 21:43:03 -04:00
Anthony Green
10099d6cad Merge pull request #271 from frida/fix/qnx-cache-flushing
arm: Fix cache flushing on QNX
2017-09-27 20:54:09 -04:00
Anthony Green
db4dad97e2 Merge pull request #312 from fjricci/fix_ub
Fix misaligned memory access in ffi_call_int
2017-09-27 20:47:08 -04:00
Jean-Luc Jumpertz
a78da73956 Fix macOS build target in Xcode project.
- Add missing files for desktop platforms in generate-darwin-source-and-headers.py, and in the Xcode project.
- Add a static library target for macOS.
- Fix "implicit conversion loses integer precision" warnings for iOS mad macOS targets.
2017-09-04 15:55:34 +02:00
Francis Ricci
9c12209d2e Fix misaligned memory access in ffi_call_int 2017-08-03 10:46:28 -07:00
Tony Reix
0ff9419f2e This patch enables FFI Go Closure on AIX. 2017-05-17 14:57:53 +02:00
Gregory Pakosz
bd72848c7a Prefix ALIGN macros with FFI_ 2017-04-27 13:22:28 +02:00
Ole André Vadla Ravnås
57d8ff044c Simplify iOS trampoline table allocation
By using VM_FLAGS_OVERWRITE there is no need for speculatively
allocating on a page we just deallocated. This approach eliminates the
race-condition and gets rid of the retry logic.
2017-03-30 13:30:50 +02:00
Johannes Goslar
0040694505 Update Xcodeproj
Include all currently relevent files.
Call autogen is build script.
Fix compiler settings.
Fix mach include.
2017-03-30 13:26:15 +02:00
Anthony Green
a94c999ba0 Handle fastcall declaration differently for some Microsoft compilers 2017-03-19 07:36:07 -04:00
Anthony Green
a0b14eea2b Merge pull request #291 from ramon-garcia/visual-studio-build
Build with Visual C++ (64 bits)
2017-03-17 09:20:40 -04:00
Ole André Vadla Ravnås
d42ce7b95c Fix error path so mutex is unlocked before returning
In the unusual case where ffi_trampoline_table_alloc() fails.
2017-03-15 01:27:43 +01:00
Ramón García Fernández
1e0d107b4b Modify configure.host to detect compilation with Microsoft Visual C++ and use assembly with Intel syntax in that case 2017-01-08 20:34:44 +01:00
Richard Henderson
256ce51c40 Merge pull request #273 from wbx-github/master
m68k: support ISA-A Coldfire CPUs
2016-09-01 13:54:51 -07:00
Richard Henderson
2ded2a4f49 Merge pull request #272 from yousong/mips64-soft-float
Mips64 soft float
2016-09-01 13:30:45 -07:00
Yuriy Kolerov
b545ff81f5 ARC: Remove unused variable
Signed-off-by: Yuriy Kolerov <yuriy.kolerov@synopsys.com>
2016-08-23 20:23:37 +03:00
Waldemar Brodkorb
52a11f6d91 m68k: support ISA-A Coldfire CPUs
Fix compilation for m68k/coldfire CPUs like mcf5208.

Signed-off-by: Thorsten Glaser <tg@mirbsd.de>
Signed-off-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
2016-08-20 01:05:32 +02:00
Yousong Zhou
7a0d2c83bf mips: fix MIPS softfloat build issue
The patch for o32.S is taken from OpenWrt packages repo 3a7a4bf "libffi:
fix MIPS softfloat build issue with current binutils"

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2016-08-15 15:14:54 +08:00
Tom Tromey
06d7c5190e Merge pull request #269 from frida/fix/aarch64-variadic-closures-on-ios
aarch64: Fix handling of variadic closures on iOS
2016-08-10 15:06:16 -06:00
Tom Tromey
aa7ed78c0e Merge pull request #268 from frida/fix/aarch64-large-aggregates
aarch64: Fix handling of aggregates larger than 16 bytes
2016-08-10 15:03:37 -06:00
Ole André Vadla Ravnås
4da814b18a aarch64: Fix handling of aggregates larger than 16 bytes
Instead of allocating stack space for a pointer we would allocate stack
space for the actual aggregate size.
2016-08-10 22:48:09 +02:00