Skip to content

Commit eef338d

Browse files
2over12tetsuo-cppartemdinaburgpgoodman
authored
Ian/sleigh support rebased (#607)
* cmake: Bring in SLEIGH as a dependency * sleigh: Boilerplate for adding a new arch * sleigh: Begin passing instruction sequences into SLEIGH * cmake: Rename target to be X86 specific * sleigh: Copy over more X86 runtime code and get things running * sleigh: Begin populating operands in the returned instruction * sleigh: Set instruction category for a few opcodes * sleigh: Initial attempt at generating LLVM IR for P-Code * sleigh: Implement enough opcodes to run the `sleigh-lift` example * sleigh: Get things building with an up-to-date Remill tree * sleigh: Use the new SLA helpers * sleigh: Clear operands between invalid lifts * added thumb2 * stub out thumb * need to refactor to relift the instruction * factored lifter out of handler: * allow lifters to decide wether to use sleigh * relift bytes * fixed both lifter contexts * hey a copy lifted :) * need to refactor to use parameterptrs to unify interface to memory * refactored to use parameter abstraction * lift at correct location * add control flow to pc and next * add categories mostly * fix direct semantics add cbranch * track cbranch metavar also lift returns * cmake: Fix SleighArch.h path * sleigh: Support more binary ops * sleigh: Implement ZEXT * sleigh: Support SEXT op * sleigh: Implement 2COMP and INT_NEGATE * mutex around parsing sleigh specs * fixed typos in custom image * added handling for exceptions, need to fix issue with xml parsing * sleigh: Support boolean binops * sleigh: Support float binary ops * sleigh: Support a few more float pcode ops that require LLVM intrinsics * sleigh: Add entries for ops that require overflow intrinsics * sleigh: Implement more float unary ops * sleigh: Reduce duplication in ops that require float intrinsics * expose mutex * fix fallthough and format of control flow resolution * sleigh: Support CARRY, SCARRY and SBORROW * Remove duplicate THUMB2 arch in enum * Remove duplicate THUMB2 entry in archnames array * Implement STORE op * Fix incorrect index * Support PIECE and SUBPIECE ops * Support remaining set of PCode ops in the base set. Now to do the pseudo ops. * Implement additional ops * Partially implement a few pseudo ops + a few missing from the docs * Fix the variadic op condition * Include <mutex> to build on Linux * stop lying about insn categories/functions * set function insns with mnemonic * fix fallthrough for ind calls * More virtualization, fewer pimples * switch back to x86 normal * Fix off-by-eight issue with ADR in AArch32 * Get rid of mutex in sleigh, make a globally-available remill locker for handling sleigh issues * CHange allow 32 bit shift to true, not sure if valid but oh well * Use the node size when creating constants * fix memory * store memory state back * fix calling intrinsic table * fix comp sizes * load pspec data * add pspec names * add differential test * fix tests start pretty printer * add runner * added really slow memory * add comparison of memory state * do reset * fix uninitialized module * fixed lift crash * add amd64 runtime * unfix fs, gs, and pc * added whitelist file * fix memory to update state with uninitialized reads * better pc handling * add main.py * x86 compiles * fixup patch generation * add replacements for mem locs and constant varnodes, now need to handle special branches * added replacement for direct branches * add context clears * add handler for claim_eq * comment out clears for now * added ambiguity check * handle duplicate names in same constructor * mantain sleigh invariant of 1 or 0 in flag * added uint8t memory intrinsics * extend shift value when needed * handle cmovs * update patch generation * removed deprecated load * fix for returned type * builds * add logging * add comment on why not compute GEPAccessors in Arch.cpp * enable opaque pointers * fix memory state update * add mem_16 impls * not preserve 1 bit width * fix CR changes * fix L and R for shift operands bigger than target * revert use after move * more CR fixes * remove lookahead... lets try this again * rework to create internal function that is inlined to allow for early return control flow * terminate conditionally * avoid large iteration counts for .REP insns * fix patch for rep insns * handle inst_start in patches * handle inserting insn_size constructor outside of macros * hint size of insn_size * refactor bool functions to make more sense * just use ; * remove delete of operands when fail to lift * remove copy and paste * remove unused deps * add patch file to sleigh list * prep git user * refer to checkout * maybe shell type? * fix layout * fix format again * fix * update dockerfile * fix gitwatcher to point to current project: * Revert "fix gitwatcher to point to current project:" This reverts commit 711da11. * fix ninja builds * disable sleigh tests * remove duplicates * refactor * fix non reset context in sleigh lifter * remove debugging prints * wrote CI runner * add handwritten test infra * refactor to allow sharing JIT test running between differential tester and hand written tests * allow for internal ownership of semantics module * handwritten test framework * fix hand written tests * pc rel testruns * add pc rel regression * fix script for pc rel * fix names for priors to ignore whitespace * fix action ops * add xor to repl ops * add xors to patch * add arm patch to build * fix test for semantics * allow cross platform tests to run * add running diff tester * 2 underscores? * run tests on macos too * fix command * fix whitelist path * remove unused test data * install python deps for differential tests * update script to git patches * update patches to git format * attempt to fixup patches * update ref for sleigh * install test depends docker * point docker to correct dir * install pydeps in macos too * initialize address field * exports, also tag master on sleigh * add comments and whitelist undefined value OF in shifts * add of accessor to whitelist impl * change variables to non alloca and remove dead code * remove dead code: * replace dump with print * code quality * make non null into ref * type alias * remove allocas from unit tests * Address copypasta comment. * Address PR comment. * Address PR comment. * fix build * unify diff modules into single structure * remove extra newline * lock sleigh to specific commit * remove new lines * remove useless fenv headers * caps * copyright notices * update more copyright * fix reviews * early returns out of accessors * early return * auto * return getarchbyname * insert register rather than modify reference * just return * only log in the assembly logger * prefer functional style * remove commented code * move defaults to header * that's not how arch switches work in pcode * informative names * simplify control flow in fill * early return * fix early exit condition * refactor register default into function * make one liner * early return * unary instead of unop * construct pair with {} * move cbranch into binops instead of integer binops * refactor float ops into getter * factor out float type * early return * separate out callother handling * do pointer extensions cleaner * braces * add private headers to lifters * refactor redirecting control flow out of instruction * use constant check function * remove has_value * structure for preconditions * return success when applying eq claim * expose arch base and move shared functionality into x86 base * dedup x86 code * dedup aarch32 * remove needless assignment, also remove else after an if that returns Co-authored-by: Alex Cameron <[email protected]> Co-authored-by: Artem Dinaburg <[email protected]> Co-authored-by: Peter Goodman <[email protected]>
1 parent 66ef46b commit eef338d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+8661
-1226
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: 'Setup Git User for Applying Patches'
2+
description: 'Setup bot user so git doesnt complain when patching'
3+
# See this thread for more details https://github.community/t/github-actions-bot-email-address/17204/5
4+
runs:
5+
using: "composite"
6+
steps:
7+
- shell: bash
8+
run: |
9+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
10+
git config --global user.name "github-actions[bot]"

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
- uses: actions/checkout@v2
3737
with:
3838
fetch-depth: 0
39+
- uses: ./.github/actions/prepare_git_user
3940
- name: Build with build script
4041
shell: bash
4142
run: |
@@ -48,6 +49,11 @@ jobs:
4849
export VCPKG_ROOT=$(pwd)/../lifting-bits-downloads/vcpkg_${{ matrix.image.name }}-${{ matrix.image.tag }}_llvm-${{ matrix.llvm }}_amd64
4950
export INSTALL_DIR=$(pwd)/remill-preset-install
5051
./scripts/build-preset.sh release
52+
53+
- name: Install Python Test Deps
54+
shell: bash
55+
run: |
56+
pip3 install --user ./scripts/diff_tester_export_insns
5157
- name: Run tests
5258
shell: bash
5359
working-directory: remill-build
@@ -102,6 +108,7 @@ jobs:
102108
- uses: actions/checkout@v2
103109
with:
104110
fetch-depth: 0
111+
- uses: ./.github/actions/prepare_git_user
105112
- name: Build with build script
106113
shell: bash
107114
run: |
@@ -114,6 +121,10 @@ jobs:
114121
export VCPKG_ROOT=$(pwd)/../lifting-bits-downloads/vcpkg_${{ matrix.os}}_llvm-${{ matrix.llvm }}_xcode-13.0_amd64
115122
export INSTALL_DIR=$(pwd)/remill-preset-install
116123
./scripts/build-preset.sh release
124+
- name: Install Python Test Deps
125+
shell: bash
126+
run: |
127+
pip3 install --user ./scripts/diff_tester_export_insns
117128
- name: Run tests
118129
shell: bash
119130
working-directory: remill-build

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ cmake-build-debug
2626
cmake-build-release
2727
compile_commands.json
2828

