Commit Graph

13 Commits

Author SHA1 Message Date
XIN bd75b4f286 add KMOW (#561)
* add KMOW

* add KMOVW

* bug fix

* bug fix

Co-authored-by: yangjiaxin <yangjiaxin8@huawei.com>
2021-11-24 09:36:00 -05:00
Joe Ranweiler b50d29f1eb Remove illegal instruction from tests (#210)
* Remove illegal instruction from tests (#205)

The code segment (CS) register cannot be explicitly loaded, unlike the
other segment registers. The instruction `mov cs, rax` is thus illegal,
and triggered a SIGILL for each test case, causing all tests to
spuriously succeed.

* Remove unneeded DS register preservation around test cases

The commit that first added this included an illegal instruction, which
caused false positives and hid the fact that this is redundant.

* Revert "Restore previously failing FMA tests"

This reverts commit 9a9f370d08.

The bug in #205 is what made it seem like the underlying issue here had
been addressed.

* Include segment registers in `SaveState()`

* If in 32-bit mode, check if we should zero out x87 CS
2017-12-23 18:12:04 -05:00
Peter Goodman 026ea1afec Issue 150 lift bin dir (#167)
* Added semantics and tests for SDIV

* Semantics and tests for SCVTF.

* Working on integer to/from float conversion bugs related to managing the fpu status register.

* Switch to using the check float function wrapper

* Remove unintentional call to fetestexcept

* Adding in a compiler reordering barrier.

* Added inline assembly that will force clang's optimizer to give up and filed a clang bug

* Adds some trailing spaces into some files. Re-enables all aarch64 tests.

* Added semantics and tests for SDIV

* Semantics and tests for SCVTF.

* Switch to using the check float function wrapper

* Remove unintentional call to fetestexcept

* Added inline assembly that will force clang's optimizer to give up and filed a clang bug

* Adds some trailing spaces into some files. Re-enables all aarch64 tests.

* Bringing the aarch64 branch back in line with master.

* Adds in a test and ISEL for LDR_BL_LDST_REGOFF, and fixes up the instructions in some SMOV and UMOV tests.

* Various fixes and some minor debugging aids for aarch64

* Resets the fenv before running lifted code.

* All existing aarch64 tests should now pass.
2017-11-29 22:53:58 -05:00
Peter Goodman 8456f10787 Improvements and packuswb (#165)
* This clarifies the difference between kCategoryInvalid and kCategoryError for instruction categories.

* Removes the --use-system-compiler option, and requires that clang always be used.

* Some general improvements, as well as semantics and tests for PACKUSWB.
2017-11-27 13:36:50 -05:00
Peter Goodman 927998635a Implements more accurate tracking of x87 exception flags, last instru… (#163)
* Implements more accurate tracking of x87 exception flags, last instruction pointer, last data pointer, and floating point instruction opcode.

* Fix that masks out the MXCSR register from being compared at the end of tests. We don't yet have good enough info to do this well. Moves the FCMOV instruction set to be under the purview of X87.cpp and its tests.

* Tests should pass now.

* Addressing issues Mike mentioned.
2017-11-14 22:50:28 -05:00
Peter Goodman 37c0a7126c Adds in explicit tracking of the FPU control word into the State stru… (#158)
* Adds in explicit tracking of the FPU control word into the State structure. This change helps make sure that VMill can initialize the FPU rounding modes correctly during its emulation. The AArch64 State struct already includes the fpcr.

* Update State.h
2017-11-09 14:23:40 -05:00
Peter Goodman b96aec8fd8 Issue 137 lift bin ls (#155)
* [WIP] Float Instructions for /bin/ls (#146)

* Added bunch of float instructions required by `ls`

Not all variants implemented but should follow same structure

* FADD
* FMUL
* FMOV
* FCVTZU
* FCMPE

Fixed bugs with FMOV_n_to_n

Implemented FMOV_D64 variant

Fixed up FADD, need to doublecheck edgecases

FMUL Added

Weird interaction with checking for denormalized output
fpclassify(prod) gives you FP_SUBNORMAL, but in the native code
the idc bit on SR and FPSR is not set so commented out for now

FCVTZU added - FPSR flags not being caught and set

Type fix In<float64_t>

Fixes for FCVTZU

Added FCMPE Sn

Cleanup testing

* Check unallocated encoding for float insts

* Minor modifications.

* Trying to wrap up some fpu operations inside of a function that can test the inputs and outputs.

* Semantics, but no tests, for some variants of FMUL, FADD, and FDIV.

* Tests for FDIV and FSUB. Additional tests for FADD and FMUL.

* Minor tweak.

* Minor tweak to using fetestexcept only once

* Added UNTESTED implementation of mrs with fpsr.

* FMOV vector instructions, some fixes (#149)

* FMOV vector instructions, some fixes

* More tests for FMOV_VECTOR

* Fix to STRH isel, uses the wrong semantics. Minor modification to add DEF_CONDs to the ForEachIsel iterator.

* Various instructions for aarch64 lifting WIP

* Tests working except where commented

Specifically STRH test throws some lifter error
FCVT has issues with flag determiniation

* Bug fix with oxc fpsr bit in print state

* FCVTS, FMOV_S, FMOV_D

* FNEG, FMADD_S/D

For FMADD still seeing weird issues with flag setting on multiplication
step when using denormals as factor, look into later

* More precise definition of segment selectors. Directory traversal utility function.

* Minor tweaks to existing APIs.

* FMADD has a bug with one type

* Fixed reimport of test

* Semantics and tests for BICS.

* Minor fix to tests.

* Semantics and tests for integer REV instructions.

* Minor fix.

* Minor fixes, forgot an ISEL.

* Tests for MOVK.

* Tests for MOVZ.

* Forgot test file.

* More STR-related tests.

* Minor fix

* Minor fix

* Post-decoder fixes for STR.

* Minor fix?

* Semantics and tests for general simd DUP.

* Minor fix for arrangement specifier. Found a possible bug in capstone/keystone.

* Wrong isel in test

* Semantics and tests for simd ADD and SUB.

* Semantics and tests for LD1_ASISDLSEP_I2_I2

* Whoops, forgot TEST_INPUTS to test.

* Semantics and tests for LD1_ASISDLSEP_I1_I1

* Used wrong isel names in tests.

* Tests and semantics for two more variants of post-index LD1

* Minor fix

* Minor fix to a check for large op sizes. Regenerated AArch64 Extract.cpp, ordering extractors by most constrained first. I observed an issue where LD1_ASISDLSEP_I3_I3 was incorrectly extracted as LD1_ASISDLSEP_R3_R3.

* Minor fix of a decoder routine for loading multiple structures.

* Semantics and tests for RBIT, SMOV, and UMOV. Also semantics, but NO tests for a large number of SIMD instructions.

* Tests for simd smax, smin, umax, umin.

* Tests for sminp, smaxp, uminp, umaxp.

* Tests for ADDP.

* Tests for the simd vector register of cmeq, cmgt, and cmge.

* Minor fix.

* Tests for cmeq, cmgt, and cmge that compare a vector against zero.
2017-11-04 15:52:23 -04:00
Peter Goodman bed610be6b Issue 137 lift bin ls (#142)
* Post-decoder, semantics, and tests for BFM.

* Semantics and tests for ANDS

* Minor naming conflict fix

* Semantics and tests for SMADDL and SMULH

* Semantics and tests for MADD

* Minor symbol renaming fix

* Semantics and tests for EXTR, which also implements ROR

* Minor fix to number of arguments to test

* Semantics, but NO tests for LSLV, LSRV, ASRV, and RORV.

* Semantics and tests for ORN

* Minor fix

* Semantics for SBC, but no tests. Added an AddWithCarryNZCV primitive, untested

* Missing two's complement negation in subs using new addwithcarrynzcv

* Tests for SBC. Semantics and tests for SBCS

* Semantics and tests for UCVTF

* Update state save/restore code to record SIMD regs

* Attempt to fix save/restore code

* More attempts at getting the save/restore assembly right, this time with the fpsr bits.

* More fixes

* More tests extracting the fpsr state. Also trying without including RestoreState.S. I don't remember why I had that.

* Semantics for SVC and BRK
2017-09-25 13:29:10 -04:00
Peter Goodman bef332fd2a Aarch64 tester (#128)
* Added in more aarch64 instructions. Fixed some x86 instructions. The x86 test cases now exercise each test through every possible combination of flags.

* Adding missing files

* Another missing file

* Rename file

* Fixup some macros

* IPR

* More improvements on the test runner

* Test runner fixes related to me not being familiar with aarch64 assembly

* Fixing default data layout

* Trying to use llc to compile bitcode to aarch64 assembly. wth.

* Revert back to using the CMAKE_BC_COMPILER for building the test assembly file instead of the whole CMAKE_LL_COMPILER stuff, now that I've adjusted cxx-common to use the right build target for aarch64.

* Documentation updates. Fixes for aarch64.

* Making progress. The native tests can run, but the first lifted test faults. Not yet sure why.

* Weirdest issue is happening on aarch64. A pointer argument is being compiled to an integer, and that's really screwing things up.

* Add caching of the libraries path to the main cmakelists to avoid having to re-run build.sh all the time when the TRAILOBITS_LIBRARIES env var is not globally defined. Experimenting with trying to force the semantics to be compiled using the x86_64 target, regardless of host arch, or modelled arch of the semantics. This is to try to get around the issue where a single-element struct containing a pointer is lowered into a uintptr_t when passed by value as an argument on aarch64.

* Alright, falling back on handling this problem in the lifter (for now, at least). Really not ideal.

* Test runner works afaict
2017-08-04 15:24:46 -04:00
Peter Goodman 7dd87902ea Vmill (#106)
* Initial commit of x86 program snapshotter. Haven't yet figured out how to save a core dump to a specific file.

Now finds and saves core dumps (in a sketchy way).

Kind of but didn't really fix remill-disass with core dumps. It almost seems like a bunch of stuff is missing from within a core dump. It may be the case that it will be simpler to use binary ninja directly on snapshot files.

Working toward the executor.

Have snapshot creation and loading working. Next up: decoding the first few instructions!

Starting to serverize remill and setting up lines of communicating between vmill and remill. Going to move on to finally implementing remill-opt.

Changed a bazillon things.

Fixed the dead register backward data-flow analysis.

Fixed soem bugs, added GEP re-association, working toward inserting stores that will kill values.

Got interprocedual dead store elimination working! :-D

Finally...dead store elimination

remill-opt is done.

Added Lifter interface

Spec'ing out the translation engine.

Got the dynamic decoder working!

Got bitcode caching working

Added caching layer for bytecode compilation.

Decided on how to access reg state and allocas in functions. The bytecode will treat the state struct and the alloca'd data as a contiguous, opaque, byte-addressible area.

Compiler seems to work

Refactor

Great progress...goodnight

Made it up to the first syscall

Fixed call to a hypercall intrinsics

Bug fixes, minor change to the CFG proto.

Refacotorings and changes

* Switching to trying nativeexec, and made memory32 map snapshot into low 32-bits of address space, preserving original addresses of program.

* About to make some interesting changes, so save save save

* Refactor done, now time to produce shared libraries

* Got initial execution of some stuff in PHP working.. it either seems like the code is in an infinite loop, or just horribly slow, not sure. Otherwise, amazing progress.

* Got initial compiling to a runtime dynamic library working

* Separated most DEF_ISEL_SEMs and tests still pass. Goodnight!

* Got incremental optimization and compilation working.

* Got caching of the bitcode file to disk working and periodically collapsing the shared libraries into a single library. OUT.

* Fixed some bugs

* Commit before the storm

* Made the JIT work again, still not that fast though.

* Minor logging fix

* Log an error that we're executing a missing instruction.

* JIT compile the whole module first, then incrementally JIT compile function partitions. Also, link in libm.

* Added new syscall

* Added breakpoint sync hypercall, useful for testing.

* Got a php5.4 unserialize bug to reproduce. Added remill-pinshot, which will use PIN to take a snapshot and print out a register trace. This is useful for debugging divergences. Fixed up the semantics of some instructions, and added semantics and tests for PSRLDQ.

* Simplifications to remill that removes all the various basic block arrays, and uses meta-data instead.

* Made cmake take over the test system

* Working on mega refactor to eventually permit klee support

* Made all semantics code return memory pointer; I think this makes LLVM's optimizer a bit happier. Made the __remill_sub_N things into global constants, referencing the actual functions, that have private linkage. Slowly getting back in the direction of execution. I've got some bitcode translation working (with a hard-coded address for my local php version). The address space stuff seems to work so far.

* Missing files.

* Other minor fixes

* rtti-related fixes for gtest

* minor travis config change

* minor travis config change

* sendfile no longer needed

* Disable building vmill on non-linux platforms

* Disable 32-bit test builds on macOS.

* Trying to get symbol names on mac right.

* Minor fix to save state code for tests, disable testing on macOS builds because of symbol mismatches in gtest.

* Fixup remill-disass to use the simplified proto structure. Something may be wrong with remill-opt, or installing remill opt. Remove caching from travis.
2017-03-23 15:49:33 -04:00
Peter Goodman 65f3812cce Opt (#76)
* Implements remill-opt

* Change back to google namespace

* ANother namespace change

* Should fix test runner.

* Try to fix deprecated use of fstat64 on macOS
2016-11-28 20:44:02 -05:00
Peter Goodman 20228d700d Fixes Issues #52 and #53. Addresses first comment of Issue #45. 2016-10-10 19:03:58 -04:00
Peter Goodman 08f5384a94 Issue 51 third party code (#60)
* Working on factoring out external dependencies

* Making progress

* CMake for remill-lift seems to work :-)

* Improving build process and dependency list. Using a blank ubuntu 14.04 vm for testing.

* Still fighting with various dependencies.

* Making more progress with CMake stuff! Now have the semantics get compiled with cmake, and support installing stuff. I have also attempted to auto-find the semantics files when --bc_in is not provided.

* Adding protobuf compilation back to the steps.

* Improving readme

* Improving readme

* Switch to using the  command.

* Updated travis. Updated README to include new build badge icons, to change where the ldconfig step goes, and to add a CMake notice for ubuntu trusty.

* Added script to generate tests. Added auto-yes in apt-add-repository commands.

* Minor fix

* Enable auto-finding of --bc_in based on --arch_in.

* Adding more test generation and compilation. Unfortunately compiling tests isn't working due to llvm::CloneFunctionInto not quite working anymore.

* llvm::CloneIntoFunction seems to work, which may resolve Issue #55. I'll need to double check with the official release version of LLVM; right now I'm using a custom debug build to try to catch issues. Added code to build and install gtest. Directly referenced which LLVM libraries must be linked. Added backup paths for deducing the semantics bitcode files based on the input arch. Made remill-lift report simple flag errors via stderr instead of using glog to abort the program. Fixed an issue where, when I added the various arch versions, xed was decoding avx-enabled instructions as 64-bit because the comparison condition deciding which decode state to use was too narrow.

* Tests generation and running scripts now work for me. Gotta test in fresh vms now.

* Addresses Issue #55. The problem was that the release version of clang 3.9 isn't guaranteed to preserve c++ variables name in the bitcode. I've added some stuff to re-introduce the variable names based on debug info.

* Build the test runner with rtti so that gtest doesn't complain on some versions of ubuntu.

* Fixing up Travis build stuff

* I am dumb; forgot to add the os-generic install file for travis to pick up.

* Change the trusty build type to generic, otherwise Travis uses a YUGE vm with all the things.

* Disable aptitude upgrading. dhclient is getting in the way.

* Re-order the linux-specific travis install script. Hope that protocol buffers gets installed correctly this time. Remove test generation and running from end of install script -- it doesn't belong there.

* Try to purge dhcp client, then add it back in, then do the normal update + upgrade

* Something is very dumb about Travi CI's generic linux build environment. It seems to be having trouble with the protobuf-compiler package -- that or somehting is going wrong just before that package is installed.

* Use the cpp build language -- I think this defaults to that mega vm though. Print out better OS information at the beginning of the travis install. Individually install needed packages, as opposed to doing it all at once.

* OK, using cpp language got me further, but builds take much longer. I was still missing cstdint, though. This time I'll try building with the generic trusty travis image, and with build-essential and the g++ 4.8 stdlib dev files installed.

* Lets try using the libstdc++ dev files

* Add in the x32 versions of the dev files. Hopefully that'll resolve the missing cstdint for the 32-bit builds of some of the instruction semantics bitcode files.

* Hopefully these are right!

* Install g++ multilib package.

* Simplifications to installer, and also to the README to now use g++-multilib.
2016-10-01 19:10:37 -04:00