-
Notifications
You must be signed in to change notification settings - Fork 34
Extend entrypoint generation to handle multi-module packages #374
Conversation
49797b2
to
40683a7
Compare
@@ -1,5 +1,5 @@ | |||
#[test_only] | |||
module std::fixed_point32_tests { | |||
module std::fp32_tests { | |||
use std::fixed_point32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change of name is to pass the 64 char limit on external symbol length imposed by the Solana VM.
40683a7
to
6dd52a5
Compare
6dd52a5
to
4e97d2d
Compare
// NB: context must outlive llvm module | ||
// fixme this should be handled with lifetimes | ||
// FIXME: this should be handled with lifetimes. | ||
// Context (global_cx) must outlive llvm module (entry_llmod). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brson's expertise is needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll give it a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed an issue with a potential fix for this #379
I don't think it should hold up this pr, as this pr is just continuing the existing pattern of manually managing the lifetime of the llvm mod.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwiw I also recall thinking that the original scheme for managing lifetimes of these contexts, with the 'mm
and 'up
lifetimes, is probably wrong, though I don't remember why. Anyway, that scheme appears to still be working for now.
* requested entry function to be passed in instruction_data byte | ||
* array. The logic in solana entrypoint iteratively compares the | ||
* string slice passed in instruction_data to every entry function | ||
* symbol of the module. Once a matching entry function is found, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a chance that the list of entry functions can have duplicates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or ODR takes care of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if two modules have the same name and they both contain entry functions with the same name, then yes there will be duplicates. We probably will include modules’ unique addresses in function names to avoid conflicts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it will help to assert that there are no two duplicates. at least in debug mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a debug_assert!()
to check for duplicate entry function names.
let level = record.level(); | ||
let mut style = formatter.style(); | ||
match record.level() { | ||
Level::Error => style.set_color(Color::Red), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! how do we test the logger?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably write tests checking the log messages. Is it worth the effort at the moment? I added this initializer for consistency with move-cli code path, as previously the logger was initialized when global context was created which is too late and wrong (https://github.com/jcivlin/move/blame/599dbfbecc6d8b8893ee9c683b402e740f1f9820/language/tools/move-mv-llvm-compiler/src/stackless/translate.rs#L121-L142). I mentioned previously, I'd like to decommission move-mv-llvm-compiler as it will never be used by the end users, it is only used for testing at the moment, and it is taking wasted efforts to maintain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary to write test for it atm. i'll just create an issue for this and move on. #377
9c35610
to
56f7cde
Compare
llvm_module: &'up llvm::Module, | ||
rtty_cx: &RttyContext, | ||
val: u64, | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and several other methods need to be used by EntrypointGenerator which has its own LLVM module that isn't included in an existing ModuleContext, therefore I tried to reuse the code by converting these methods to 'class'-level methods instead of 'instance'-level. Maybe some other refactoring is needed to have a better design and code reuse. I would appreciate suggestions how to improve this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as long as it is helping you make progress, i guess this is fine. Maybe we can just write a comment here (as TODO?) or have a task and move on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment.
test_signers: args.test_signers.clone(), | ||
..MoveToSolanaOptions::default() | ||
}; | ||
let entry_llmod = global_cx.llvm_cx.create_module("solana_entrypoint"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: i feel like we need a file with all these constants (e.g. solana_entrypoint) which can be reused. As in language/tools/move-mv-llvm-compiler/tests/rbpf-tests.rs where we have solana_entrypoint.o
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, although rbpf-tests.rs is exposed to too many internals of compiler at the moment. This specific string is supposed to be hidden in move-to-solana/lib.rs only, where it should be defined as a compile time constant, probably.
56f7cde
to
15116df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with all this assuming @ksolana's is satisfied.
Motivation
Current generation of entrypoint glue code works only for packages with entry functions defined in a single module. These changes move entrypoint glue code generation outside ModuleContext. The glue code is generated in a separate LLVM module, so that it can make calls to entry functions defined in any module of a package.
Test Plan
Added rbpf-tests test with entry functions in different modules.
Resolves #369