Author: Jian Cai Date: 2020-03-17T14:27:47-07:00 New Revision: 81c9639ebafc42f90f6e0b83ec01e70d86558e06
URL: https://github.com/llvm/llvm-project/commit/81c9639ebafc42f90f6e0b83ec01e70d86558e06 DIFF: https://github.com/llvm/llvm-project/commit/81c9639ebafc42f90f6e0b83ec01e70d86558e06.diff LOG: [MC] Recalculate fragment offsets after relaxation Summary: The current relaxation implementation is not correctly adjusting the size and offsets of fragements in one section based on changes in size of another if the layout order of the two happened to be such that the former was visited before the later. Therefore, we need to invalidate the fragments in all sections after each iteration of relaxation, and possibly further relax some of them in the next ieration. This fixes PR#45190. Reviewers: jyknight, MaskRay, annita.zhang, reames, skan Reviewed By: reames, skan Subscribers: llozano, manojgupta, nickdesaulniers, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D76114 Added: llvm/test/MC/X86/relax-offset.s Modified: llvm/lib/MC/MCAssembler.cpp Removed: ################################################################################ diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 83f0d62bac2a..97fb13bdb885 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -785,9 +785,15 @@ void MCAssembler::layout(MCAsmLayout &Layout) { } // Layout until everything fits. - while (layoutOnce(Layout)) + while (layoutOnce(Layout)) { if (getContext().hadError()) return; + // Size of fragments in one section can depend on the size of fragments in + // another. If any fragment has changed size, we have to re-layout (and + // as a result possibly further relax) all. + for (MCSection &Sec : *this) + Layout.invalidateFragmentsFrom(&*Sec.begin()); + } DEBUG_WITH_TYPE("mc-dump", { errs() << "assembler backend - post-relaxation\n--\n"; diff --git a/llvm/test/MC/X86/relax-offset.s b/llvm/test/MC/X86/relax-offset.s new file mode 100644 index 000000000000..78de255e9d6f --- /dev/null +++ b/llvm/test/MC/X86/relax-offset.s @@ -0,0 +1,13 @@ +# RUN: llvm-mc -filetype=obj -triple=i386 %s | llvm-objdump - --headers | FileCheck %s + + # CHECK: .text1 00000005 00000000 + # CHECK: .text2 00000005 00000000 + + .section .text1 + .skip after-before,0x0 +.Lint80_keep_stack: + + .section .text2 +before: + jmp .Lint80_keep_stack +after: _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits