Skip to content

Commit 65549b3

Browse files
authored
Pass opaque pointer flag to Clang so it can handle Remill's IR (#605)
* 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
1 parent 6873a4c commit 65549b3

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

lib/BC/Optimizer.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ void OptimizeModule(const remill::Arch *arch, llvm::Module *module,
5656
TLI->disableAllFunctions(); // `-fno-builtin`.
5757

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

9699
llvm::PassManagerBuilder builder;
97-
builder.OptLevel = 3;
100+
// TODO(alex): Some of the optimization passes that the builder adds still rely on typed pointers
101+
// so we cannot use them. We should switch to using the new pass manager and choose which passes
102+
// we want.
103+
builder.OptLevel = 0;
98104
builder.SizeLevel = 0;
99105
builder.Inliner = llvm::createFunctionInliningPass(250);
100106
builder.LibraryInfo = TLI; // Deleted by `llvm::~PassManagerBuilder`.

tests/AArch64/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ add_custom_command(
7171
-S -O1 -g0
7272
-c tests_aarch64.bc
7373
-o tests_aarch64.S
74+
-mllvm -opaque-pointers
7475
DEPENDS tests_aarch64.bc
7576
)
7677

tests/AArch64/Run.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ MAKE_RW_FP_MEMORY(32)
143143
MAKE_RW_FP_MEMORY(64)
144144
MAKE_RW_FP_MEMORY(128)
145145

146+
State __remill_state{};
147+
146148
NEVER_INLINE Memory *__remill_read_memory_f80(Memory *, addr_t addr,
147149
native_float80_t &out) {
148150
out = AccessMemory<native_float80_t>(addr);

tests/X86/CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ function(COMPILE_X86_TESTS name address_size has_avx has_avx512)
2424
-DGTEST_HAS_RTTI=0
2525
-DGTEST_HAS_TR1_TUPLE=0
2626
)
27-
27+
2828
add_executable(lift-${name}-tests
2929
EXCLUDE_FROM_ALL
3030
Lift.cpp
3131
Tests.S
3232
)
33-
33+
3434
target_compile_options(lift-${name}-tests
3535
PRIVATE ${X86_TEST_FLAGS} -DIN_TEST_GENERATOR
3636
)
37-
37+
3838
file(GLOB X86_TEST_FILES
3939
"${CMAKE_CURRENT_LIST_DIR}/*/*.S"
4040
)
41-
41+
4242
set_target_properties(lift-${name}-tests PROPERTIES OBJECT_DEPENDS "${X86_TEST_FILES}")
4343

4444
target_link_libraries(lift-${name}-tests PRIVATE remill GTest::gtest)
@@ -49,19 +49,19 @@ function(COMPILE_X86_TESTS name address_size has_avx has_avx512)
4949
COMMAND lift-${name}-tests --arch ${name} --bc_out tests_${name}.bc
5050
DEPENDS semantics
5151
)
52-
52+
5353
add_custom_command(
5454
OUTPUT tests_${name}.S
55-
COMMAND ${CMAKE_BC_COMPILER} -Wno-override-module -S -O0 -g0 -c tests_${name}.bc -o tests_${name}.S
55+
COMMAND ${CMAKE_BC_COMPILER} -Wno-override-module -S -O0 -g0 -c tests_${name}.bc -o tests_${name}.S -mllvm -opaque-pointers
5656
DEPENDS tests_${name}.bc
5757
)
58-
58+
5959
add_executable(run-${name}-tests EXCLUDE_FROM_ALL Run.cpp Tests.S tests_${name}.S)
6060
set_target_properties(run-${name}-tests PROPERTIES OBJECT_DEPENDS "${X86_TEST_FILES}")
6161

6262
target_link_libraries(run-${name}-tests PUBLIC remill GTest::gtest)
6363
target_compile_definitions(run-${name}-tests PUBLIC ${PROJECT_DEFINITIONS})
64-
64+
6565
target_compile_options(run-${name}-tests
6666
PRIVATE ${X86_TEST_FLAGS}
6767
)

tests/X86/Run.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ MAKE_RW_FP_MEMORY(64)
181181
//MAKE_RW_FP_MEMORY(80)
182182
MAKE_RW_FP_MEMORY(128)
183183

184+
State __remill_state{};
185+
184186
NEVER_INLINE Memory *__remill_read_memory_f80(Memory *, addr_t addr,
185187
native_float80_t &out) {
186188
out = AccessMemory<native_float80_t>(addr);

0 commit comments

Comments
 (0)