[llvm-branch-commits] [llvm] [BOLT] Skip out-of-range pending relocations (PR #116964)

Maksim Panchenko via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Mar 27 13:51:16 PDT 2025


================
@@ -174,11 +175,31 @@ void BinarySection::flushPendingRelocations(raw_pwrite_stream &OS,
     OS.pwrite(Patch.Bytes.data(), Patch.Bytes.size(),
               SectionFileOffset + Patch.Offset);
 
+  uint64_t SkippedPendingRelocations = 0;
   for (Relocation &Reloc : PendingRelocations) {
     uint64_t Value = Reloc.Addend;
     if (Reloc.Symbol)
       Value += Resolver(Reloc.Symbol);
 
+    // Safely skip any optional pending relocation that cannot be encoded.
+    if (Reloc.isOptional() &&
+        !Relocation::canEncodeValue(Reloc.Type, Value,
+                                    SectionAddress + Reloc.Offset)) {
+
+      // A successful run of 'scanExternalRefs' means that all pending
+      // relocations are flushed. Otherwise, PatchEntries should run.
+      if (!opts::ForcePatch) {
+        BC.errs()
+            << "BOLT-ERROR: Cannot fully run scanExternalRefs as pending "
+               "relocation for symbol "
----------------
maksfb wrote:

Let's rephrase the message in a more user-oriented way, i.e. drop `scanExternalRefs()`.

https://github.com/llvm/llvm-project/pull/116964


More information about the llvm-branch-commits mailing list