[PATCH] D154501: [JITLink][RISCV] Move relax to PostAllocationPasses

Job Noorman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 5 05:27:57 PDT 2023


jobnoorman created this revision.
jobnoorman added reviewers: lhames, StephenFan.
Herald added subscribers: asb, luke, pmatos, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
jobnoorman requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, eopXD.
Herald added a project: LLVM.

`JITLinkContext` is notified (using `notifyResolved`) of the final
symbol addresses after allocating memory and running the post-allocation
passes. However, linker relaxation, which can cause symbol addresses to
change, was run during the pre-fixup passes. This causes users of
JITLink (e.g., ORC) to pick-up wrong symbol addresses when linker
relaxation was enabled.

This patch fixes this by running relaxation during the post-allocation
passes.

Fixes #63671

@lhames: afaict, `llvm-jitlink` gathers symbol values during a custom
post-fixup pass [1]. Therefore, it isn't affected by this bug and I'm
not quite sure how to add a test for it. Any suggestions?

[1] https://github.com/llvm/llvm-project/blob/3003da71540bb8483615e18f8ab379da39fa4512/llvm/tools/llvm-jitlink/llvm-jitlink.cpp#L1080-L1082


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154501

Files:
  llvm/include/llvm/ExecutionEngine/JITLink/ELF_riscv.h
  llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp


Index: llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
===================================================================
--- llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
+++ llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
@@ -967,7 +967,7 @@
       Config.PrePrunePasses.push_back(markAllSymbolsLive);
     Config.PostPrunePasses.push_back(
         PerGraphGOTAndPLTStubsBuilder_ELF_riscv::asPass);
-    Config.PreFixupPasses.push_back(relax);
+    Config.PostAllocationPasses.push_back(relax);
   }
   if (auto Err = Ctx->modifyPassConfig(*G, Config))
     return Ctx->notifyFailed(std::move(Err));
Index: llvm/include/llvm/ExecutionEngine/JITLink/ELF_riscv.h
===================================================================
--- llvm/include/llvm/ExecutionEngine/JITLink/ELF_riscv.h
+++ llvm/include/llvm/ExecutionEngine/JITLink/ELF_riscv.h
@@ -33,7 +33,7 @@
                     std::unique_ptr<JITLinkContext> Ctx);
 
 /// Returns a pass that performs linker relaxation. Should be added to
-/// PreFixupPasses.
+/// PostAllocationPasses.
 LinkGraphPassFunction createRelaxationPass_ELF_riscv();
 
 } // end namespace jitlink


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154501.537311.patch
Type: text/x-patch
Size: 1134 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230705/0cc9e950/attachment.bin>


More information about the llvm-commits mailing list