Skip to content

Commit

Permalink
Pass opaque pointer flag to Clang so it can handle Remill's IR (#605)
Browse files Browse the repository at this point in the history
* Pass the opaque pointer flag to Clang so it can handle Remill's IR

* Fix linker errors in tests

* Turn down optimization in the Remill optimizer
  • Loading branch information
tetsuo-cpp authored Jun 27, 2022
1 parent 6873a4c commit 65549b3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
10 changes: 8 additions & 2 deletions lib/BC/Optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ void OptimizeModule(const remill::Arch *arch, llvm::Module *module,
TLI->disableAllFunctions(); // `-fno-builtin`.

llvm::PassManagerBuilder builder;
builder.OptLevel = 3;
// TODO(alex): Some of the optimization passes that the builder adds still rely on typed pointers
// so we cannot use them. We should switch to using the new pass manager and choose which passes
// we want.
builder.OptLevel = 0;
builder.SizeLevel = 0;
builder.Inliner = llvm::createFunctionInliningPass(250);
builder.LibraryInfo = TLI; // Deleted by `llvm::~PassManagerBuilder`.
Expand Down Expand Up @@ -94,7 +97,10 @@ void OptimizeBareModule(llvm::Module *module, OptimizationGuide guide) {
TLI->disableAllFunctions(); // `-fno-builtin`.

llvm::PassManagerBuilder builder;
builder.OptLevel = 3;
// TODO(alex): Some of the optimization passes that the builder adds still rely on typed pointers
// so we cannot use them. We should switch to using the new pass manager and choose which passes
// we want.
builder.OptLevel = 0;
builder.SizeLevel = 0;
builder.Inliner = llvm::createFunctionInliningPass(250);
builder.LibraryInfo = TLI; // Deleted by `llvm::~PassManagerBuilder`.
Expand Down
1 change: 1 addition & 0 deletions tests/AArch64/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ add_custom_command(
-S -O1 -g0
-c tests_aarch64.bc
-o tests_aarch64.S
-mllvm -opaque-pointers
DEPENDS tests_aarch64.bc
)

Expand Down
2 changes: 2 additions & 0 deletions tests/AArch64/Run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ MAKE_RW_FP_MEMORY(32)
MAKE_RW_FP_MEMORY(64)
MAKE_RW_FP_MEMORY(128)

State __remill_state{};

NEVER_INLINE Memory *__remill_read_memory_f80(Memory *, addr_t addr,
native_float80_t &out) {
out = AccessMemory<native_float80_t>(addr);
Expand Down
16 changes: 8 additions & 8 deletions tests/X86/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ function(COMPILE_X86_TESTS name address_size has_avx has_avx512)
-DGTEST_HAS_RTTI=0
-DGTEST_HAS_TR1_TUPLE=0
)

add_executable(lift-${name}-tests
EXCLUDE_FROM_ALL
Lift.cpp
Tests.S
)

target_compile_options(lift-${name}-tests
PRIVATE ${X86_TEST_FLAGS} -DIN_TEST_GENERATOR
)

file(GLOB X86_TEST_FILES
"${CMAKE_CURRENT_LIST_DIR}/*/*.S"
)

set_target_properties(lift-${name}-tests PROPERTIES OBJECT_DEPENDS "${X86_TEST_FILES}")

target_link_libraries(lift-${name}-tests PRIVATE remill GTest::gtest)
Expand All @@ -49,19 +49,19 @@ function(COMPILE_X86_TESTS name address_size has_avx has_avx512)
COMMAND lift-${name}-tests --arch ${name} --bc_out tests_${name}.bc
DEPENDS semantics
)

add_custom_command(
OUTPUT tests_${name}.S
COMMAND ${CMAKE_BC_COMPILER} -Wno-override-module -S -O0 -g0 -c tests_${name}.bc -o tests_${name}.S
COMMAND ${CMAKE_BC_COMPILER} -Wno-override-module -S -O0 -g0 -c tests_${name}.bc -o tests_${name}.S -mllvm -opaque-pointers
DEPENDS tests_${name}.bc
)

add_executable(run-${name}-tests EXCLUDE_FROM_ALL Run.cpp Tests.S tests_${name}.S)
set_target_properties(run-${name}-tests PROPERTIES OBJECT_DEPENDS "${X86_TEST_FILES}")

target_link_libraries(run-${name}-tests PUBLIC remill GTest::gtest)
target_compile_definitions(run-${name}-tests PUBLIC ${PROJECT_DEFINITIONS})

target_compile_options(run-${name}-tests
PRIVATE ${X86_TEST_FLAGS}
)
Expand Down
2 changes: 2 additions & 0 deletions tests/X86/Run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ MAKE_RW_FP_MEMORY(64)
//MAKE_RW_FP_MEMORY(80)
MAKE_RW_FP_MEMORY(128)

State __remill_state{};

NEVER_INLINE Memory *__remill_read_memory_f80(Memory *, addr_t addr,
native_float80_t &out) {
out = AccessMemory<native_float80_t>(addr);
Expand Down

0 comments on commit 65549b3

Please sign in to comment.