diff --git a/CHANGELOG.md b/CHANGELOG.md index aa3cb80..6a1119d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ This is a development pre-release. Supported `polkadot-sdk` rev: `2509.0.0` +### Changed +- Instruct the LLVM backend and linker to `--relax` (may lead to smaller contract code size). + ## v0.5.0 This is a development pre-release. diff --git a/crates/integration/codesize.json b/crates/integration/codesize.json index 07bb015..84c4bfe 100644 --- a/crates/integration/codesize.json +++ b/crates/integration/codesize.json @@ -1,10 +1,10 @@ { - "Baseline": 914, - "Computation": 2295, - "DivisionArithmetics": 14496, - "ERC20": 17482, - "Events": 1674, - "FibonacciIterative": 1490, - "Flipper": 2086, - "SHA1": 8158 + "Baseline": 905, + "Computation": 2286, + "DivisionArithmetics": 14347, + "ERC20": 16929, + "Events": 1665, + "FibonacciIterative": 1447, + "Flipper": 2077, + "SHA1": 7721 } \ No newline at end of file diff --git a/crates/linker/src/elf.rs b/crates/linker/src/elf.rs index afa3e46..2862d93 100644 --- a/crates/linker/src/elf.rs +++ b/crates/linker/src/elf.rs @@ -78,7 +78,7 @@ SECTIONS { "--error-limit=0", "--relocatable", "--emit-relocs", - "--no-relax", + "--relax", "--unique", "--gc-sections", self.linker_script_path.to_str().expect("should be utf8"), diff --git a/crates/llvm-context/src/polkavm/context/global.rs b/crates/llvm-context/src/polkavm/context/global.rs index 315cbf6..f0cddb1 100644 --- a/crates/llvm-context/src/polkavm/context/global.rs +++ b/crates/llvm-context/src/polkavm/context/global.rs @@ -35,7 +35,7 @@ impl<'ctx> Global<'ctx> { .add_global(r#type, Some(address_space.into()), name); let global = Self { r#type, value }; - global.value.set_linkage(inkwell::module::Linkage::External); + global.value.set_linkage(inkwell::module::Linkage::Internal); global .value .set_visibility(inkwell::GlobalVisibility::Default); diff --git a/crates/llvm-context/src/polkavm/context/mod.rs b/crates/llvm-context/src/polkavm/context/mod.rs index 4cc8eb9..54f2306 100644 --- a/crates/llvm-context/src/polkavm/context/mod.rs +++ b/crates/llvm-context/src/polkavm/context/mod.rs @@ -134,7 +134,7 @@ impl<'ctx> Context<'ctx> { module .get_function(import) .unwrap_or_else(|| panic!("{import} import should be declared")) - .set_linkage(inkwell::module::Linkage::External); + .set_linkage(inkwell::module::Linkage::Internal); } } diff --git a/crates/llvm-context/src/target_machine/mod.rs b/crates/llvm-context/src/target_machine/mod.rs index 0200f19..3717d99 100644 --- a/crates/llvm-context/src/target_machine/mod.rs +++ b/crates/llvm-context/src/target_machine/mod.rs @@ -29,7 +29,7 @@ impl TargetMachine { /// LLVM target features. pub const VM_FEATURES: &'static str = - "+e,+m,+a,+c,+zbb,+auipc-addi-fusion,+ld-add-fusion,+lui-addi-fusion,+xtheadcondmov"; + "+e,+m,+a,+c,+zbb,+auipc-addi-fusion,+ld-add-fusion,+lui-addi-fusion,+xtheadcondmov,+relax"; /// A shortcut constructor. /// A separate instance for every optimization level is created. diff --git a/crates/yul/src/parser/statement/function_definition.rs b/crates/yul/src/parser/statement/function_definition.rs index 37c5033..5be29e7 100644 --- a/crates/yul/src/parser/statement/function_definition.rs +++ b/crates/yul/src/parser/statement/function_definition.rs @@ -215,7 +215,7 @@ impl PolkaVMWriteLLVM for FunctionDefinition { self.identifier.as_str(), function_type, self.result.len(), - Some(inkwell::module::Linkage::External), + Some(inkwell::module::Linkage::Internal), Some((self.location.line, self.location.column)), true, )?;