Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set wasm32 target triple and data layout for the generated LLVM IR. #56

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lifter/Lift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ DEFINE_string(arch, REMILL_ARCH,
DEFINE_string(target_elf, "DUMMY_ELF", "Name of the target ELF binary");
DEFINE_string(dbg_fun_cfg, "", "Function Name of the debug target");
DEFINE_string(bitcode_path, "", "Function Name of the debug target");
DEFINE_string(target_arch, "", "Target Architecture for conversion");

extern "C" void debug_stream_out_sigaction(int sig, siginfo_t *info, void *ctx) {
std::cout << remill::ECV_DEBUG_STREAM.str();
Expand Down Expand Up @@ -148,6 +149,19 @@ int main(int argc, char *argv[]) {
/* generate LLVM bitcode file */
auto host_arch = remill::Arch::Build(&context, os_name, remill::GetArchName(REMILL_ARCH));
host_arch->PrepareModule(module.get());

// Set wasm32-unknown-wasi and wasm32 data layout if necessary.
if (FLAGS_target_arch == "wasm32") {
auto wasm32_dl =
llvm::DataLayout("e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20");
module->setDataLayout(wasm32_dl.getStringRepresentation());
llvm::Triple wasm32_triple;
wasm32_triple.setArch(llvm::Triple::wasm32);
wasm32_triple.setVendor(llvm::Triple::UnknownVendor);
wasm32_triple.setOS(llvm::Triple::WASI);
module->setTargetTriple(wasm32_triple.str());
}

remill::StoreModuleToFile(module.get(), FLAGS_bc_out);

printf("[\033[32mINFO\033[0m] Lift Done.\n");
Expand Down
9 changes: 8 additions & 1 deletion scripts/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,20 @@ lifting() {
# ELF -> LLVM bc
echo -e "[\033[32mINFO\033[0m] ELF Converting Start."
elf_path=$( realpath "$1" )

wasm32_target_arch=''
if [ "${TARGET}" == "wasi" ]; then
wasm32_target_arch='wasm32'
fi

cd ${BUILD_LIFTER_DIR} && \
./elflift \
--arch aarch64 \
--bc_out ./lift.bc \
--target_elf "$elf_path" \
--dbg_fun_cfg "$2" \
--bitcode_path "$3" && \
--bitcode_path "$3" \
--target_arch "$wasm32_target_arch" && \
llvm-dis-${LLVM_VERSION} lift.bc -o lift.ll
echo -e "[\033[32mINFO\033[0m] Generate lift.bc."

Expand Down
Loading