29-
bin/*
3029

3130
third_party/*
3231
build/*

CMakeLists.txt

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# you may not use this file except in compliance with the License.
55
# You may obtain a copy of the License at
66
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
7+
# http://www.apache.org/licenses/LICENSE-2.0
88
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,7 +20,7 @@ include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/ccache.cmake")
2020

2121
project(remill C CXX ASM)
2222
include(GNUInstallDirs)
23-
23+
include(FetchContent)
2424
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/settings.cmake")
2525
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils.cmake")
2626
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/options.cmake")
@@ -72,6 +72,7 @@ include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/BCCompiler.cmake")
7272
# Go find only the static libraries of LLVM, and link against those.
7373
foreach(LLVM_LIB IN LISTS LLVM_AVAILABLE_LIBS)
7474
get_target_property(LLVM_LIB_TYPE ${LLVM_LIB} TYPE)
75+
7576
if(LLVM_LIB_TYPE STREQUAL "STATIC_LIBRARY")
7677
list(APPEND LLVM_LIBRARIES "${LLVM_LIB}")
7778
endif()
@@ -88,7 +89,7 @@ target_link_libraries(thirdparty_llvm INTERFACE
8889
# Microsoft Z3 with LLVM. Not exactly used in remill, but LLVM doesn't link
8990
# against it correctly
9091
# NOTE: If changing this, also replicate in remillConfig file
91-
if (LLVM_WITH_Z3)
92+
if(LLVM_WITH_Z3)
9293
find_package(Z3 CONFIG REQUIRED 4.7.1)
9394
get_target_property(LLVMSupport_LIBS LLVMSupport INTERFACE_LINK_LIBRARIES)
9495
list(REMOVE_ITEM LLVMSupport_LIBS Z3)
@@ -120,15 +121,32 @@ target_link_libraries(thirdparty_gflags INTERFACE
120121
gflags
121122
)
122123

124+
set(sleigh_ENABLE_TESTS OFF)
125+
set(sleigh_ADDITIONAL_PATCHES "${CMAKE_CURRENT_SOURCE_DIR}/patches/sleigh/x86-ia.patch;${CMAKE_CURRENT_SOURCE_DIR}/patches/sleigh/arm-thumb.patch")
126+
127+
# GHIDRA SLEIGH
128+
FetchContent_Declare(sleigh
129+
GIT_REPOSITORY https://github.com/lifting-bits/sleigh.git
130+
GIT_TAG 5ee2f2c16250a6529108e6a6fff89e0f147502d2
131+
)
132+
133+
FetchContent_MakeAvailable(sleigh)
134+
add_library(thirdparty_sleigh INTERFACE)
135+
target_link_libraries(thirdparty_sleigh INTERFACE
136+
sleigh::sla
137+
sleigh::decomp
138+
sleigh::support
139+
)
140+
123141
# Windows SDK
124142
add_library(thirdparty_win32 INTERFACE)
143+
125144
if(DEFINED WIN32)
126145
target_link_libraries(thirdparty_win32 INTERFACE
127-
"Kernel32.lib"
146+
"Kernel32.lib"
128147
)
129148
endif()
130149

131-
132150
# For Linux builds, group LLVM libraries into a single group
133151
# that avoids frustrating library ordering issues.
134152
if(UNIX AND NOT APPLE)
@@ -150,7 +168,6 @@ option(REMILL_BUILD_SPARC32_RUNTIME "Build the Runtime for SPARC32. Turn this of
150168
#
151169

152170
# add everything as public.
153-
154171
add_library(remill_settings INTERFACE)
155172

156173
target_include_directories(remill_settings INTERFACE
@@ -235,7 +252,7 @@ target_compile_definitions(remill_settings INTERFACE
235252
"REMILL_BUILD_SEMANTICS_DIR_SPARC64=\"${REMILL_BUILD_SEMANTICS_DIR_SPARC64}\""
236253
)
237254

238-
set(THIRDPARTY_LIBRARY_LIST thirdparty_llvm thirdparty_xed thirdparty_glog thirdparty_gflags)
255+
set(THIRDPARTY_LIBRARY_LIST thirdparty_llvm thirdparty_xed thirdparty_glog thirdparty_gflags thirdparty_sleigh)
239256
target_link_libraries(remill_settings INTERFACE
240257
${THIRDPARTY_LIBRARY_LIST}
241258
)
@@ -259,7 +276,6 @@ target_link_libraries(remill INTERFACE
259276
#
260277
# Also install clang, libllvm and llvm-link
261278
#
262-
263279
set(INSTALLED_CLANG_NAME "remill-clang-${REMILL_LLVM_VERSION}${CMAKE_EXECUTABLE_SUFFIX}")
264280
set(INSTALLED_LLVMLINK_NAME "remill-llvm-link-${REMILL_LLVM_VERSION}${CMAKE_EXECUTABLE_SUFFIX}")
265281

@@ -269,15 +285,18 @@ InstallExternalTarget("ext_llvmlink" "${LLVMLINK_PATH}" "BIN" "${INSTALLED_LLVML
269285

270286
GetTargetTree(THIRDPARTY_LIBRARIES ${THIRDPARTY_LIBRARY_LIST})
271287
GetPublicIncludeFolders(THIRDPARTY_INCLUDE_DIRECTORIES ${THIRDPARTY_LIBRARIES})
288+
272289
foreach(THIRDPARTY_LIB IN LISTS THIRDPARTY_LIBRARIES)
273290
string(SUBSTRING "${THIRDPARTY_LIB}" 0 1 THIRDPARTY_LIB_PREFIX)
291+
274292
if(TARGET ${THIRDPARTY_LIB})
275293
get_target_property(THIRDPARTY_LIB_TYPE ${THIRDPARTY_LIB} TYPE)
294+
276295
if(THIRDPARTY_LIB_TYPE STREQUAL "STATIC_LIBRARY" OR THIRDPARTY_LIB_TYPE STREQUAL "SHARED_LIBRARY")
277296
list(APPEND THIRDPARTY_LIBRARY_FILES "$${}<TARGET_FILE:${THIRDPARTY_LIB}>")
278297
endif()
279298
elseif("${THIRDPARTY_LIB_PREFIX}" STREQUAL "$${}")
280-
# E.g. $<LINK_ONLY:...>
299+
# E.g. $<LINK_ONLY:...>
281300
else()
282301
list(APPEND THIRDPARTY_LIBRARY_FILES "${THIRDPARTY_LIB}")
283302
endif()
@@ -288,31 +307,33 @@ list(REMOVE_DUPLICATES THIRDPARTY_LIBRARY_FILES)
288307
#
289308
# additional targets
290309
#
291-
292310
add_custom_target(semantics)
293311

312+
# shared JIT tools
313+
add_subdirectory(test_runner_lib)
314+
294315
# tools
295316
add_subdirectory(bin)
296317

297318
if(REMILL_ENABLE_INSTALL_TARGET)
298319
install(TARGETS remill EXPORT remillTargets)
299-
320+
300321
install(TARGETS remill_settings ${THIRDPARTY_LIBRARY_LIST}
301322
EXPORT remillTargets
302323
)
303-
324+
304325
# First do the basic substitutions.
305326
configure_file(
306327
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/remillConfig.cmake.in"
307328
"${CMAKE_CURRENT_BINARY_DIR}/remillConfig.cmake"
308329
@ONLY
309330
)
310-
331+
311332
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/remillConfig.cmake"
312-
"${CMAKE_CURRENT_LIST_DIR}/cmake/vcpkg_helper.cmake"
333+
"${CMAKE_CURRENT_LIST_DIR}/cmake/vcpkg_helper.cmake"
313334
DESTINATION "${REMILL_INSTALL_LIB_DIR}/cmake/remill"
314335
)
315-
336+
316337
install(DIRECTORY "${REMILL_INCLUDE_DIR}/remill/"
317338
DESTINATION "${REMILL_INSTALL_INCLUDE_DIR}/remill"
318339
)
@@ -322,14 +343,19 @@ if(REMILL_ENABLE_INSTALL_TARGET)
322343
endif()
323344

324345
# tests
325-
if (REMILL_ENABLE_TESTING)
346+
if(REMILL_ENABLE_TESTING)
326347
# Tests require enabling exports on binaries
327348
# https://cmake.org/cmake/help/latest/variable/CMAKE_ENABLE_EXPORTS.html#variable:CMAKE_ENABLE_EXPORTS
328349
set(CMAKE_ENABLE_EXPORTS ON)
329350

330351
find_package(Threads REQUIRED)
331352
add_custom_target(test_dependencies)
332353

354+
if(REMILL_ENABLE_TESTING_SLEIGH_THUMB)
355+
message(STATUS "thumb tests enabled")
356+
add_subdirectory(tests/Thumb)
357+
endif()
358+
333359
if(REMILL_ENABLE_TESTING_X86)
334360
message(STATUS "X86 tests enabled")
335361
add_subdirectory(tests/X86)

Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ ARG LLVM_VERSION
3030

3131
WORKDIR /remill
3232
COPY ./ ./
33+
34+
RUN git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" && git config --global user.name "github-actions[bot]"
35+
3336
RUN ./scripts/build.sh \
34-
--llvm-version ${LLVM_VERSION} \
35-
--prefix /opt/trailofbits \
36-
--extra-cmake-args "-DCMAKE_BUILD_TYPE=Release"
37+
--llvm-version ${LLVM_VERSION} \
38+
--prefix /opt/trailofbits \
39+
--extra-cmake-args "-DCMAKE_BUILD_TYPE=Release"
40+
41+
RUN pip3 install ./scripts/diff_tester_export_insns
3742

3843
RUN cd remill-build && \
3944
cmake --build . --target test_dependencies -- -j $(nproc) && \

bin/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Copyright (c) 2017 Trail of Bits, Inc.
1+
# Copyright (c) 2022 Trail of Bits, Inc.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
55
# You may obtain a copy of the License at
66
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
7+
# http://www.apache.org/licenses/LICENSE-2.0
88
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,3 +14,6 @@
1414

1515
add_subdirectory(lift)
1616

17+
if(REMILL_ENABLE_DIFFERENTIAL_TESTING)
18+
add_subdirectory(differential_tester_x86)
19+
endif()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) 2022 Trail of Bits, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
find_package(Python COMPONENTS Interpreter)
16+
add_executable(
17+
lift-and-compare
18+
LiftAndCompare.cpp
19+
Whitelist.cpp
20+
Whitelist.h
21+
)
22+
23+
target_link_libraries(
24+
lift-and-compare
25+
PRIVATE
26+
remill
27+
thirdparty_glog
28+
test-runner
29+
)
30+
31+
set_property(TARGET lift-and-compare PROPERTY ENABLE_EXPORTS ON)
32+
set_property(TARGET lift-and-compare PROPERTY POSITION_INDEPENDENT_CODE ON)
33+
enable_testing()
34+
35+
add_test(NAME "small_diff_test" COMMAND "${Python_EXECUTABLE}" ${REMILL_SOURCE_DIR}/scripts/diff_tester_export_insns/diff_tester_export_insns/ci_runner.py --required_success_rate 1.0 --difftester_bin ${CMAKE_BINARY_DIR}/bin/differential_tester_x86/lift-and-compare --workdir ${CMAKE_BINARY_DIR} ${REMILL_SOURCE_DIR}/bin/differential_tester_x86/data/small_test/ --whitelist_file ${REMILL_SOURCE_DIR}/bin/differential_tester_x86/whitelist.json)

0 commit comments

Comments
 (0)