Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Extend entrypoint generation to handle multi-module packages #374

Merged
merged 1 commit into from
Sep 21, 2023
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
2 changes: 1 addition & 1 deletion language/move-stdlib/tests/fixedpoint32_tests.move
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[test_only]
module std::fixed_point32_tests {
module std::fp32_tests {
use std::fixed_point32;
Copy link
Collaborator Author

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.


#[test]
Expand Down
17 changes: 14 additions & 3 deletions language/solana/move-to-solana/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ fn compile(global_env: &GlobalEnv, options: &Options) -> anyhow::Result<()> {
.or_else(|err| anyhow::bail!("Error creating directory: {}", err))?;
}
let mut objects = vec![];
let entry_llmod = global_cx.llvm_cx.create_module("solana_entrypoint");
let entrypoint_generator =
EntrypointGenerator::new(&global_cx, &entry_llmod, &llmachine, options);
for mod_id in global_env
.get_modules()
.collect::<Vec<_>>()
Expand All @@ -401,12 +404,15 @@ fn compile(global_env: &GlobalEnv, options: &Options) -> anyhow::Result<()> {
let modname = module.llvm_module_name();
debug!("Generating code for module {}", modname);
let llmod = global_cx.llvm_cx.create_module(&modname);
let mod_cx = global_cx.create_module_context(mod_id, &llmod, options);
let mod_cx =
global_cx.create_module_context(mod_id, &llmod, &entrypoint_generator, options);
mod_cx.translate();

let mut out_path = out_path.join(&modname);
out_path.set_extension(&options.output_file_extension);
let mut output_file = out_path.to_str().unwrap().to_string();
// llmod is moved and dropped in both branches of this
// if-then-else when the module is written to a file.
if options.llvm_ir {
output_file = options.output.clone();
let path = Path::new(&output_file);
Expand Down Expand Up @@ -435,15 +441,20 @@ fn compile(global_env: &GlobalEnv, options: &Options) -> anyhow::Result<()> {
}
}
if !(options.compile || options.llvm_ir) {
if entrypoint_generator.has_entries() {
let output_file = entrypoint_generator.write_object_file(&out_path).unwrap();
objects.push(Path::new(&output_file).to_path_buf());
}
link_object_files(
out_path,
objects.as_slice(),
Path::new(&output_file_path).to_path_buf(),
&options.move_native_archive,
)?;
}
// 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).
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Collaborator

@brson brson Sep 20, 2023

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.

Copy link
Collaborator

@brson brson Sep 20, 2023

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.

drop(entry_llmod);
drop(global_cx);
Ok(())
}
Expand Down
Loading