Commit Graph

166 Commits

Author SHA1 Message Date
Duncan Ogilvie 9a6868a27d Fix X87 lifting on LLVM 18+ 2025-11-05 20:46:01 -05:00
Duncan Ogilvie 1be540eeef Implement FMADD in terms of std::fma 2025-11-05 20:46:01 -05:00
Duncan Ogilvie 6082054723 Fix bug with uninitialized MONITOR variable causing UB 2025-11-05 20:46:01 -05:00
Duncan Ogilvie eba0652f86 Replace cfenv dependency with new remill FPU intrinsics 2025-11-05 20:46:01 -05:00
Duncan Ogilvie ac78aa9dca Switch to standalone sysroot for semantics compilation 2025-11-05 20:46:01 -05:00
Duncan Ogilvie ddef25db7c Add support for LLVM 15-21 2025-11-05 20:46:01 -05:00
Matteo e42ac37294 Fix UBSan error when computing the state field offsets. 2025-11-05 20:46:01 -05:00
cctv130 b6fc70f0f4 CMake: update to C++20, clean up properties, optimize fetch content (#721)
- Enable C++20 on both Windows and Linux
- Remove unnecessary set_property calls to silence LOCATION warnings
- Replace duplicate -fPIC flags with INTERFACE_POSITION_INDEPENDENT_CODE
- Set FETCHCONTENT_BASE_DIR to speed up sleigh and ghidra-fork downloads/builds
- fixed: Does not match the generator used previously: Unix Makefiles,use ninja instead
2025-09-05 17:55:23 -04:00
cctv130 e272b48e84 fix: windows clang build (#719)
* Update settings.cmake

Fix the issue where debugging on Windows in VSCode doesn’t work

* fix: windows clang build

The following flags are not supported in non-MSVC environments
/EHsc /wd4141 /wd4146 /wd4180 /wd4244 /wd4258 /wd4267 /wd4291
/wd4345 /wd4351 /wd4355 /wd4456 /wd4457 /wd4458 /wd4459 /wd4503
/wd4624 /wd4722 /wd4800 /wd4100 /wd4127 /wd4512 /wd4505 /wd4610
/wd4510 /wd4702 /wd4245 /wd4706 /wd4310 /wd4701 /wd4703 /wd4389
/wd4611 /wd4805 /wd4204 /wd4577 /wd4091 /wd4592 /wd4324

Update cmake_minimum_required(VERSION 3.21) to remove CMake warning.
2025-08-18 17:42:31 -04:00
Maurice Heumann f59f129753 Pass undef if semantic function argument is unused (#716)
Remill tries to infer the proper type of an argument for a semantic function.
If the argument is unused that won't work and yields wrong results.
However, in that case, it doesn't matter what's passed,
as nobody uses the value, so passing undef works and prevents issues.
2025-07-03 20:36:28 -04:00
Masashi Yoshimura aa886a2244 Fix AArch64 breakpoint exception handling to use builtin fuctions or BRK instruction. (#714) 2025-05-13 12:47:08 -04:00
Duncan Ogilvie 7f091d4256 Remove [[gnu::const]] (readnone) from __remill intrinsics (#710)
* Remove [[gnu::const]] (readnone) from __remill intrinsics

* Remove FindPureIntrinsic and SetMemoryReadNone
2024-07-17 12:32:00 -04:00
Masashi Yoshimura 92d1867d1a Fix the offset of STUR and LDUR of AArch64 instructions. (#708) 2024-05-11 21:49:42 -04:00
2over12 874490a894 Fix placement of 32 bit regs on e500 and populate the low bits of PC on BE (#702)
* be fixes

* decriptive names

* fix tests
2024-02-28 11:16:37 -05:00
2over12 608acf8edd Fix big endian type conversions for registers (#699)
* add conversion checking

* Update lib/BC/SleighLifter.cpp

Co-authored-by: William Tan <1284324+Ninja3047@users.noreply.github.com>

---------

Co-authored-by: William Tan <1284324+Ninja3047@users.noreply.github.com>
2024-02-14 13:43:25 -05:00
2over12 391261923a actually call branch taken store (#697) 2024-01-16 07:50:56 -05:00
2over12 ec76ca4c53 new layout (#696) 2024-01-12 09:18:52 -05:00
William Tan 17cff6b4df SPARC support via Sleigh (#681)
* initial WIP sleigh based SPARC32 arch

* add install option to build script

* fix register names

* fix incorrect index into current_bytes in loadFill implementation

* add didrestore register

* dlog register adding

* ignore categories

* remove decompile_mode from llvm

* fix register mapping for flags

* remove nextpc/npc since it doesn't appear to be used and breaks anvill

* overlay NPC with NEXT_PC

* remove next_pc correctly since it was still breaking stuff

* Don't mark instruction as "invalid" when we can't determine a control
flow category

* fix pcode cfg for calls and branches

* add double registers to sparc state structure

* match up with ghidra register names

* fix missing header

* add starts for blocks after control flow ops to guarentee a block split for a term

* remove sparc64_sleigh, fix initialization order

* lift floating point numbers using ghidra names

---------

Co-authored-by: Alex Cameron <asc@tetsuo.sh>
Co-authored-by: 2over12 <ian.smith@trailofbits.com>
2023-11-10 07:44:27 -05:00
2over12 0183248218 llvm 17 fixes (#688)
* llvm 17 fix

* more instances

* more fixes

* add inline

* bump ci

* bump cxx common

* add 17 case

* bump xcode version

* macos 13

* xcode 15

* bump docker to llvm 17

* change actual matrix value

* opaque pointers are the default now

* actually remove the option

* debug size

* install tree

* fix install

* fix install?

* get tree after

* build dir?

* tree above

* accumulate

* bug?

* try to remove intermediate packaging

* fix opt

* only inline

* give up on function inlining

* llvm 17

* remove debug tasks

* Update scripts/build.sh

Co-authored-by: William Tan <1284324+Ninja3047@users.noreply.github.com>

* Revert "Update scripts/build.sh"

This reverts commit 6c727a539d.

* debug

* try clear out old build

* retest

* try to save more space

* up

* Clear space and don't use cxx-common docker image (#689)

* Clear space and don't use cxx-common docker image

* Run on all PRs

* Fix perms

* Remove some unnecessary apt commands

* Install LLVM version as root

* Allow writing to external target

* Build before running tests

* Install with sudo

* Simplify with container volume mounts

---------

Co-authored-by: William Tan <1284324+Ninja3047@users.noreply.github.com>
Co-authored-by: Eric Kilmer <eric.d.kilmer@gmail.com>
2023-10-12 16:37:45 -04:00
2over12 a6abbb818c Mirror Sleigh's Byte-width Flags (#668)
* add sleigh state

* remove bad include

* add volatile

* dont run tests in docker deploys

* remove ccache

* Revert "remove ccache"

This reverts commit 221b70a1bc.

* Revert "dont run tests in docker deploys"

This reverts commit 72229acd6e.

* disable packaging in dockerfile

* fix block packagingA

* fix syntax
2023-07-10 12:07:42 -04:00
Eric Kilmer 396e228e93 Fix Linux AArch64 compilation for SPARC32 runtime (#674)
* Fix Linux AArch64 compilation for SPARC32 runtime

Issue with conflicting compilation target(s).

Tests fail though.
2023-05-10 18:38:18 -04:00
Eric Kilmer 22b3d4b231 Fix GCC compilation (#672)
* Fix compilation with GCC

Fixes a few errors reported by GCC and not Clang

1. "non-trivial designated initializers not supported"

    - Fixed by adding array entries that were missing initializers and
      reordering

2. "Cannot bind packed field"

    - This fixes arrays missing initializers for some entries. This
      isn't the greatest fix because instead of using a reference, we
      use a pointer, which is basically the same thing, but it is
      checked less strictly. I think a real fix would be to remove the
      'packed' annotations.

* Add GCC to CI
2023-05-09 18:45:01 -04:00
2over12 1831127e62 fix name add runtime 2023-04-30 10:27:38 -04:00
2over12 9303453ffc allow sleigh version 2023-04-30 10:19:47 -04:00
2over12 c751f850ae add decoder 2023-04-30 10:14:18 -04:00
2over12 88dfa0922a add name 2023-04-30 09:55:46 -04:00
2over12 8096963e80 fix redef 2023-04-30 09:34:45 -04:00
2over12 12b70920c6 factor out shared functionality into base class 2023-04-30 09:34:08 -04:00
2over12 72a36678fc add base arch 2023-04-30 09:00:22 -04:00
Alex Cameron 031305d519 Get Remill building with LLVM 16 (#665)
* Get Remill building with LLVM 16

* Update scripts and README

* Refactor `MoveConstantIntoModule` check to reduce duplication

* Remove hack since we don't plan to clone functions across contexts

* Remove call to deprecated LLVM function

* Add LLVM 16 to CI

* Bump cxx-common version

* Fix scripts to work with new `cxx-common`

* Don't add unsupported `readnone` attribute with LLVM 16

* Use `memory(none)` with LLVM 16 instead of `readnone`

* Add LLVM 16 to docker lifter entrypoint
2023-04-28 10:29:34 +10:00
2over12 cae518402d Add Custom PPC Spec and Update Sleigh (#666)
* builds with e200 spec

* install rule

* add initialization

* fix ppc

* new x86 patch

* force release type head

* nits

* fix x86 patch place earlier

* Update CMakeLists.txt

Co-authored-by: William Tan <1284324+Ninja3047@users.noreply.github.com>

* Update CMakeLists.txt

Co-authored-by: William Tan <1284324+Ninja3047@users.noreply.github.com>

* add context init

---------

Co-authored-by: William Tan <1284324+Ninja3047@users.noreply.github.com>
2023-04-25 13:58:52 -04:00
2over12 db394b3979 Fix bug in rendering actual PC from NEXT_PC with thumb preffix/suffix instructions (#661)
* use context to figure out mode in thumb for insn size

* add patches for inst_next based on curr isamode

* add decoding context constant injection in lifting

* allocate registers to repr context and insert belief about context registers as first value

* add regression test

* fix imports

* add comment
2023-04-05 10:41:31 -04:00
William Tan 58e5c4d255 fix claim-eq error logging, check is inverted 2023-04-04 09:47:02 -04:00
Eric Kilmer b677387f6f Test on Ubuntu 22.04 (#660)
* Only support and test Ubuntu 22.04

* Fix regex matching in CI

* Remove unnecessary addr size check

---------

Co-authored-by: Alex Cameron <asc@tetsuo.sh>
2023-03-30 10:46:25 -04:00
2over12 ca80510996 Replace the Manual AArch32 Semantics and Decoder with Sleigh (#659)
* update to default to sleigh decoder

* lift correct insn size if not in thumb:

* add test, prevent sleigh pspecs from overwriting context registers that remill sets

* Revert "add test, prevent sleigh pspecs from overwriting context registers that remill sets"

This reverts commit 3e5f1728a9.

* add test

* override pspec context data by setting value

* remove dead code
2023-03-15 12:11:02 -04:00
2over12 38ec19ad3d nextpc instead of the PC reg which points 4 ahead (#657) 2023-02-24 12:44:22 -05:00
Alex Cameron 1818fc8e50 Support PowerPC syscall (#653)
* Support PowerPC syscall

* Enable PowerPC syscall unit test

* Create stub sync hyper call

* Cleanup

* Fix `ConstantInt` call

* Use `LoadMemoryPointerRef` util
2023-02-17 10:34:21 +13:00
Alex Cameron 6cc821bc7e Use DLOG where appropriate (#654) 2023-02-13 08:03:15 -05:00
2over12 db6e08462d add missing case (#652) 2023-02-09 07:52:36 -05:00
Alex Cameron fb018c96e9 PowerPC Support (#645)
* Add skeleton for PPC

* Copyright notices

* Fill in some details for the PPC arch

* Start building a (wrong) PPC runtime

* Begin populating state structure

* First pass for EIS state structure

* Map registers to Sleigh register names

* More fixes

* add optional param

* Create handle unsupported and invalid instruction isels

* Correct typo

* Get a basic `remill-lift` invocation running without failure

* Fix capitalisation

* Set vle context reg

* Fix SleighDecoder signatures

* Set VLE context register in the Sleigh engine in addition to our
internal context reg mapping

* Capitalize reg names

* Add the flag registers for XER and CR

* Rename bitflag structures in PPC state

* PPC Sleigh patches (#643)

* Modified sleigh patch script to generate patches for multiple .sinc files

* update README with new examples of sleigh patch script invocation

* add ppc register definition

* add ppc sleigh patches

* fix issue with remill_insn_size definition

* regenerate sleigh patches for PPC

* update CMakeLists.txt to include PPC patches

* Add TEA signal as a register in the PPC state

* Uppercase the stack pointer register name

* Fix PPC instruction sizes

* initial PPC tests

* remove duplicate tests

* fix tests for e_stmvgprw/e_ldmvgprw

* add tests for loading/storing from special registers

* add tests with internal conditionals in pcode

* fix for pc reg and addr width not being the same... I suspect this issue is going to come up elsewhere

* add heuristic for flow from normal intrainstruction flow

* rework tests to allow testing for different sized registers

* add tests for overflow and record add

* fix bug with log printout

* add intrafunction control flow lifting

* handle edge case where there is no pcode op at the zero index

* Fix another inconsistency with mismatching address and PC reg size

* Allocate unique ptrs in the entry block

* Fix `INT_LEFT` and `INT_RIGHT` impl where shift exceeds bit width

* fix supiece lift?

* Add PPC emulate instruction to hyper call

* fix for pc reg and addr width not being the same... I suspect this issue is going to come up elsewhere

* add heuristic for flow from normal intrainstruction flow

* add intrafunction control flow lifting

* handle edge case where there is no pcode op at the zero index

* Fix another inconsistency with mismatching address and PC reg size

* fix supiece lift?

* Allocate unique ptrs in the entry block

* Fix `INT_LEFT` and `INT_RIGHT` impl where shift exceeds bit width

* fix int2float semantics

should use appropriate sized float based on the output size

* add tests for lifting int2float

* fix INT_{LEFT,RIGHT} semantics

should be `ICmpSGE` instead of `ICmpSGT`

* add cr0-7 registers

* fix formatting

* fix conditional branch test

* add test for compare

* re-enable rotate left word immediate and mask test

* genericize TestSpecOutput

* explicit instruction data size

* add test for syscall/callother (disabled)

* add tests for store/load word

* add test to convert from float to int

* specify intrinsic arg type, fixes null deref

* Add PPC emulate instruction to hyper call

* add headers + formatting

* remove old comment

* Map CRALL register

* Add basic LLVM data layout that specifies 32-bit addresses

* Remove unused variables

* convert auto* to auto when possible

* RegisterPrecondition -> RegisterCondition

* fix variable name

* convert any to variant

* use std::move

* bump to c++20, use concepts

* set arch in constructor since class isn't generic anyways

* formatting

* make type aliases

* bump cxx-common

* add comment

* clang format

* throw exception if register not found

* use const ref

* use shorthand for lambda capture values

* Add more detail to data layout to include proper stack alignment

* Compare to the correct size for SUBPIECE impl

* Add Sleigh message to error

* throw exception in else case

* throw runtime error if register value has incorrect type

* use reference instead of value

* get rid of unnecessary type alias

* formatting

* Propagate VLE context reg value into Sleigh

* Remove unnecessary whitespace

* Remove stale TODO and NOTE comments

* add additional parameter to test runner to specify decoding context

* drop llvm 14, bump macos version

* bump cxx-common, fix ci.yml mac build

* add test for unconditional relative negative branch

* add missing space to pcode debug log

* fix bug due to unordered_map, iteration order matters

* add error log in case we aren't able to adjust PC value

* use helper for getting register reference

* Revert "add optional param"

This reverts commit 51ed49f8cf.

* Remove remaining LLVM 14 compatibility code and configuration

* Add padding between CR and XER flags

* Use `enum class`

* Remove void cast

* Remove unnecessary variable

* Use initialiser lists where appropriate

* Remove redundant `else`

* Prefer `CHECK` over `assert`

* Polish PowerPC function initialisation with lambda

* zero out xer_so to fix tests

* log error when we see claim_eq with no usages

* Collapse namespace blocks

* Remove unnecessary `this->`

* Use `auto` where appropriate

* Remove unnecessary `else`

* Use `emplace` over `insert` for `std::map`

Co-authored-by: lkorenc <lukas.korencik@trailofbits.com>

* Use `constexpr` for VLE reg name

* Use module verification util

* Add `VerifyFunction` util and use where applicable

* Extract lambda to improve readability of flow categorisation

* Use type alias for context values

* Introduce type alias for block exit

* Create type alias for optional branch taken

* Refactor `PcodeCFGBuilder`

* Use lambda to avoid conditional mutation

* Extract duplicated bit-shift code generation into helper

* Simplify flow with ternary

* Add `GetBlock` helper

* Rename variables

* Move statement for clarity

* Create helpers for working with Sleigh context register values

* Convert loop to `std::copy`

* Add a comment explaining the use of set to de-duplicate and sort

* Refactor `IntraProcTransferCollector`

* Expose static method to easily use `IntraProcTransferCollector`

* Rename PPC related variables to include address width

* add docs to intrainstructionindex

* remove llvm 14 ifdefs

* don't log error if no claim_eqs were used

* update comments

* Cleanup exit visitors

---------

Co-authored-by: 2over12 <ian.smith@trailofbits.com>
Co-authored-by: William Tan <1284324+Ninja3047@users.noreply.github.com>
Co-authored-by: lkorenc <lukas.korencik@trailofbits.com>
2023-02-02 10:05:28 -05:00
2over12 9005cb0fc8 Weaken remill check in utils to allow additional parameters (#650)
* weaken remill check in utils to allow additional parameters

* more unambiguous name
2023-01-30 13:38:38 -05:00
Francesco Bertolaccini ab03a02dbc Add APIs that allow specifying an insertion point (#642) 2022-12-02 12:00:15 -05:00
2over12 829ee4acf5 Sleigh Preliminary Floating Point Support (#632)
* re-enable broken float code

* try to cast floats as integers

* fix assingment for function calls

* actually fix calls

* make sure to set branch not taken

* add initial neon registers

* fix missing unit128 fields

* add more debug

* do armv8 since that's what we need right now

* add complete fpscr

* make FPSCR capital

* initialize return_pc

* fix build on linux (#633)

* undo superfluous change (#634)

* revert aarch64 linux changes for now

* fix off by 2 when defining INST_NEXT_PTR in patches for thumb

* fix off by 2

* fix typo

* fix typo

* use maybe float directly

* fix test

* add additional float types

Co-authored-by: William Tan <1284324+Ninja3047@users.noreply.github.com>
2022-11-17 14:41:27 -05:00
Alex Cameron d5c5035728 Get Remill building with LLVM 15 (#631)
* Get Remill building with LLVM 15

* Add missing header for x86 lift test

* Fix `enableOpaquePointers` calls

* Define a non-extern `__remill_state` in each Instructions module

* Remove `__remill_state` variables in tests

* Update build script to support LLVM 15

* Build with LLVM 15 in CI

* Bump CXX Common version

* Update Docker script

* Add comment explaining the definition of the state variable

* Correct wording
2022-10-30 16:42:23 -04:00
2over12 65817f05b8 Mixed Mode AArch32 (#622)
* stuff

* make decoders standalone from arch

* compiles

* fix lazy initialization of intrinsic table

* add back sleigh arch

* added switching between arches... need to update contexts

* add instructin sizes

* thumb triplet

* back out of lambda approach

* updating context in thumb case

* fix differential tester to initialize lifter

* add back lambda approach

* aarch32 context updates

* add tests

* fix assetions in tests

* fix address alignment for tests

* add better decode function

* fix tests

* add conditional tests

* fix uninitialized context in contextupdater

* restore old contexts on call...

* null out branch taken arch on indirects

* fix fallthrough for conditional where neither src evaluates properly

* initialize is interproc

* fix initial context arm

* fix boolop bug where params would be lifted when not bool op

* fix comparison

* remove debug

* make missing context non fatal

* bump sleigh

* add insn flow variant

* stub out computing categories

* add control flow structuring

* adding unconditoinal abnormal

* start refactoring flows to share more structure

* rework conditionals to express a combination of a condition with an abnormal flow

* finish basic flow analysis

* add context updater

* implement eq

* stop passing back contexts through return value

* add tests

* rework constructors, make flow usage consistent

* implement flows in aarch32

* add implementation of flows for old cateogries and no context

* make sleigh lifter backwards compatible by applying flows to instructions

* fix bug in generating coarse flows

* refactor to allow lifter to bring along decoding state

* rework insertion of branch taken vats

* fix off by one

* fix size

* dont reset bytes before use

* disable broken float ops

* back of ambiguity to non fatal error, also add logging of callother's encountered

* update names

* remove debug logging

* add comment about x86 context

* move to headers

* move eqs

* order of ctors, fields, methods

* noop subtype of normal

* remove direct constructors

* remove more duplication

* more duplication in noop

* remove unused field

* add utility for is thumb

* absolute path

* remove duplication

* absolute paths

* review fixes

* make const refs

* make enums match style guide

* add constructor to flow

* non ref

* make refs

* move map out of optional

* refer to enum

* move curr id out

* fix BOOL_NEGATE for non 1 bit

* type alias for decoding result of branch taken and flow

* more delog

* this language makes me incredibly happy

* remap flags and treat metavars more like how the instructionlifter does it

* more fixes to metavars

* fix pc reg definition so consistent with value during isntruction execution

* fix alignment of test

* add todo

* extract condition

* add comment
2022-09-28 13:38:36 -04:00
Alex Cameron 166553c8e2 Emit IR for syscall in addition to a __remill_async_hyper_call (#625)
* Add `syscall` case to `__remill_sync_hyper_call`

* Cross compile 32 bit and 64 bit x86 appropriately

* Support `sysenter` and `sysexit`

* Pass in full set of registers for syscall instructions

* Address review comments
2022-09-27 17:36:41 -04:00
William Tan 8f62b657ce update git_watcher.cmake to latest, use git-describe for version 2022-08-29 13:16:19 -04:00
Alex Cameron fe6d4276cd Provide initial definition for __remill_sync_hyper_call (#611)
* Create initial implementation of `__remill_sync_hyper_call`

* Fill in a few more cases

* Use `state.addr_to_load` for LGDT and LIDT operands

* Fix variable names

* Cross-compile the Remill runtimes

* Create temp variable for `lgdt` and `lidt` handling

* Add intrinsics for SPARC emulate instruction calls

* Create intrinsics for remaining hyper calls

* Remove `__remill_sync_hyper_call` implementations in tests

* Create the target triple based on the provided arch

* Provide ARCH parameter for SPARC archs

* CMake formatting

* Switch the conditions around

* Adjust target triple

* Cross-compile the hyper calls and then link them into the runtime

* Cleanup

* Prefix int types with namespace

* Include `<limits>`

* Fix `lgdt` and `lidt` handling

* Mark new intrinsics as "used"

* Add placeholder intrinsic definitions to tests

* Complete list of intrinsic definitions

* Mark hyper call definition with `always_inline`

* Use `_BitInt` if available

* Use `__builtin_unreachable` instead of `abort`

* Leave comment explaining `always_inline` attribute
2022-08-22 13:02:00 -04:00
2over12 1f55826a1f Fix Type Info for Register Variable GEPs (#620)
* add test

* direct type of found variable by reg info

* weaker requirement on variable types
2022-08-20 12:06:45 -04:00
2over12 c0f90b9e4a Add Context Structure to Affect State Dependent Liftings (#617)
* add empty contexts

* add include

* make function const

* add helper for uniform mappings

* expose cache clearing for operand lifter

* decoding context documentation:

* move virtual inheritance down

* remove unused var names

* add type alias

* remove underscores

* make sure we have poetry

* check version in CI

* try specify python3

* newer poetry install script

* fail fast

* try use pythons pip

* upgrade pip?

* install directly

* update in linux too
2022-08-17 16:42:17 -04:00