diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -407,14 +407,6 @@ NamedRegionTimer T("discoverStorage", "discover storage", TimerGroupName, TimerGroupDesc, opts::TimeRewrite); - // Stubs are harmful because RuntimeDyld may try to increase the size of - // sections accounting for stubs when we need those sections to match the - // same size seen in the input binary, in case this section is a copy - // of the original one seen in the binary. - BC->EFMM.reset(new ExecutableFileMemoryManager(*BC, /*AllowStubs*/ false)); - BC->EFMM->setNewSecPrefix(getNewSecPrefix()); - BC->EFMM->setOrgSecPrefix(getOrgSecPrefix()); - auto ELF64LEFile = dyn_cast(InputFile); const ELFFile &Obj = ELF64LEFile->getELFFile(); @@ -3180,6 +3172,14 @@ MCAsmLayout FinalLayout( static_cast(Streamer.get())->getAssembler()); + // Disable stubs because RuntimeDyld may try to increase the size of + // sections accounting for stubs. We need those sections to match the + // same size seen in the input binary, in case this section is a copy + // of the original one seen in the binary. + BC->EFMM.reset(new ExecutableFileMemoryManager(*BC, /*AllowStubs=*/false)); + BC->EFMM->setNewSecPrefix(getNewSecPrefix()); + BC->EFMM->setOrgSecPrefix(getOrgSecPrefix()); + RTDyld.reset(new decltype(RTDyld)::element_type(*BC->EFMM, Resolver)); RTDyld->setProcessAllSections(false); RTDyld->loadObject(*Obj);