22# compiler detection
33#
44
5- if (DEFINED CMAKE_OSX_SYSROOT)
6- set (EXTRA_BC_SYSROOT -isysroot ${CMAKE_OSX_SYSROOT} )
7- endif ()
8-
5+ # NOTE: This is a fake sysroot, with just enough to build the semantics
6+ set (BC_SYSROOT "${PROJECT_SOURCE_DIR} /include/remill/Arch/Runtime/sysroot" )
97set (DEFAULT_BC_COMPILER_FLAGS
8+ "--sysroot=${BC_SYSROOT} "
9+ -nostdinc++
10+ -isystem "${BC_SYSROOT} "
11+
1012 -emit-llvm -Wno-unknown-warning-option -Wall -Wshadow
1113 -Wconversion -Wpadded -pedantic -Wshorten-64-to-32 -Wgnu-alignof-expression
1214 -Wno-gnu-anonymous-struct -Wno-return-type -c-linkage
@@ -19,7 +21,6 @@ set(DEFAULT_BC_COMPILER_FLAGS
1921 -Wno-unused-function -Wgnu-inline-cpp-without-extern
2022 -Wno-pass-failed=transform-warning
2123 -std=c++17
22- ${EXTRA_BC_SYSROOT}
2324)
2425
2526find_package (Clang CONFIG REQUIRED)
@@ -52,6 +53,8 @@ endif()
5253set (add_runtime_usage "add_runtime(target_name SOURCES <src1 src2> ADDRESS_SIZE <size> DEFINITIONS <def1 def2> BCFLAGS <bcflag1 bcflag2> LINKERFLAGS <lnkflag1 lnkflag2> INCLUDEDIRECTORIES <path1 path2> INSTALLDESTINATION <path> DEPENDENCIES <dependency1 dependency2>" )
5354
5455function (add_runtime target_name)
56+ set (BUILD_COMMANDS "" )
57+
5558 if (NOT DEFINED CMAKE_BC_COMPILER)
5659 message (FATAL_ERROR "The bitcode compiler was not found!" )
5760 endif ()
@@ -176,28 +179,22 @@ function(add_runtime target_name)
176179 set (additional_windows_settings "-D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH" )
177180 endif ()
178181
179- # The hyper call implementation contains inline assembly for each architecture so we'll need to
180- # cross-compile for the runtime architecture.
181- if (${source_file} STREQUAL ${hyper_call_source} )
182- # Some architectures add an explicit target for the host to successfully
183- # compile with 32 bits (like AArch64 to arm), however, we don't want that
184- # to interfere with the hyper call crosscompile
185- list (FILTER bc_flag_list EXCLUDE REGEX "--target=.*" )
186- set (target_decl "-target" "${arch} -none-eabi" )
187- elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
188- set (target_decl "-target" "x86_64-apple-macosx11.0.0" )
182+ # Only arm32 has eabihf (hard float)
183+ if ("${arch} " STREQUAL "arm" )
184+ set (target_decl "-target" "${arch} -none-eabihf" )
189185 else ()
190- unset (target_decl)
186+ set (target_decl "-target" " ${arch} -none-elf" )
191187 endif ()
192188
193-
194189 add_custom_command (OUTPUT "${absolute_output_file_path} "
195- COMMAND "${CMAKE_BC_COMPILER} " ${include_directory_list} ${additional_windows_settings} ${target_decl} "-DADDRESS_SIZE_BITS=${address_size} " ${definition_list} ${DEFAULT_BC_COMPILER_FLAGS} ${bc_flag_list} ${source_file_option_list} -c "${absolute_source_file_path} " -o "${absolute_output_file_path} "
190+ COMMAND "${CMAKE_BC_COMPILER} " ${include_directory_list} ${additional_windows_settings} ${target_decl} "-DADDRESS_SIZE_BITS=${address_size} " ${definition_list} ${DEFAULT_BC_COMPILER_FLAGS} ${bc_flag_list} ${source_file_option_list} -c "${absolute_source_file_path} " -o "${absolute_output_file_path} "
196191 MAIN_DEPENDENCY "${absolute_source_file_path} "
197192 ${dependency_list_directive}
198- COMMENT "Building BC object ${ absolute_output_file_path} "
193+ COMMENT "Building BC object: \" ${CMAKE_BC_COMPILER} \" ${include_directory_list} ${additional_windows_settings} ${target_decl} \" -DADDRESS_SIZE_BITS= ${address_size} \" ${definition_list} ${DEFAULT_BC_COMPILER_FLAGS} ${bc_flag_list} ${source_file_option_list} -c \" ${absolute_source_file_path} \" -o \" ${ absolute_output_file_path}\" "
199194 )
200195
196+ set (BUILD_COMMANDS "${BUILD_COMMANDS} \" ${CMAKE_BC_COMPILER} \" ${include_directory_list} ${additional_windows_settings} ${target_decl} \" -DADDRESS_SIZE_BITS=${address_size} \" ${definition_list} ${DEFAULT_BC_COMPILER_FLAGS} ${bc_flag_list} ${source_file_option_list} -c \" ${absolute_source_file_path} \" -o \" ${absolute_output_file_path} \"\n " )
197+
201198 set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${absolute_output_file_path} " )
202199 list (APPEND bitcode_file_list "${absolute_output_file_path} " )
203200 endforeach ()
@@ -213,6 +210,9 @@ function(add_runtime target_name)
213210 DEPENDS ${bitcode_file_list}
214211 COMMENT "Linking BC runtime ${absolute_target_path} "
215212 )
213+ set (BUILD_COMMANDS "${BUILD_COMMANDS} \" ${CMAKE_BC_LINKER} \" ${linker_flag_list} ${bitcode_file_list} -o \" ${absolute_target_path} \"\n " )
214+ string (REPLACE ";" " " BUILD_COMMANDS "${BUILD_COMMANDS} " )
215+ file (WRITE "${CMAKE_BINARY_DIR} /runtimes/${target_name} .txt" "${BUILD_COMMANDS} " )
216216
217217 set (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${absolute_target_path} " )
218218
0 commit comments