-
Notifications
You must be signed in to change notification settings - Fork 32
Extend entrypoint generation to handle multi-module packages #374
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
|
||
#[test] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<_>>() | ||
|
@@ -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); | ||
|
@@ -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). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 |
||
drop(entry_llmod); | ||
drop(global_cx); | ||
Ok(()) | ||
} | ||
|
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.