File tree Expand file tree Collapse file tree 6 files changed +34
-3
lines changed Expand file tree Collapse file tree 6 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ class MetadataManager {
3636 // / Execute metadata initializers after CFG was constructed for functions.
3737 void runInitializersPostCFG ();
3838
39+ // / Run finalization step of rewriters before the binary is emitted.
40+ void runFinalizersPreEmit ();
41+
3942 // / Run finalization step of rewriters after code has been emitted.
4043 void runFinalizersAfterEmit ();
4144};
Original file line number Diff line number Diff line change @@ -52,6 +52,9 @@ class MetadataRewriter {
5252 // / Run the rewriter once the functions are in CFG state.
5353 virtual Error postCFGInitializer () { return Error::success (); }
5454
55+ // / Run the pass before the binary is emitted.
56+ virtual Error preEmitFinalizer () { return Error::success (); }
57+
5558 // / Finalize section contents based on the new context after the new code is
5659 // / emitted.
5760 virtual Error postEmitFinalizer () { return Error::success (); }
Original file line number Diff line number Diff line change @@ -183,6 +183,9 @@ class RewriteInstance {
183183 // / Process metadata in special sections after CFG is built for functions.
184184 void processMetadataPostCFG ();
185185
186+ // / Make changes to metadata before the binary is emitted.
187+ void finalizeMetadataPreEmit ();
188+
186189 // / Update debug and other auxiliary information in the file.
187190 void updateMetadata ();
188191
Original file line number Diff line number Diff line change @@ -163,14 +163,18 @@ class LinuxKernelRewriter final : public MetadataRewriter {
163163 return Error::success ();
164164 }
165165
166- Error postEmitFinalizer () override {
167- updateLKMarkers ();
168-
166+ Error preEmitFinalizer () override {
169167 if (Error E = rewriteORCTables ())
170168 return E;
171169
172170 return Error::success ();
173171 }
172+
173+ Error postEmitFinalizer () override {
174+ updateLKMarkers ();
175+
176+ return Error::success ();
177+ }
174178};
175179
176180Error LinuxKernelRewriter::markInstructions () {
Original file line number Diff line number Diff line change @@ -44,6 +44,18 @@ void MetadataManager::runInitializersPostCFG() {
4444 }
4545}
4646
47+ void MetadataManager::runFinalizersPreEmit () {
48+ for (auto &Rewriter : Rewriters) {
49+ LLVM_DEBUG (dbgs () << " BOLT-DEBUG: invoking " << Rewriter->getName ()
50+ << " before emitting binary context\n " );
51+ if (Error E = Rewriter->preEmitFinalizer ()) {
52+ errs () << " BOLT-ERROR: while running " << Rewriter->getName ()
53+ << " before emit: " << toString (std::move (E)) << ' \n ' ;
54+ exit (1 );
55+ }
56+ }
57+ }
58+
4759void MetadataManager::runFinalizersAfterEmit () {
4860 for (auto &Rewriter : Rewriters) {
4961 LLVM_DEBUG (dbgs () << " BOLT-DEBUG: invoking " << Rewriter->getName ()
Original file line number Diff line number Diff line change @@ -742,6 +742,8 @@ Error RewriteInstance::run() {
742742
743743 runOptimizationPasses ();
744744
745+ finalizeMetadataPreEmit ();
746+
745747 emitAndLink ();
746748
747749 updateMetadata ();
@@ -3416,6 +3418,10 @@ void RewriteInstance::emitAndLink() {
34163418 }
34173419}
34183420
3421+ void RewriteInstance::finalizeMetadataPreEmit () {
3422+ MetadataManager.runFinalizersPreEmit ();
3423+ }
3424+
34193425void RewriteInstance::updateMetadata () {
34203426 MetadataManager.runFinalizersAfterEmit ();
34213427
You can’t perform that action at this time.
0 commit comments