Index: include/llvm/MC/MCObjectStreamer.h =================================================================== --- include/llvm/MC/MCObjectStreamer.h +++ include/llvm/MC/MCObjectStreamer.h @@ -82,9 +82,7 @@ /// If any labels have been emitted but not assigned fragments, ensure that /// they get assigned, either to F if possible or to a new data fragment. - /// Optionally, it is also possible to provide an offset \p FOffset, which - /// will be used as a symbol offset within the fragment. - void flushPendingLabels(MCFragment *F, uint64_t FOffset = 0); + void flushPendingLabels(MCFragment *F); public: void visitUsedSymbol(const MCSymbol &Sym) override; Index: lib/MC/MCELFStreamer.cpp =================================================================== --- lib/MC/MCELFStreamer.cpp +++ lib/MC/MCELFStreamer.cpp @@ -72,12 +72,18 @@ VecOS.flush(); delete OW; + // Push any symbols which are on the fragment boundary below the padding. + size_t Offset = DF->getContents().size(); + for (const MCSymbol &Symbol : Assembler.symbols()) { + MCSymbolData &SD = Symbol.getData(); + if (SD.getFragment() == DF && SD.getOffset() == Offset) { + SD.setOffset(SD.getOffset() + Code.size()); + } + } DF->getContents().append(Code.begin(), Code.end()); } } - flushPendingLabels(DF, DF->getContents().size()); - for (unsigned i = 0, e = EF->getFixups().size(); i != e; ++i) { EF->getFixups()[i].setOffset(EF->getFixups()[i].getOffset() + DF->getContents().size()); Index: lib/MC/MCObjectStreamer.cpp =================================================================== --- lib/MC/MCObjectStreamer.cpp +++ lib/MC/MCObjectStreamer.cpp @@ -38,7 +38,7 @@ delete Assembler; } -void MCObjectStreamer::flushPendingLabels(MCFragment *F, uint64_t FOffset) { +void MCObjectStreamer::flushPendingLabels(MCFragment *F) { if (PendingLabels.size()) { if (!F) { F = new MCDataFragment(); @@ -47,7 +47,6 @@ } for (MCSymbolData *SD : PendingLabels) { SD->setFragment(F); - SD->setOffset(FOffset); } PendingLabels.clear(); } @@ -168,9 +167,7 @@ // If there is a current fragment, mark the symbol as pointing into it. // Otherwise queue the label and set its fragment pointer when we emit the // next fragment. - auto *F = dyn_cast_or_null(getCurrentFragment()); - if (F && !(getAssembler().isBundlingEnabled() && - getAssembler().getRelaxAll())) { + if (auto *F = dyn_cast_or_null(getCurrentFragment())) { SD.setFragment(F); SD.setOffset(F->getContents().size()); } else {