Commit Graph

562 Commits

Author SHA1 Message Date
kobalicek
268bce7952 Minor change making static analysis happy
* clang-18 on now enabled on CI and used for static analysis
  * return error when X86Internal_setupSaveRestoreInfo() is called
    with invalid register group. Should never happen though.
2024-03-09 11:53:14 +01:00
kobalicek
7ff9c2a545 [CI] Minor changes in CMakeLists.txt, disable arm/v7 because of CI 2024-03-09 08:26:46 +01:00
kobalicek
3ca5c186bf [Bug] Fixed RW info of sub and subs instructions (AArch64) 2024-02-23 22:09:50 +01:00
kobalicek
4e50d8b319 Allocate preserved registers last
Register allocator now tries to allocate preserved registers last,
improving prolog/epilog sequence especially on AArch64, which has
calling conventions that require to preserve both GP and vector
registers.
2024-02-16 21:58:20 +01:00
kobalicek
d82e478fb8 Use atomics in CpuInfo::host()
The code was fine, however, some compilers may be able to optimize
it and in some border cases the features returned would be all zero.
This prevents such behavior.
2024-02-10 22:44:02 +01:00
kobalicek
9e39b1e814 Added basic abstractions to CondCode, Gp, and Vec
* Each architecture now provides r32() and r64() functions for
    register casting
  * Each architecture now provides v128() function for register
    casting, returning just Vec to make writing cross platform
    code easier
  * Added some basic condition code abstractions so it can be used
    interchangeably across architectures
  * Added back unlicense to asmjit database (now it's dual licensed)
2024-02-10 16:43:40 +01:00
kobalicek
a63d41e80b Added support for mach_vm_remap() for dual mapping
mach_vm_remap() allows to create a dual mapping without having to
use a file descriptor, which has to open a file or shm memory. The
problem is that the recent macos version started displaying a popup
message when such file is opened and that annoyed a lot of users.

Thus, the initial code-path is no longer used, and mach_vm_remap()
is used instead.

This change only applies for x86 macs. Apple silicon doesn't allow
dual mapping and instead uses MAP_JIT.
2024-01-25 22:23:13 +01:00
kobalicek
bfa0bf690c Workaround for issue #427
MSVC incorrectly auto-vectorizes a loop that is used in liveness
analysis. Due to this bug the result is wrong, which then affects
how registers are allocated. This workarounds a C++ compiler bug.
2024-01-23 23:46:52 +01:00
kobalicek
03b784c9fe [Doc] Added CONTRIBUTING.md and issue templates; updated docs 2024-01-22 00:25:23 +01:00
kobalicek
b4b2ff3109 Hardened runtime detection enhancements
A new HardenedRuntimeFlags::kDualMapping flag has been introduced to
detect whether dual mapping is provided by the target platform. This
flag can be set even when hardened runtime is not enforced in cases,
in which dual mapping is not available.

This fixes running unit tests on Apple hardware where dual mapping
is not available, but MAP_JIT is (AArch64 hardware).

Additionally, this changeset fixes using -msse2 flag on non-x86
targets, where compiler don't mind "-msse2" flag, but warns about
it. This makes the build 100% clean.
2024-01-20 12:23:11 +01:00
kobalicek
8210620f3e [Bug] Fixed AArch64 calling convention handling on Apple platforms
The standard AArch64 calling convention specifies that the minimum
size of each argument passed via stack is 8 bytes. However, Apple
doesn't follow this convention and only aligns stack to 8 bytes
when an argument has 8 bytes or more. This makes it incompatible
with the standard calling convention as two consecutive 32-bit
integers would occupy only 8 bytes instead of 16 when passed via
stack.
2024-01-20 09:30:00 +01:00
kobalicek
118ae6ced1 [Bug] Fixed sign and zero extension in Function API (x86)
The problem was that the sign/zero extension was not working with
TypeIds, but it was working with register IDs, when emitted. Thus,
even when TypeId was uint8, for example, the register could be
uint32, so the final instruction emitted was 'movzx eax, eax', for
example, which was wrong.
2024-01-13 14:31:35 +01:00
kobalicek
c620b113ad Added API to set BaseMem base+index types 2024-01-07 21:31:56 +01:00
kobalicek
1cf7ee03ed Improved compile times by avoiding <iterator> header 2024-01-06 23:39:33 +01:00
kobalicek
33ef5fded9 [Doc] Mostly documentation update 2024-01-03 17:03:06 +01:00
kobalicek
3772c447ca [ABI] Accumulated API/ABI changes
* Renamed all eq() methods to equals() (consistency) (ABI)
  * Reorganized some X86 instructions in X86 database
  * Properly detect RISC-V CPU at compile time (Environment)
  * Removed CallConvId::kNone in favor of defaulting to kCDecl (ABI)
  * CallConvId::kHost is now alias to CallConvId::kCDecl (ABI)
  * Added FloatABI to Environment to disginguish between softfloat
    and hardfloat
  * Added more AArch64 CPU features and their detection (ABI)
  * Because of CallConvId changes it's now possible to run
    compiler tests on 32-bit ARM (fixes a bug in test cases)
  * Added QEMU to CI build matrix to test different architectures
2024-01-01 20:15:00 +01:00
kobalicek
a465fe71ab [ABI] Reworked FuncSignature 2023-12-27 21:17:45 +01:00
kobalicek
b0638ede77 [Bug] Fixed CpuInfo not reporting hw thread count on non-windows platforms 2023-12-27 18:11:49 +01:00
kobalicek
5ce45e0356 [ABI] Renamed a64::Vec::ElementType to a64::VecElementType 2023-12-27 13:04:27 +01:00
kobalicek
b4ad286890 [Doc] Documentation fixes 2023-12-27 02:43:41 +01:00
kobalicek
f27334eaf8 [ABI] Moved vector operand from arm to a64 namespace
This is unfortunately API/ABI break, which cannot be deprecated
instead of removed as arm::Vec would collide with a64::Vec if present.

This is a preparetion for ARM32 tooling.
2023-12-27 02:26:36 +01:00
kobalicek
b25df5554d [ABI] Updated instruction DB, operands, and minor API changes
This changeset contains an updated instruction database that brings
ARM32 instructions for the first time. It also updates instruction
database tooling especially for ARM64, which will also be used by
ARM32 generator.

Additionally, new operan has been added, which represents a register
list as used by ARM32 instruction set.

Other minor changes are related to ARM - some stuff had to be moved
to a64 namespace from arm namespace as it's incompatible between
32-bit and 64-bit ISA.
2023-12-26 23:28:40 +01:00
kobalicek
13bd440022 [ABI] Added prfm instruction (AArch64) 2023-12-26 19:05:05 +01:00
kobalicek
073f6e85e4 [ABI] Improvements to avoid UB and warnings, clean build with MSAN
* Added more clang compilers on CI (CI)
  * Added memory sanitizer to build matrix (CI)
  * Use problem matcher in all builds (CI)
  * Fixed the use of some constructs in tests
  * Fixed warnings about unused functions in tests
  * Fixed warnings about unused variables caused by some build options
  * Fixed tests to be clean with MSAN (zeroing memory filled by JIT code)
  * Removed -Wclass-memaccess (gcc) from ignored warnings
  * Removed -Wconstant-logical-operand (clang) from ignored warnings
  * Removed -Wunnamed-type-template-args (clang) from ignored warnings
  * Reworked InstData and InstExData to not cause UB (ABI break)

Unfortunately the existing InstData and InstExData was not good for static
analysis and in general compilers emitted warnings regarding accessing
InstNode::_opArray. The reason was that InstExNode added one or two
more operands which extended InstData::_opArray, but there was no way to
tell the C++ compiler about this layout.

It has been changed to InstNode having no operands and InstNodeWithOperands
being templatized for the right number of operands. Nodes that need to
inherit InstNode would just inherit InstNodeWithOperands<N>. It works the
same way as before, just the class hierarchy changed a little.
2023-12-26 19:00:00 +01:00
kobalicek
7c10a14d34 Added indirect branch protection to function abstraction
* Adds a new entry to FuncAttributes
  * Adds a new API to FuncFrame
2023-12-19 12:39:55 +01:00
kobalicek
416f735696 Fixed some warnings and initialization in constructors
This doesn't fix any bugs, it's just improving the code a bit.
2023-12-12 13:40:57 +01:00
kobalicek
1a81158e8b Build related improvements (CMake 3.8 now required)
* CMake 3.8 as a baseline means no "IF"s in a cmake build script
2023-12-07 22:00:05 +01:00
Paul Ivanov
6a13a935d1 [Doc] Fix repeated-word typos (#425) 2023-12-03 09:19:05 +01:00
kobalicek
504c988e2f [ABI] Removed OSUtils::getTickCount(), use 64-bit file API by default
OSUtils::getTickCount() is a legacy function that used to have some
magic to actually return correct values. However, since the function
was not used by any open-source project on GH it's better if it's just
removed so it doesn't have to be maintained. It had no tests and since
there is <chrono> in C++ it really has no purpose anymore.

In addition, use 64-bit file API by default on some platforms as this
is what most applications use anyway. This is just a little optimization
to avoid using both open() and open64() functions in an application if
it already uses 64-bit file API.
2023-12-03 07:48:41 +01:00
kobalicek
e731f57975 Build related improvements (additional) 2023-12-01 23:20:00 +01:00
kobalicek
803712f111 Build related improvements, better ASMJIT_NO_STDCXX support
* Added more cmake options to control features to be built
  * Added a detection whether to link to libpthread (if not part of libc)
  * Added a detection whether to link to librt (if not part of libc)
  * Removed pure virtual functions as this collides with -nostdlib
  * As a result the support for ASMJIT_NO_STDCXX has improved
2023-12-01 16:22:58 +01:00
kobalicek
1f8999065b [Bug] Fixed compilation on ARM32 (hwcaps) 2023-11-30 10:58:27 +01:00
kobalicek
1da9e4d957 Added support for MFD_EXEC to be used by default (memfd_create)
The purpose of this change is to avoid a system warning in case
memfd_create is used on a 6.3+ kernel without MFD_EXEC.
2023-11-15 23:06:07 +01:00
smcallis
dbfe3900e4 [Bug] Fix breakages that occur when targeting WASM with Emscripten. (#422)
We don't import either architecture in archtraits so include
environment.h to ensure Environment is visible, and don't use
__builtin__clear_cache in Emscripten because it's unsupported.
2023-11-15 09:15:30 +01:00
kobalicek
b2a01018ad [Bug] Fixed ASMJIT_NO_STDCXX option broken by previous commit 2023-11-12 19:04:50 +01:00
kobalicek
10ae662219 Removed the dependency on a <new> header 2023-11-12 13:20:50 +01:00
kobalicek
30b83beda7 [Doc] Minor fix in x86::Assembler documentation 2023-11-06 14:13:33 +01:00
kobalicek
7e64eabca4 [CI] Updated BSD versions on CI 2023-10-07 11:37:07 +02:00
kobalicek
6e71f6be0c Use override instead of virtual on destructors
In addition, fixed a potential fall-through in x86:Assembler.
2023-10-06 23:04:56 +02:00
kobalicek
4413d78c98 [CI] Removed NetBSD builds because the VM doesn't work 2023-10-06 12:06:47 +02:00
Xing Guo
c1e02dc558 [Doc] Fixed documentation of SystemV X86_64 calling convention. (#417)
The first 6 arguments passed on UNIX64 platform is by RDI, RSI, RDX, RCX, R8, R9.
2023-10-06 11:06:48 +02:00
kobalicek
917f19d940 Added NodeList to abstract double linked list of nodes 2023-09-14 17:59:54 +02:00
kobalicek
87bec89b10 [API] Deprecated the use of Operand::size()
From this moment, the use of Operand::size() is discouraged:

  - Use BaseReg::size() to get a size of a register
  - Use x86::Mem::size() to get a size of a x88 memory operand
  - Use Operand::x86RmSize() to get a size of a register or
    x86 memory operand (convenience)

The problem with size occupying bits of each operand is problematic
as we want to pack more information to architecture specific operands.
For example AArch32 and AArch64 memory operands need more payload,
which can use the bits that were used by size in the past.
2023-09-14 16:47:52 +02:00
kobalicek
46bdb67262 Fixed -fno-semantic-interposition warning with apple-clang 2023-09-11 10:47:10 +02:00
kobalicek
8c9b0073a7 Fixed implicit long to int conversion (VirtMem) 2023-09-11 10:20:58 +02:00
kobalicek
cfc0b8ffb0 Updated docs, added back deprecated CpuFeature getters
* Updated documentation regarding recent breaking changes.
  * Added back 3 CPU feature getters, which were deprecated.
2023-09-10 19:29:30 +02:00
kobalicek
2fa0b3f8fb [ABI] Added implementation of all pure virtual functions
This changes virtually nothing from API perspective, however, it
allows to embed asmjit well in C projects that do not link to C++
standard library.

In normal circumstances, when a pure virtual function is declared,
but not implemented, the compiler would replace it with it's
default version, which would print a message and terminate the
program. However, this function is part of a C++ standard library,
so we don't want to use it.
2023-09-10 17:12:15 +02:00
kobalicek
f6a9c86b26 Use ASMJIT_INLINE_NODEBUG to make debugging easier
Having 'inline' is fine, however, when debugging a class that has
abstractions then sometimes to step over all of them can be very
frustrating. This is solved by ASMJIT_INLINE_NODEBUG, which tells
compiler that the body of a function doesn't have to be debuggable.

This mostly applies to getters, setters, and wrappers around API
functions.

In addition - some assembler tests were split to make the compilation
a little bit faster, especially when compiling with UBSAN.
2023-09-10 15:04:39 +02:00
kobalicek
e4e61c4f15 [ABI] Completely reworked instruction DB and generators
* Instruction database is now part of asmjit to keep it in sync
  * X86/X64 ISA data has been reworked, now in a proper JSON format
  * ARM32 ISA data has been added (currently only DB, support later)
  * ARM64 ISA data has been added
  * ARM features detection has been updated
2023-09-10 09:55:17 +02:00
kobalicek
8e2f4de484 [ABI] Reworked JitAllocator to alloc spans and to use explicit write API 2023-09-10 09:55:00 +02:00