mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-21 11:31:02 +00:00
Prevent frontend function confusion (#383)
Function symbols can clash as we compile multiple YUL `object` definition into the same `LLVM` module. - Disambiguate via unique function symbols based its location (runtime or deploy code). - Use `LinkOnceODR` linkage for compiler builtin helpers. --------- Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
//! The deploy code function.
|
||||
|
||||
use crate::polkavm::context::code_type::CodeType;
|
||||
use crate::polkavm::context::function::runtime;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::WriteLLVM;
|
||||
@@ -38,16 +37,16 @@ where
|
||||
0,
|
||||
Some(inkwell::module::Linkage::Private),
|
||||
None,
|
||||
false,
|
||||
)?;
|
||||
|
||||
self.inner.declare(context)
|
||||
}
|
||||
|
||||
fn into_llvm(self, context: &mut Context) -> anyhow::Result<()> {
|
||||
context.set_current_function(runtime::FUNCTION_DEPLOY_CODE, None)?;
|
||||
context.set_current_function(runtime::FUNCTION_DEPLOY_CODE, None, false)?;
|
||||
|
||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||
context.set_code_type(CodeType::Deploy);
|
||||
|
||||
self.inner.into_llvm(context)?;
|
||||
context.set_debug_location(0, 0, None)?;
|
||||
|
||||
@@ -138,6 +138,7 @@ impl WriteLLVM for Entry {
|
||||
0,
|
||||
Some(inkwell::module::Linkage::External),
|
||||
None,
|
||||
false,
|
||||
)?;
|
||||
|
||||
context.declare_global(
|
||||
@@ -160,7 +161,7 @@ impl WriteLLVM for Entry {
|
||||
/// The `entry` function loads calldata, sets globals and calls the runtime or deploy code.
|
||||
fn into_llvm(self, context: &mut Context) -> anyhow::Result<()> {
|
||||
let entry = context
|
||||
.get_function(runtime::FUNCTION_ENTRY)
|
||||
.get_function(runtime::FUNCTION_ENTRY, false)
|
||||
.expect("the entry function should already be declared")
|
||||
.borrow()
|
||||
.declaration;
|
||||
@@ -171,7 +172,7 @@ impl WriteLLVM for Entry {
|
||||
true,
|
||||
);
|
||||
|
||||
context.set_current_function(runtime::FUNCTION_ENTRY, None)?;
|
||||
context.set_current_function(runtime::FUNCTION_ENTRY, None, false)?;
|
||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||
|
||||
Self::initialize_globals(context)?;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
//! The runtime code function.
|
||||
|
||||
use crate::polkavm::context::code_type::CodeType;
|
||||
use crate::polkavm::context::function::runtime;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::WriteLLVM;
|
||||
@@ -38,16 +37,16 @@ where
|
||||
0,
|
||||
Some(inkwell::module::Linkage::Private),
|
||||
None,
|
||||
false,
|
||||
)?;
|
||||
|
||||
self.inner.declare(context)
|
||||
}
|
||||
|
||||
fn into_llvm(self, context: &mut Context) -> anyhow::Result<()> {
|
||||
context.set_current_function(runtime::FUNCTION_RUNTIME_CODE, None)?;
|
||||
context.set_current_function(runtime::FUNCTION_RUNTIME_CODE, None, false)?;
|
||||
|
||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||
context.set_code_type(CodeType::Runtime);
|
||||
|
||||
self.inner.into_llvm(context)?;
|
||||
context.set_debug_location(0, 0, None)?;
|
||||
|
||||
Reference in New Issue
Block a user