[PATCH] D76114: [MC] Recalculate fragment offsets after relaxation
Jian Cai via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 13 12:23:37 PDT 2020
jcai19 updated this revision to Diff 250274.
jcai19 added a comment.
Update tests based on comments.
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,15 @@
+# RUN: llvm-mc -filetype=obj -triple=i386 %s -o /dev/null
+
+.macro ALTERNATIVE newinstr
+ .skip 144f-143f,0x0
+ .pushsection .altinstr_replacement,"ax"
+143:
+ \newinstr
+144:
+ .popsection
+.endm
+
+ .section .entry.text, "ax"
+ ALTERNATIVE "jmp .Lint80_keep_stack"
+.Lint80_keep_stack:
+# CHECK-NOT: error: Assertion `OS.tell() - Start == Layout.getSectionAddressSize(Sec)' failed
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.250274.patch
Type: text/x-patch
Size: 1994 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200313/761ff190/attachment.bin>
More information about the llvm-commits
mailing list