Skip to content

Commit

Permalink
Merge pull request #14 from yomaytk/performance
Browse files Browse the repository at this point in the history
Fix workflows and integration tests.
  • Loading branch information
yomaytk authored Feb 16, 2024
2 parents 982a29d + 8e9f0cc commit 66bce25
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 53 deletions.
Binary file added examples/hello/a.failed_arm64
Binary file not shown.
6 changes: 3 additions & 3 deletions lifter/Lift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

#include "MainLifter.h"
#include "TraceManager.h"
#include "remill/BC/HelperMacro.h"
#include "remill/BC/Lifter.h"
#include "utils/Util.h"

#include <llvm/IR/LegacyPassManager.h>
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
#include <remill/BC/HelperMacro.h>
#include <remill/BC/Lifter.h>
#include <remill/BC/Optimizer.h>
#include <utils/Util.h>
DEFINE_string(bc_out, "", "Name of the file in which to place the generated bitcode.");

DEFINE_string(os, REMILL_OS,
Expand Down
6 changes: 3 additions & 3 deletions lifter/MainLifter.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "MainLifter.h"

#include "remill/Arch/Arch.h"
#include "remill/BC/ABI.h"
#include "utils/Util.h"
#include <remill/Arch/Arch.h>
#include <remill/BC/ABI.h>
#include <utils/Util.h>

/* Set entry function pointer */
void MainLifter::SetEntryPoint(std::string &entry_func_name) {
Expand Down
3 changes: 2 additions & 1 deletion lifter/MainLifter.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#include "Binary/Loader.h"
#include "remill/BC/TraceLifter.h"

#include <remill/BC/TraceLifter.h>

using namespace remill;

Expand Down
5 changes: 4 additions & 1 deletion lifter/TraceManager.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "TraceManager.h"

#include "Lift.h"
#include "utils/Util.h"

#include <utils/Util.h>

void AArch64TraceManager::SetLiftedTraceDefinition(uint64_t addr, llvm::Function *lifted_func) {
traces[addr] = lifted_func;
Expand Down Expand Up @@ -121,6 +122,8 @@ void AArch64TraceManager::SetELFData() {
}
/* set instructions of every block of .plt section (FIXME) */
auto plt_section = elf_obj.code_sections[".plt"];
if (plt_section.sec_name.empty())
plt_section = elf_obj.code_sections[".iplt"];
if (!plt_section.sec_name.empty()) {
uint64_t ins_i = 0;
while (ins_i < plt_section.size) {
Expand Down
24 changes: 12 additions & 12 deletions lifter/TraceManager.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
#pragma once
#include <gflags/gflags.h>
#include <glog/logging.h>
#include "Binary/Loader.h"
#include "remill/Arch/AArch64/Runtime/State.h"
#include "remill/Arch/Arch.h"
#include "remill/Arch/Instruction.h"
#include "remill/Arch/Name.h"
#include "remill/Arch/Runtime/Intrinsics.h"
#include "remill/Arch/Runtime/Runtime.h"
#include "remill/BC/IntrinsicTable.h"
#include "remill/BC/Lifter.h"
#include "remill/BC/Util.h"
#include "remill/OS/OS.h"

#include <algorithm>
#include <cstdint>
#include <fstream>
#include <gflags/gflags.h>
#include <glog/logging.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/GlobalValue.h>
#include <llvm/IR/Instructions.h>
Expand All @@ -24,6 +14,16 @@
#include <llvm/IR/Type.h>
#include <map>
#include <memory>
#include <remill/Arch/AArch64/Runtime/State.h>
#include <remill/Arch/Arch.h>
#include <remill/Arch/Instruction.h>
#include <remill/Arch/Name.h>
#include <remill/Arch/Runtime/Intrinsics.h>
#include <remill/Arch/Runtime/Runtime.h>
#include <remill/BC/IntrinsicTable.h>
#include <remill/BC/Lifter.h>
#include <remill/BC/Util.h>
#include <remill/OS/OS.h>
#include <sstream>
#include <string>

Expand Down
6 changes: 3 additions & 3 deletions runtime/Entry.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "Memory.h"
#include "remill/Arch/AArch64/Runtime/State.h"
#include "remill/Arch/Runtime/Intrinsics.h"
#include "remill/BC/HelperMacro.h"

#include <cstdint>
#include <cstring>
#include <map>
#include <remill/Arch/AArch64/Runtime/State.h>
#include <remill/Arch/Runtime/Intrinsics.h>
#include <remill/BC/HelperMacro.h>
#include <stdio.h>

State g_state = State();
Expand Down
5 changes: 2 additions & 3 deletions runtime/Memory.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include "Memory.h"

#include "utils/Util.h"
#include "utils/elfconv.h"

#include <iomanip>
#include <iostream>
#include <utils/Util.h>
#include <utils/elfconv.h>

// #define MULSECTIONS_WARNING_MSG 1

Expand Down
5 changes: 2 additions & 3 deletions runtime/Memory.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#pragma once

#include "remill/Arch/AArch64/Runtime/State.h"
#include "remill/Arch/Runtime/Types.h"

#include <cstring>
#include <map>
#include <remill/Arch/AArch64/Runtime/State.h>
#include <remill/Arch/Runtime/Types.h>
#include <string>
#include <unistd.h>
#include <unordered_map>
Expand Down
6 changes: 3 additions & 3 deletions runtime/Syscall.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include "Memory.h"
#include "remill/Arch/AArch64/Runtime/State.h"
#include "remill/BC/HelperMacro.h"
#include "utils/Util.h"

#include <algorithm>
#include <cstring>
#include <iostream>
#include <remill/Arch/AArch64/Runtime/State.h>
#include <remill/BC/HelperMacro.h>
#include <signal.h>
#include <stdlib.h>
#include <string>
Expand All @@ -16,6 +15,7 @@
#include <sys/utsname.h>
#include <termios.h>
#include <unistd.h>
#include <utils/Util.h>

#if defined(ELFCONV_SYSCALL_DEBUG)
# define EMPTY_SYSCALL(sysnum) printf("[WARNING] syscall \"" #sysnum "\" is empty now.\n");
Expand Down
10 changes: 5 additions & 5 deletions runtime/VmIntrinsics.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "Memory.h"
#include "remill/Arch/AArch64/Runtime/State.h"
#include "remill/Arch/Runtime/Intrinsics.h"
#include "remill/BC/HelperMacro.h"
#include "utils/Util.h"
#include "utils/elfconv.h"

#include <cstdarg>
#include <iomanip>
#include <iostream>
#include <remill/Arch/AArch64/Runtime/State.h>
#include <remill/Arch/Runtime/Intrinsics.h>
#include <remill/BC/HelperMacro.h>
#include <utils/Util.h>
#include <utils/elfconv.h>

#define UNDEFINED_INTRINSICS(intrinsics) \
printf("[ERROR] undefined intrinsics: %s\n", intrinsics); \
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ LIFT_DEBUG_MACROS=
CXX_COMMON_VERSION="0.5.0"
EMCC=emcc
EMAR=emar
EMCCFLAGS="-I"$( realpath "${REMILL_DIR}" )"/include -O3"
EMCCFLAGS="-I"$( realpath "${REMILL_DIR}" )"/include -I${ROOT_DIR} -O3"
RUNTIME_DIR=""$( realpath "${ROOT_DIR}" )"/runtime"
UTILS_DIR=""$( realpath "${ROOT_DIR}" )"/utils"
ELFCONV_MACROS="-DELFCONV_BROWSER_ENV=1"
Expand Down
10 changes: 8 additions & 2 deletions scripts/container-entry-point.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ source ~/.bash_profile
./scripts/build.sh

# elfconv integration test
make -C ~/elfconv/examples/print_hello
make -C ~/elfconv/examples/eratosthenes_sieve
make -C ~/elfconv/examples/hello
cd ~/elfconv/build && ctest && cd ~/elfconv
cd ~/elfconv/build
if ctest; then
echo "Integration Test Passed."
else
echo "Integration Test failed."
exit 1
fi
cd ~/elfconv

# bash
exec bash && source ~/.bash_profile
2 changes: 2 additions & 0 deletions tests/elfconv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ target_link_libraries(
GTest::gtest_main
)

target_include_directories(elfconv_test PRIVATE ${CMAKE_SOURCE_DIR})

include(GoogleTest)
gtest_discover_tests(elfconv_test)
21 changes: 10 additions & 11 deletions tests/elfconv/Test.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "../../utils/Util.h"

#include <gtest/gtest.h>
#include <gtest/internal/gtest-port.h>
#include <stdio.h>
#include <stdlib.h>
#include <utils/Util.h>

using ::testing::InitGoogleTest;
using ::testing::Test;
Expand All @@ -12,10 +11,12 @@ using ::testing::UnitTest;

#define ECV_PATH(path) "../../../" #path
#define EMCC_HOST_CMD(ident) \
"emcc -O0 -DELFCONV_SERVER_ENV=1 -I../../../backend/remill/include -o " #ident ".test.wasm.o " \
"emcc -O0 -DELFCONV_SERVER_ENV=1 -I../../../backend/remill/include -I../../../ -o " #ident \
".test.wasm.o " \
"-c ../../../runtime/" #ident ".cpp"
#define EMCC_UTILS_CMD(ident) \
"emcc -O0 -DELFCONV_SERVER_ENV=1 -I../../../backend/remill/include -o " #ident ".test.wasm.o " \
"emcc -O0 -DELFCONV_SERVER_ENV=1 -I../../../backend/remill/include -I../../../ -o " #ident \
".test.wasm.o " \
"-c ../../../utils/" #ident ".cpp"
#define EMCC_WASM_O(bc_ident) \
"emcc -c " bc_ident ".bc" \
Expand All @@ -25,22 +26,22 @@ using ::testing::UnitTest;

enum WASI_RUNTIME : uint8_t { WASMTIME, WASMEDGE };

void compile_fronts_emscripten();
void compile_runtime_emscripten();
void clean_up();

class TestEnvironment : public ::testing::Environment {
public:
~TestEnvironment() override {}
void SetUp() override {
compile_fronts_emscripten();
compile_runtime_emscripten();
}
void TearDown() override {
clean_up();
}
};

// compile `elfconv/runtime`
void compile_fronts_emscripten() {
void compile_runtime_emscripten() {
std::string cmds[] = {EMCC_HOST_CMD(Entry), EMCC_HOST_CMD(Memory),
EMCC_HOST_CMD(Syscall), EMCC_HOST_CMD(VmIntrinsics),
EMCC_UTILS_CMD(Util), EMCC_UTILS_CMD(elfconv)};
Expand Down Expand Up @@ -138,21 +139,19 @@ void unit_test_wasi_runtime(const char *program, const char *expected, WASI_RUNT
}

TEST(TestWasmtime, IntegrationExamplesTest) {
unit_test_wasi_runtime("print_hello", "Hello, World!\n", WASMTIME);
unit_test_wasi_runtime(
"eratosthenes_sieve",
"2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541\n",
WASMTIME);
// unit_test_wasi_runtime("hello", "Hello, World!\n", WASMTIME); (ERROR)
unit_test_wasi_runtime("hello", "Hello, World!\n", WASMTIME);
}

TEST(TestWasmedge, IntegrationExamplesTest) {
unit_test_wasi_runtime("print_hello", "Hello, World!\n", WASMEDGE);
unit_test_wasi_runtime(
"eratosthenes_sieve",
"2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541\n",
WASMEDGE);
// unit_test_wasi_runtime("hello", "Hello, World!\n", WASMTIME); (ERROR)
unit_test_wasi_runtime("hello", "Hello, World!\n", WASMTIME);
}

int main(int argc, char **argv) {
Expand Down
3 changes: 1 addition & 2 deletions utils/elfconv.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "elfconv.h"

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

#include <iomanip>
#include <iostream>
#include <remill/Arch/AArch64/Runtime/State.h>

#define PRINT_GPR(index) \
std::cout << std::hex << "x" << #index << ": 0x" << g_state.gpr.x##index.qword << std::endl;
Expand Down

0 comments on commit 66bce25

Please sign in to comment.