Compile fewer trampolines with module linking (#2774)

Previously each module in a module-linking-using-module would compile
all the trampolines for all signatures for all modules. In forest-like
situations with lots of modules this would cause quite a few trampolines
to get compiled. The original intention was to have one global list of
trampolines for all modules in the module-linking graph that they could
all share. With the current design of module linking, however, the
intention is for modules to be relatively isolated from one another
which would make achieving this difficult.

In lieu of total sharing (which would be good for the global scope
anyway but we also don't do that right now) this commit implements an
alternative strategy where each module simply compiles its own
trampolines that it itself can reach. This should mean that
module-linking modules behave more similarly to standalone modules in
terms of trampoline duplication. If we ever do global trampoline
deduplication we can likely batch this all together into one, but for
now this should fix the performance issues seen in fuzzing.

Closes #2525
This commit is contained in:
Alex Crichton
2021-03-25 19:11:02 -05:00
committed by GitHub
parent 211731b876
commit 7d8931c517
4 changed files with 37 additions and 29 deletions

View File

@@ -257,7 +257,7 @@ pub struct ObjectBuilder<'a> {
module: &'a Module,
code_alignment: u64,
compilation: &'a CompiledFunctions,
trampolines: PrimaryMap<SignatureIndex, CompiledFunction>,
trampolines: Vec<(SignatureIndex, CompiledFunction)>,
dwarf_sections: Vec<DwarfSection>,
}
@@ -271,7 +271,7 @@ impl<'a> ObjectBuilder<'a> {
target,
module,
code_alignment: 1,
trampolines: PrimaryMap::new(),
trampolines: Vec::new(),
dwarf_sections: vec![],
compilation,
}
@@ -284,7 +284,7 @@ impl<'a> ObjectBuilder<'a> {
pub fn set_trampolines(
&mut self,
trampolines: PrimaryMap<SignatureIndex, CompiledFunction>,
trampolines: Vec<(SignatureIndex, CompiledFunction)>,
) -> &mut Self {
self.trampolines = trampolines;
self
@@ -359,7 +359,7 @@ impl<'a> ObjectBuilder<'a> {
}
let mut trampolines = Vec::new();
for (i, func) in self.trampolines.iter() {
let name = utils::trampoline_symbol_name(i).as_bytes().to_vec();
let name = utils::trampoline_symbol_name(*i).as_bytes().to_vec();
trampolines.push(append_func(name, func));
}
@@ -399,7 +399,7 @@ impl<'a> ObjectBuilder<'a> {
}
}
for (func, symbol) in self.trampolines.values().zip(trampolines) {
for ((_, func), symbol) in self.trampolines.iter().zip(trampolines) {
let (_, off) = obj.symbol_section_and_offset(symbol).unwrap();
for r in to_object_relocations(
func.relocations.iter(),