diff --git a/Cargo.lock b/Cargo.lock index bd11682..d8628b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1349,7 +1349,7 @@ dependencies = [ [[package]] name = "polkavm" version = "0.9.3" -source = "git+https://github.com/koute/polkavm.git#4ca06cc1b7cb435b2b92e81e30c2eb0e988f563e" +source = "git+https://github.com/xermicus/polkavm.git?branch=master_byteswap#73ab6d953c13de26ab75ed11707aa6d902ba47ea" dependencies = [ "libc", "log", @@ -1361,7 +1361,7 @@ dependencies = [ [[package]] name = "polkavm-assembler" version = "0.9.0" -source = "git+https://github.com/koute/polkavm.git#4ca06cc1b7cb435b2b92e81e30c2eb0e988f563e" +source = "git+https://github.com/xermicus/polkavm.git?branch=master_byteswap#73ab6d953c13de26ab75ed11707aa6d902ba47ea" dependencies = [ "log", ] @@ -1369,7 +1369,7 @@ dependencies = [ [[package]] name = "polkavm-common" version = "0.9.0" -source = "git+https://github.com/koute/polkavm.git#4ca06cc1b7cb435b2b92e81e30c2eb0e988f563e" +source = "git+https://github.com/xermicus/polkavm.git?branch=master_byteswap#73ab6d953c13de26ab75ed11707aa6d902ba47ea" dependencies = [ "log", ] @@ -1377,7 +1377,7 @@ dependencies = [ [[package]] name = "polkavm-linker" version = "0.9.2" -source = "git+https://github.com/koute/polkavm.git#4ca06cc1b7cb435b2b92e81e30c2eb0e988f563e" +source = "git+https://github.com/xermicus/polkavm.git?branch=master_byteswap#73ab6d953c13de26ab75ed11707aa6d902ba47ea" dependencies = [ "gimli", "hashbrown 0.14.3", @@ -1391,7 +1391,7 @@ dependencies = [ [[package]] name = "polkavm-linux-raw" version = "0.9.0" -source = "git+https://github.com/koute/polkavm.git#4ca06cc1b7cb435b2b92e81e30c2eb0e988f563e" +source = "git+https://github.com/xermicus/polkavm.git?branch=master_byteswap#73ab6d953c13de26ab75ed11707aa6d902ba47ea" [[package]] name = "ppv-lite86" @@ -1675,6 +1675,8 @@ dependencies = [ "polkavm", "revive-differential", "revive-solidity", + "serde", + "serde_json", "sha1", ] diff --git a/Cargo.toml b/Cargo.toml index 902f9e2..fbfbaa8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,9 +27,9 @@ path-slash = "0.2" rayon = "1.8" structopt = { version = "0.3", default-features = false } rand = "0.8" -polkavm-common = { git = "https://github.com/koute/polkavm.git" } -polkavm-linker = { git = "https://github.com/koute/polkavm.git" } -polkavm = { git = "https://github.com/koute/polkavm.git" } +polkavm-common = { branch = "master_byteswap", git = "https://github.com/xermicus/polkavm.git" } +polkavm-linker = { branch = "master_byteswap", git = "https://github.com/xermicus/polkavm.git" } +polkavm = { branch = "master_byteswap", git = "https://github.com/xermicus/polkavm.git" } alloy-primitives = "0.6" alloy-sol-types = "0.6" env_logger = { version = "0.10.0", default-features = false } diff --git a/build-llvm.sh b/build-llvm.sh index 2a1b12e..77ac449 100755 --- a/build-llvm.sh +++ b/build-llvm.sh @@ -37,7 +37,7 @@ cd ../compiler-rt mkdir -p build cd build -CFLAGS="--target=riscv32 -march=rv32em -mabi=ilp32e -nostdlib -nodefaultlibs -mcpu=generic-rv32" +CFLAGS="--target=riscv64 -march=rv64em -mabi=lp64e -nostdlib -nodefaultlibs -mcpu=generic-rv64" cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \ -DCOMPILER_RT_BUILD_BUILTINS=ON \ -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \ @@ -46,8 +46,8 @@ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \ -DCOMPILER_RT_BUILD_SANITIZERS=OFF \ -DCOMPILER_RT_BUILD_XRAY=OFF \ -DCMAKE_C_COMPILER=$INSTALL_DIR/bin/clang \ - -DCMAKE_C_COMPILER_TARGET="riscv32" \ - -DCMAKE_ASM_COMPILER_TARGET="riscv32" \ + -DCMAKE_C_COMPILER_TARGET="riscv64" \ + -DCMAKE_ASM_COMPILER_TARGET="riscv64" \ -DCMAKE_AR=$INSTALL_DIR/bin/llvm-ar \ -DCMAKE_NM=$INSTALL_DIR/bin/llvm-nm \ -DCMAKE_RANLIB=$INSTALL_DIR/bin/llvm-ranlib \ diff --git a/crates/builtins/build.rs b/crates/builtins/build.rs index e16d4eb..9e5993d 100644 --- a/crates/builtins/build.rs +++ b/crates/builtins/build.rs @@ -1,7 +1,7 @@ use std::{env, fs, io::Read, path::Path, process::Command}; fn main() { - let lib = "libclang_rt.builtins-riscv32.a"; + let lib = "libclang_rt.builtins-riscv64.a"; let mut llvm_lib_dir = String::new(); Command::new("llvm-config") @@ -16,7 +16,7 @@ fn main() { let lib_path = std::path::PathBuf::from(llvm_lib_dir.trim()) .join("linux") .join(lib); - let archive = fs::read(lib_path).expect("clang builtins for riscv32 not found"); + let archive = fs::read(lib_path).expect("clang builtins for riscv64 not found"); let out_dir = env::var_os("OUT_DIR").expect("has OUT_DIR"); let archive_path = Path::new(&out_dir).join(lib); diff --git a/crates/common/src/byte_length.rs b/crates/common/src/byte_length.rs index 7e59964..a1aa6f5 100644 --- a/crates/common/src/byte_length.rs +++ b/crates/common/src/byte_length.rs @@ -9,7 +9,7 @@ pub const BYTE_LENGTH_BYTE: usize = 1; pub const BYTE_LENGTH_X32: usize = 4; /// Native stack alignment size in bytes -pub const BYTE_LENGTH_STACK_ALIGN: usize = 4; +pub const BYTE_LENGTH_STACK_ALIGN: usize = BYTE_LENGTH_X64; /// The x86_64 word byte-length. pub const BYTE_LENGTH_X64: usize = 8; diff --git a/crates/extensions/bswap.ll b/crates/extensions/bswap.ll index 36a4b4a..066b8d8 100644 --- a/crates/extensions/bswap.ll +++ b/crates/extensions/bswap.ll @@ -1,5 +1,7 @@ -target datalayout = "e-m:e-p:32:32-i64:64-n32-S128" -target triple = "riscv32-unknown-unknown-elf" +; target datalayout = "e-m:e-p:32:32-i64:64-n32-S128" +; target triple = "riscv32-unknown-unknown-elf" +target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128" +target triple = "riscv64-unknown-unknown-elf" define dso_local noundef i256 @__bswap(i256 noundef %0) local_unnamed_addr #0 { %2 = tail call i256 @llvm.bswap.i256(i256 %0) diff --git a/crates/integration/codesize.json b/crates/integration/codesize.json index ea47c6b..d0ace94 100644 --- a/crates/integration/codesize.json +++ b/crates/integration/codesize.json @@ -1,7 +1,7 @@ { - "Computation": 5912, - "ERC20": 33512, "Flipper": 3958, "Baseline": 3551, - "Fibonacci": 4909 + "Computation": 5912, + "Fibonacci": 4909, + "ERC20": 1966 } \ No newline at end of file diff --git a/crates/linker/src/lib.rs b/crates/linker/src/lib.rs index 5f47ba8..13b55c0 100644 --- a/crates/linker/src/lib.rs +++ b/crates/linker/src/lib.rs @@ -33,7 +33,7 @@ pub fn link>(input: T) -> anyhow::Result> { let output_path = dir.path().join("out.so"); let object_path = dir.path().join("out.o"); let linker_script_path = dir.path().join("linker.ld"); - let compiler_rt_path = dir.path().join("libclang_rt.builtins-riscv32.a"); + let compiler_rt_path = dir.path().join("libclang_rt.builtins-riscv64.a"); fs::write(&object_path, input).map_err(|msg| anyhow::anyhow!("{msg} {object_path:?}"))?; @@ -58,7 +58,7 @@ pub fn link>(input: T) -> anyhow::Result> { "--library-path", dir.path().to_str().expect("should be utf8"), "--library", - "clang_rt.builtins-riscv32", + "clang_rt.builtins-riscv64", linker_script_path.to_str().expect("should be utf8"), object_path.to_str().expect("should be utf8"), "-o", diff --git a/crates/llvm-context/src/target_machine/mod.rs b/crates/llvm-context/src/target_machine/mod.rs index 2ed67fb..5220539 100644 --- a/crates/llvm-context/src/target_machine/mod.rs +++ b/crates/llvm-context/src/target_machine/mod.rs @@ -24,10 +24,10 @@ pub struct TargetMachine { impl TargetMachine { /// The LLVM target name. - pub const VM_TARGET_NAME: &'static str = "riscv32"; + pub const VM_TARGET_NAME: &'static str = "riscv64"; /// The LLVM target triple. - pub const VM_TARGET_TRIPLE: &'static str = "riscv32-unknown-unknown-elf"; + pub const VM_TARGET_TRIPLE: &'static str = "riscv64-unknown-unknown-elf"; /// LLVM target features. #[cfg(feature = "riscv-zbb")] @@ -45,7 +45,7 @@ impl TargetMachine { .ok_or_else(|| anyhow::anyhow!("LLVM target machine `{}` not found", target.name()))? .create_target_machine( &inkwell::targets::TargetTriple::create(target.triple()), - "generic-rv32", + "generic-rv64", Self::VM_FEATURES, optimizer_settings.level_back_end, inkwell::targets::RelocMode::PIC, diff --git a/crates/llvm-context/src/target_machine/target.rs b/crates/llvm-context/src/target_machine/target.rs index fedc802..ff12146 100644 --- a/crates/llvm-context/src/target_machine/target.rs +++ b/crates/llvm-context/src/target_machine/target.rs @@ -19,7 +19,7 @@ impl Target { /// pub fn name(&self) -> &str { match self { - Self::PVM => "riscv32", + Self::PVM => "riscv64", } } @@ -28,7 +28,7 @@ impl Target { /// pub fn triple(&self) -> &str { match self { - Self::PVM => "riscv32-unknown-unknown-elf", + Self::PVM => "riscv64-unknown-unknown-elf", } } @@ -47,7 +47,7 @@ impl FromStr for Target { fn from_str(string: &str) -> Result { match string { - "riscv32" => Ok(Self::PVM), + "riscv64" => Ok(Self::PVM), _ => Err(anyhow::anyhow!( "Unknown target `{}`. Supported targets: {:?}", string, @@ -60,7 +60,7 @@ impl FromStr for Target { impl std::fmt::Display for Target { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Target::PVM => write!(f, "riscv32"), + Target::PVM => write!(f, "riscv64"), } } } diff --git a/crates/pallet-contracts-pvm-llapi/build.rs b/crates/pallet-contracts-pvm-llapi/build.rs index 110e7f0..5b4834c 100644 --- a/crates/pallet-contracts-pvm-llapi/build.rs +++ b/crates/pallet-contracts-pvm-llapi/build.rs @@ -3,11 +3,11 @@ use std::{env, fs, path::Path, process::Command}; fn compile(bitcode_path: &str) { let output = Command::new("clang") .args([ - "--target=riscv32", + "--target=riscv64", "-Xclang", - "-triple=riscv32-unknown-unknown-elf", - "-march=rv32em", - "-mabi=ilp32e", + "-triple=riscv64-unknown-unknown-elf", + "-march=rv64em", + "-mabi=lp64e", "-fno-exceptions", "-ffreestanding", "-Wall",