Skip to content

Commit a6abbb8

Browse files
authored
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 221b70a. * Revert "dont run tests in docker deploys" This reverts commit 72229ac. * disable packaging in dockerfile * fix block packagingA * fix syntax
1 parent 047c628 commit a6abbb8

File tree

5 files changed

+78
-8
lines changed

5 files changed

+78
-8
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ RUN git config --global user.email "41898282+github-actions[bot]@users.noreply.g
3636
RUN ./scripts/build.sh \
3737
--llvm-version ${LLVM_VERSION} \
3838
--prefix /opt/trailofbits \
39-
--extra-cmake-args "-DCMAKE_BUILD_TYPE=Release"
39+
--extra-cmake-args "-DCMAKE_BUILD_TYPE=Release" \
40+
--disable-package
4041

4142
RUN pip3 install ./scripts/diff_tester_export_insns
4243

include/remill/Arch/AArch64/Runtime/State.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,31 @@ struct alignas(16) SIMD {
279279

280280
static_assert(512 == sizeof(SIMD), "Invalid packing of `struct SIMD`.");
281281

282+
struct alignas(8) SleighFlagState {
283+
uint8_t NG;
284+
volatile uint8_t _1;
285+
uint8_t ZR;
286+
volatile uint8_t _2;
287+
uint8_t CY;
288+
volatile uint8_t _3;
289+
uint8_t OV;
290+
volatile uint8_t _4;
291+
uint8_t shift_carry;
292+
volatile uint8_t _5;
293+
uint8_t tmpCY;
294+
volatile uint8_t _6;
295+
uint8_t tmpOV;
296+
volatile uint8_t _7;
297+
uint8_t tmpNG;
298+
volatile uint8_t _8;
299+
uint8_t tmpZR;
300+
volatile uint8_t _9;
301+
uint8_t padding[6];
302+
} __attribute__((packed));
303+
304+
static_assert(24 == sizeof(SleighFlagState),
305+
"Invalid packing of `struct SleighFlagState`.");
306+
282307
struct alignas(16) AArch64State : public ArchState {
283308
SIMD simd; // 512 bytes.
284309

@@ -298,9 +323,13 @@ struct alignas(16) AArch64State : public ArchState {
298323

299324
uint64_t _3;
300325

326+
SleighFlagState sleigh_flags;
327+
328+
uint8_t padding[8];
329+
301330
} __attribute__((packed));
302331

303-
static_assert((1152 + 16) == sizeof(AArch64State),
332+
static_assert((1152 + 16 + 24 + 8) == sizeof(AArch64State),
304333
"Invalid packing of `struct State`");
305334

306335
struct State : public AArch64State {};

lib/Arch/Sleigh/AArch64Arch.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <sstream>
55
#include <string>
66

7+
#include "remill/Arch/AArch64/AArch64Base.h"
78
#include "remill/Arch/Instruction.h"
89
#include "remill/Arch/Name.h"
910
#include "remill/BC/ABI.h"
@@ -24,8 +25,7 @@ namespace remill {
2425
// TODO(Ian): support different arm versions
2526
SleighAArch64Decoder::SleighAArch64Decoder(const remill::Arch &arch)
2627
: SleighDecoder(arch, "AARCH64.sla", "AARCH64.pspec",
27-
sleigh::ContextRegMappings({}, {}),
28-
{{"CY", "C"}, {"NG", "N"}, {"ZR", "Z"}, {"OV", "V"}}) {}
28+
sleigh::ContextRegMappings({}, {}), {}) {}
2929

3030

3131
void SleighAArch64Decoder::InitializeSleighContext(
@@ -76,6 +76,32 @@ DecodingContext AArch64Arch::CreateInitialContext(void) const {
7676
return DecodingContext();
7777
}
7878

79+
void AArch64Arch::PopulateRegisterTable(void) const {
80+
AArch64ArchBase::PopulateRegisterTable();
81+
82+
#define OFFSET_OF(type, access) \
83+
(reinterpret_cast<uintptr_t>(&reinterpret_cast<const volatile char &>( \
84+
static_cast<type *>(nullptr)->access)))
85+
86+
#define REG(name, access, type) \
87+
AddRegister(#name, type, OFFSET_OF(AArch64State, access), nullptr)
88+
89+
#define SUB_REG(name, access, type, parent_reg_name) \
90+
AddRegister(#name, type, OFFSET_OF(AArch64State, access), #parent_reg_name)
91+
92+
auto u8 = llvm::Type::getInt8Ty(*context);
93+
94+
REG(NG, sleigh_flags.NG, u8);
95+
REG(ZR, sleigh_flags.ZR, u8);
96+
REG(CY, sleigh_flags.CY, u8);
97+
REG(OV, sleigh_flags.OV, u8);
98+
REG(SHIFT_CARRY, sleigh_flags.shift_carry, u8);
99+
REG(TMPCY, sleigh_flags.tmpCY, u8);
100+
REG(TMPOV, sleigh_flags.tmpOV, u8);
101+
REG(TMPZR, sleigh_flags.tmpZR, u8);
102+
REG(TMPNG, sleigh_flags.tmpNG, u8);
103+
}
104+
79105

80106
// TODO(pag): We pretend that these are singletons, but they aren't really!
81107
Arch::ArchPtr Arch::GetAArch64Sleigh(llvm::LLVMContext *context_,

lib/Arch/Sleigh/AArch64Arch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class AArch64Arch final : public AArch64ArchBase {
2727
virtual ~AArch64Arch(void);
2828

2929

30+
void PopulateRegisterTable(void) const override;
31+
3032
virtual DecodingContext CreateInitialContext(void) const override;
3133

3234
bool DecodeInstruction(uint64_t address, std::string_view instr_bytes,

scripts/build.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ OS_VERSION=
2828
ARCH_VERSION=
2929
BUILD_FLAGS=
3030
CXX_COMMON_VERSION="0.3.1"
31+
CREATE_PACKAGES=true
3132

3233
# There are pre-build versions of various libraries for specific
3334
# Ubuntu releases.
@@ -275,9 +276,12 @@ function Package
275276
cmake --build . \
276277
--target install
277278

278-
cpack -D REMILL_DATA_PATH="${DESTDIR}" \
279-
-R ${remill_version} \
280-
--config "${SRC_DIR}/packaging/main.cmake"
279+
280+
if [ "$CREATE_PACKAGES" = true ]; then
281+
cpack -D REMILL_DATA_PATH="${DESTDIR}" \
282+
-R ${remill_version} \
283+
--config "${SRC_DIR}/packaging/main.cmake"
284+
fi
281285
) || return $?
282286

283287
return $?
@@ -366,6 +370,14 @@ function main
366370
shift # past argument
367371
;;
368372

373+
# Disable packages
374+
--disable-package)
375+
CREATE_PACKAGES=false
376+
echo "[+] Disabled building packages"
377+
shift # past argument
378+
;;
379+
380+
369381
# Make the build type to be a debug build.
370382
--debug)
371383
BUILD_FLAGS="${BUILD_FLAGS} -DCMAKE_BUILD_TYPE=Debug"
@@ -407,7 +419,7 @@ function main
407419
mkdir -p "${BUILD_DIR}"
408420
cd "${BUILD_DIR}" || exit 1
409421

410-
if ! (DownloadLibraries && Configure && Build && Package); then
422+
if ! (DownloadLibraries && Configure && Build && Package ); then
411423
echo "[x] Build aborted."
412424
exit 1
413425
fi

0 commit comments

Comments
 (0)