[llvm] e17bc02 - [MC] flushPendingLabels: set Atom for new fragment after D71368

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 18 17:49:58 PDT 2023


Author: Fangrui Song
Date: 2023-06-18T17:49:53-07:00
New Revision: e17bc023f4e5b79f08bfc7f624f8ff0f0cf17ce4

URL: https://github.com/llvm/llvm-project/commit/e17bc023f4e5b79f08bfc7f624f8ff0f0cf17ce4
DIFF: https://github.com/llvm/llvm-project/commit/e17bc023f4e5b79f08bfc7f624f8ff0f0cf17ce4.diff

LOG: [MC] flushPendingLabels: set Atom for new fragment after D71368

Fixes: c26c5e47ab9ca60835f191c90fa751e9a7dd0f3d (essentially a no-op)

The newly created MCDataFragment should inherit Atom (see
MCMachOStreamer::finishImpl). To the best of my knowledge, this change cannot be
tested at present, but this is important to ensure
MCExpr.cpp:AttemptToFoldSymbolOffsetDifference gives the same result in case we
evaluate the expression again with a MCAsmLayout.

In the following case,
```
.section __DATA,xray_instr_map
lxray_sleds_start1:
.space 16
Lxray_sleds_end1:
.section __DATA,xray_fn_idx
.quad (Lxray_sleds_end1-lxray_sleds_start1)>>4 // can be folded without a MCAsmLayout
```

When we have a MCAsmLayout, without this change, evaluating
(Lxray_sleds_end1-lxray_sleds_start1)>>4 again will fail due to
`FA->getAtom() == nullptr && FB.getAtom() != nullptr` in
MachObjectWriter::isSymbolRefDifferenceFullyResolvedImpl, called by
AttemptToFoldSymbolOffsetDifference.

Added: 
    

Modified: 
    llvm/lib/MC/MCSection.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCSection.cpp b/llvm/lib/MC/MCSection.cpp
index 9b784a65e755a..0fb9e8e13910f 100644
--- a/llvm/lib/MC/MCSection.cpp
+++ b/llvm/lib/MC/MCSection.cpp
@@ -113,11 +113,13 @@ void MCSection::flushPendingLabels() {
     PendingLabel& Label = PendingLabels[0];
     iterator CurInsertionPoint =
       this->getSubsectionInsertionPoint(Label.Subsection);
+    const MCSymbol *Atom = nullptr;
+    if (CurInsertionPoint != begin())
+      Atom = std::prev(CurInsertionPoint)->getAtom();
     MCFragment *F = new MCDataFragment();
     getFragmentList().insert(CurInsertionPoint, F);
     F->setParent(this);
-    if (CurInsertionPoint != begin())
-      F->setAtom(std::prev(CurInsertionPoint)->getAtom());
+    F->setAtom(Atom);
     flushPendingLabels(F, 0, Label.Subsection);
   }
 }


        


More information about the llvm-commits mailing list