[PATCH] D117317: [MC] Put the pending fixups into relocation offset symbol's fragment

luxufan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 19 01:14:43 PST 2022


StephenFan updated this revision to Diff 401126.
StephenFan added a comment.

Add tests for FT_Dwarf and FT_PseudoProbe.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117317/new/

https://reviews.llvm.org/D117317

Files:
  llvm/lib/MC/MCObjectStreamer.cpp
  llvm/test/MC/RISCV/reloc-directive.s


Index: llvm/test/MC/RISCV/reloc-directive.s
===================================================================
--- llvm/test/MC/RISCV/reloc-directive.s
+++ llvm/test/MC/RISCV/reloc-directive.s
@@ -22,6 +22,19 @@
 # CHECK-NEXT: 0x0 R_RISCV_NONE - 0x9
 # CHECK-NEXT: 0x0 R_RISCV_32 - 0x9
 # CHECK-NEXT: 0x0 R_RISCV_64 - 0x9
+
+# CHECK: Section ({{.*}}) .rela.data {
+# CHECK-NEXT: 0x0 R_RISCV_32 - 0x6
+# CHECK-NEXT: }
+
+# CHECK: Section ({{.*}}) .rela.debug_line {
+# CHECK-NEXT: 0x0 R_RISCV_32 - 0x6
+# CHECK-NEXT: }
+
+# CHECK: Section ({{.*}}) .rela.pseudoprobe {
+# CHECK-NEXT: 0x0 R_RISCV_32 - 0x6
+# CHECK-NEXT: }
+
 .text
   ret
   nop
@@ -38,9 +51,21 @@
   .reloc 0, BFD_RELOC_32, 9
   .reloc 0, BFD_RELOC_64, 9
 
+  .reloc foo, R_RISCV_32, 6
+  .reloc line, R_RISCV_32, 6
+  .reloc probe, R_RISCV_32, 6
+
 .data
 .globl foo
 foo:
   .word 0
   .word 0
   .word 0
+
+.section    .debug_line,"", at progbits
+line:
+  .word 0
+
+.section    .pseudoprobe,"", at progbits
+probe:
+  .word 0
Index: llvm/lib/MC/MCObjectStreamer.cpp
===================================================================
--- llvm/lib/MC/MCObjectStreamer.cpp
+++ llvm/lib/MC/MCObjectStreamer.cpp
@@ -120,7 +120,29 @@
     }
     flushPendingLabels(PendingFixup.DF, PendingFixup.DF->getContents().size());
     PendingFixup.Fixup.setOffset(PendingFixup.Sym->getOffset());
-    PendingFixup.DF->getFixups().push_back(PendingFixup.Fixup);
+
+    // If the location symbol to relocate is in MCEncodedFragmentWithFixups,
+    // put the Fixup into location symbol's fragment. Otherwise
+    // put into PendingFixup.DF
+    MCFragment *SymFragment = PendingFixup.Sym->getFragment();
+    switch (SymFragment->getKind()) {
+    case MCFragment::FT_Relaxable:
+    case MCFragment::FT_Dwarf:
+    case MCFragment::FT_PseudoProbe:
+      cast<MCEncodedFragmentWithFixups<8, 1>>(SymFragment)
+          ->getFixups()
+          .push_back(PendingFixup.Fixup);
+      break;
+    case MCFragment::FT_Data:
+    case MCFragment::FT_CVDefRange:
+      cast<MCEncodedFragmentWithFixups<32, 4>>(SymFragment)
+          ->getFixups()
+          .push_back(PendingFixup.Fixup);
+      break;
+    default:
+      PendingFixup.DF->getFixups().push_back(PendingFixup.Fixup);
+      break;
+    }
   }
   PendingFixups.clear();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117317.401126.patch
Type: text/x-patch
Size: 2289 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220119/6fdac7b2/attachment-0001.bin>


More information about the llvm-commits mailing list