[PATCH] D76114: [MC] Recalculate fragment offsets after relaxation

Jian Cai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 13 15:40:42 PDT 2020


jcai19 updated this revision to Diff 250316.
jcai19 added a comment.

Update test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76114

Files:
  llvm/lib/MC/MCAssembler.cpp
  llvm/test/MC/X86/relax-offset.s


Index: llvm/test/MC/X86/relax-offset.s
===================================================================
--- /dev/null
+++ llvm/test/MC/X86/relax-offset.s
@@ -0,0 +1,11 @@
+# RUN: llvm-mc -filetype=obj -triple=i386 %s -o /dev/null
+
+.section .entry.text, "ax"
+.skip 144f-143f,0x0
+.pushsection .altinstr_replacement,"ax"
+143:
+jmp .Lint80_keep_stack
+144:
+.popsection
+
+.Lint80_keep_stack:
Index: llvm/lib/MC/MCAssembler.cpp
===================================================================
--- llvm/lib/MC/MCAssembler.cpp
+++ llvm/lib/MC/MCAssembler.cpp
@@ -389,14 +389,15 @@
 void MCAsmLayout::layoutFragment(MCFragment *F) {
   MCFragment *Prev = F->getPrevNode();
 
-  // We should never try to recompute something which is valid.
-  assert(!isFragmentValid(F) && "Attempt to recompute a valid fragment!");
   // We should never try to compute the fragment layout if its predecessor
   // isn't valid.
   assert((!Prev || isFragmentValid(Prev)) &&
          "Attempt to compute fragment before its predecessor!");
 
-  ++stats::FragmentLayouts;
+  // We may need to recompute the offset of valid framents if relaxation changes
+  // the offset of some fragments. PR#45190
+  if (!isFragmentValid(F))
+    ++stats::FragmentLayouts;
 
   // Compute fragment offset and size.
   if (Prev)
@@ -785,9 +786,18 @@
   }
 
   // Layout until everything fits.
-  while (layoutOnce(Layout))
+  bool WasRelaxed = false;
+  while (layoutOnce(Layout)) {
     if (getContext().hadError())
       return;
+    WasRelaxed = true;
+  }
+  // recalculate the offsets of fragments if relaxation happens. PR#45190
+  if (WasRelaxed) {
+    for (MCSection &Sec : *this)
+      for (MCFragment &F : Sec)
+        Layout.layoutFragment(&F);
+  }
 
   DEBUG_WITH_TYPE("mc-dump", {
       errs() << "assembler backend - post-relaxation\n--\n";


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76114.250316.patch
Type: text/x-patch
Size: 1831 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200313/11e870b3/attachment.bin>


More information about the llvm-commits mailing list