2010-06-17 04:04:22 +08:00
|
|
|
//===- lib/MC/MCObjectStreamer.cpp - Object File MCStreamer Interface -----===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-17 04:04:22 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/MC/MCObjectStreamer.h"
|
2013-04-18 05:18:16 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2012-03-26 14:58:25 +08:00
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
2010-06-17 04:04:22 +08:00
|
|
|
#include "llvm/MC/MCAssembler.h"
|
2010-07-30 01:48:06 +08:00
|
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
2016-08-27 01:58:37 +08:00
|
|
|
#include "llvm/MC/MCCodeView.h"
|
2010-12-10 15:39:47 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2010-11-02 00:27:31 +08:00
|
|
|
#include "llvm/MC/MCDwarf.h"
|
2010-07-19 14:13:10 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2012-03-26 14:58:25 +08:00
|
|
|
#include "llvm/MC/MCObjectWriter.h"
|
2013-06-27 22:35:03 +08:00
|
|
|
#include "llvm/MC/MCSection.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2012-03-26 14:58:25 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2016-05-28 13:57:48 +08:00
|
|
|
#include "llvm/Support/SourceMgr.h"
|
2010-06-17 04:04:22 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2017-10-11 09:57:21 +08:00
|
|
|
MCObjectStreamer::MCObjectStreamer(MCContext &Context,
|
|
|
|
std::unique_ptr<MCAsmBackend> TAB,
|
2018-05-19 02:26:45 +08:00
|
|
|
std::unique_ptr<MCObjectWriter> OW,
|
2017-10-12 07:34:47 +08:00
|
|
|
std::unique_ptr<MCCodeEmitter> Emitter)
|
2018-04-27 23:45:27 +08:00
|
|
|
: MCStreamer(Context),
|
2019-08-15 23:54:37 +08:00
|
|
|
Assembler(std::make_unique<MCAssembler>(
|
2018-05-19 02:26:45 +08:00
|
|
|
Context, std::move(TAB), std::move(Emitter), std::move(OW))),
|
2020-01-09 01:58:42 +08:00
|
|
|
EmitEHFrame(true), EmitDebugFrame(false) {
|
|
|
|
if (Assembler->getBackendPtr())
|
|
|
|
setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());
|
|
|
|
}
|
2010-06-17 04:04:22 +08:00
|
|
|
|
2017-10-12 07:34:47 +08:00
|
|
|
MCObjectStreamer::~MCObjectStreamer() {}
|
2010-06-17 04:04:25 +08:00
|
|
|
|
[MC] Change AsmParser to leverage Assembler during evaluation
Teach AsmParser to check with Assembler for when evaluating constant
expressions. This improves the handing of preprocessor expressions
that must be resolved at parse time. This idiom can be found as
assembling-time assertion checks in source-level assemblers. Note that
this relies on the MCStreamer to keep sufficient tabs on Section /
Fragment information which the MCAsmStreamer does not. As a result the
textual output may fail where the equivalent object generation would
pass. This can most easily be resolved by folding the MCAsmStreamer
and MCObjectStreamer together which is planned for in a separate
patch.
Currently, this feature is only enabled for assembly input, keeping IR
compilation consistent between assembly and object generation.
Reviewers: echristo, rnk, probinson, espindola, peter.smith
Reviewed By: peter.smith
Subscribers: eraman, peter.smith, arichardson, jyknight, hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D45164
llvm-svn: 331218
2018-05-01 03:22:40 +08:00
|
|
|
// AssemblerPtr is used for evaluation of expressions and causes
|
|
|
|
// difference between asm and object outputs. Return nullptr to in
|
|
|
|
// inline asm mode to limit divergence to assembly inputs.
|
|
|
|
MCAssembler *MCObjectStreamer::getAssemblerPtr() {
|
|
|
|
if (getUseAssemblerInfoForParsing())
|
|
|
|
return Assembler.get();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
[ MC ] Match labels to existing fragments even when switching sections.
(This commit restores the original branch (4272372c571) and applies an
additional change dropped from the original in a bad merge. This change
should address the previous bot failures. Both changes reviewed by pete.)
Summary:
This commit builds upon Derek Schuff's 2014 commit for attaching labels to
existing fragments ( Diff Revision: http://reviews.llvm.org/D5915 )
When temporary labels appear ahead of a fragment, MCObjectStreamer will
track the temporary label symbol in a "Pending Labels" list. Labels are
associated with fragments when a real fragment arrives; otherwise, an empty
data fragment will be created if the streamer's section changes or if the
stream finishes.
This commit moves the "Pending Labels" list into each MCStream, so that
this label-fragment matching process is resilient to section changes. If
the streamer emits a label in a new section, switches to another section to
do other work, then switches back to the first section and emits a
fragment, that initial label will be associated with this new fragment.
Labels will only receive empty data fragments in the case where no other
fragment exists for that section.
The downstream effects of this can be seen in Mach-O relocations. The
previous approach could produce local section relocations and external
symbol relocations for the same data in an object file, and this mix of
relocation types resulted in problems in the ld64 Mach-O linker. This
commit ensures relocations triggered by temporary labels are consistent.
Reviewers: pete, ab, dschuff
Reviewed By: pete, dschuff
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71368
2019-12-12 02:42:37 +08:00
|
|
|
void MCObjectStreamer::addPendingLabel(MCSymbol* S) {
|
|
|
|
MCSection *CurSection = getCurrentSectionOnly();
|
|
|
|
if (CurSection) {
|
|
|
|
// Register labels that have not yet been assigned to a Section.
|
|
|
|
if (!PendingLabels.empty()) {
|
|
|
|
for (MCSymbol* Sym : PendingLabels)
|
|
|
|
CurSection->addPendingLabel(Sym);
|
|
|
|
PendingLabels.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add this label to the current Section / Subsection.
|
|
|
|
CurSection->addPendingLabel(S, CurSubsectionIdx);
|
|
|
|
|
|
|
|
// Add this Section to the list of PendingLabelSections.
|
2020-04-26 22:39:30 +08:00
|
|
|
PendingLabelSections.insert(CurSection);
|
|
|
|
} else
|
[ MC ] Match labels to existing fragments even when switching sections.
(This commit restores the original branch (4272372c571) and applies an
additional change dropped from the original in a bad merge. This change
should address the previous bot failures. Both changes reviewed by pete.)
Summary:
This commit builds upon Derek Schuff's 2014 commit for attaching labels to
existing fragments ( Diff Revision: http://reviews.llvm.org/D5915 )
When temporary labels appear ahead of a fragment, MCObjectStreamer will
track the temporary label symbol in a "Pending Labels" list. Labels are
associated with fragments when a real fragment arrives; otherwise, an empty
data fragment will be created if the streamer's section changes or if the
stream finishes.
This commit moves the "Pending Labels" list into each MCStream, so that
this label-fragment matching process is resilient to section changes. If
the streamer emits a label in a new section, switches to another section to
do other work, then switches back to the first section and emits a
fragment, that initial label will be associated with this new fragment.
Labels will only receive empty data fragments in the case where no other
fragment exists for that section.
The downstream effects of this can be seen in Mach-O relocations. The
previous approach could produce local section relocations and external
symbol relocations for the same data in an object file, and this mix of
relocation types resulted in problems in the ld64 Mach-O linker. This
commit ensures relocations triggered by temporary labels are consistent.
Reviewers: pete, ab, dschuff
Reviewed By: pete, dschuff
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71368
2019-12-12 02:42:37 +08:00
|
|
|
// There is no Section / Subsection for this label yet.
|
|
|
|
PendingLabels.push_back(S);
|
|
|
|
}
|
|
|
|
|
2015-04-13 07:42:25 +08:00
|
|
|
void MCObjectStreamer::flushPendingLabels(MCFragment *F, uint64_t FOffset) {
|
[ MC ] Match labels to existing fragments even when switching sections.
(This commit restores the original branch (4272372c571) and applies an
additional change dropped from the original in a bad merge. This change
should address the previous bot failures. Both changes reviewed by pete.)
Summary:
This commit builds upon Derek Schuff's 2014 commit for attaching labels to
existing fragments ( Diff Revision: http://reviews.llvm.org/D5915 )
When temporary labels appear ahead of a fragment, MCObjectStreamer will
track the temporary label symbol in a "Pending Labels" list. Labels are
associated with fragments when a real fragment arrives; otherwise, an empty
data fragment will be created if the streamer's section changes or if the
stream finishes.
This commit moves the "Pending Labels" list into each MCStream, so that
this label-fragment matching process is resilient to section changes. If
the streamer emits a label in a new section, switches to another section to
do other work, then switches back to the first section and emits a
fragment, that initial label will be associated with this new fragment.
Labels will only receive empty data fragments in the case where no other
fragment exists for that section.
The downstream effects of this can be seen in Mach-O relocations. The
previous approach could produce local section relocations and external
symbol relocations for the same data in an object file, and this mix of
relocation types resulted in problems in the ld64 Mach-O linker. This
commit ensures relocations triggered by temporary labels are consistent.
Reviewers: pete, ab, dschuff
Reviewed By: pete, dschuff
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71368
2019-12-12 02:42:37 +08:00
|
|
|
MCSection *CurSection = getCurrentSectionOnly();
|
|
|
|
if (!CurSection) {
|
|
|
|
assert(PendingLabels.empty());
|
2015-10-03 08:57:12 +08:00
|
|
|
return;
|
[ MC ] Match labels to existing fragments even when switching sections.
Summary:
This commit builds upon Derek Schuff's 2014 commit for attaching labels to
existing fragments ( Diff Revision: http://reviews.llvm.org/D5915 )
When temporary labels appear ahead of a fragment, MCObjectStreamer will
track the temporary label symbol in a "Pending Labels" list. Labels are
associated with fragments when a real fragment arrives; otherwise, an empty
data fragment will be created if the streamer's section changes or if the
stream finishes.
This commit moves the "Pending Labels" list into each MCStream, so that
this label-fragment matching process is resilient to section changes. If
the streamer emits a label in a new section, switches to another section to
do other work, then switches back to the first section and emits a
fragment, that initial label will be associated with this new fragment.
Labels will only receive empty data fragments in the case where no other
fragment exists for that section.
The downstream effects of this can be seen in Mach-O relocations. The
previous approach could produce local section relocations and external
symbol relocations for the same data in an object file, and this mix of
relocation types resulted in problems in the ld64 Mach-O linker. This
commit ensures relocations triggered by temporary labels are consistent.
Reviewers: pete, ab, dschuff
Reviewed By: pete, dschuff
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71368
2019-12-12 02:42:37 +08:00
|
|
|
}
|
[ MC ] Match labels to existing fragments even when switching sections.
(This commit restores the original branch (4272372c571) and applies an
additional change dropped from the original in a bad merge. This change
should address the previous bot failures. Both changes reviewed by pete.)
Summary:
This commit builds upon Derek Schuff's 2014 commit for attaching labels to
existing fragments ( Diff Revision: http://reviews.llvm.org/D5915 )
When temporary labels appear ahead of a fragment, MCObjectStreamer will
track the temporary label symbol in a "Pending Labels" list. Labels are
associated with fragments when a real fragment arrives; otherwise, an empty
data fragment will be created if the streamer's section changes or if the
stream finishes.
This commit moves the "Pending Labels" list into each MCStream, so that
this label-fragment matching process is resilient to section changes. If
the streamer emits a label in a new section, switches to another section to
do other work, then switches back to the first section and emits a
fragment, that initial label will be associated with this new fragment.
Labels will only receive empty data fragments in the case where no other
fragment exists for that section.
The downstream effects of this can be seen in Mach-O relocations. The
previous approach could produce local section relocations and external
symbol relocations for the same data in an object file, and this mix of
relocation types resulted in problems in the ld64 Mach-O linker. This
commit ensures relocations triggered by temporary labels are consistent.
Reviewers: pete, ab, dschuff
Reviewed By: pete, dschuff
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71368
2019-12-12 02:42:37 +08:00
|
|
|
// Register labels that have not yet been assigned to a Section.
|
|
|
|
if (!PendingLabels.empty()) {
|
|
|
|
for (MCSymbol* Sym : PendingLabels)
|
|
|
|
CurSection->addPendingLabel(Sym, CurSubsectionIdx);
|
|
|
|
PendingLabels.clear();
|
2019-12-18 07:03:10 +08:00
|
|
|
}
|
[ MC ] Match labels to existing fragments even when switching sections.
(This commit restores the original branch (4272372c571) and applies an
additional change dropped from the original in a bad merge. This change
should address the previous bot failures. Both changes reviewed by pete.)
Summary:
This commit builds upon Derek Schuff's 2014 commit for attaching labels to
existing fragments ( Diff Revision: http://reviews.llvm.org/D5915 )
When temporary labels appear ahead of a fragment, MCObjectStreamer will
track the temporary label symbol in a "Pending Labels" list. Labels are
associated with fragments when a real fragment arrives; otherwise, an empty
data fragment will be created if the streamer's section changes or if the
stream finishes.
This commit moves the "Pending Labels" list into each MCStream, so that
this label-fragment matching process is resilient to section changes. If
the streamer emits a label in a new section, switches to another section to
do other work, then switches back to the first section and emits a
fragment, that initial label will be associated with this new fragment.
Labels will only receive empty data fragments in the case where no other
fragment exists for that section.
The downstream effects of this can be seen in Mach-O relocations. The
previous approach could produce local section relocations and external
symbol relocations for the same data in an object file, and this mix of
relocation types resulted in problems in the ld64 Mach-O linker. This
commit ensures relocations triggered by temporary labels are consistent.
Reviewers: pete, ab, dschuff
Reviewed By: pete, dschuff
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71368
2019-12-12 02:42:37 +08:00
|
|
|
|
|
|
|
// Associate a fragment with this label, either the supplied fragment
|
|
|
|
// or an empty data fragment.
|
|
|
|
if (F)
|
|
|
|
CurSection->flushPendingLabels(F, FOffset, CurSubsectionIdx);
|
|
|
|
else
|
|
|
|
CurSection->flushPendingLabels(nullptr, 0, CurSubsectionIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCObjectStreamer::flushPendingLabels() {
|
|
|
|
// Register labels that have not yet been assigned to a Section.
|
|
|
|
if (!PendingLabels.empty()) {
|
|
|
|
MCSection *CurSection = getCurrentSectionOnly();
|
|
|
|
assert(CurSection);
|
|
|
|
for (MCSymbol* Sym : PendingLabels)
|
|
|
|
CurSection->addPendingLabel(Sym, CurSubsectionIdx);
|
|
|
|
PendingLabels.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assign an empty data fragment to all remaining pending labels.
|
|
|
|
for (MCSection* Section : PendingLabelSections)
|
|
|
|
Section->flushPendingLabels();
|
2014-10-23 06:38:06 +08:00
|
|
|
}
|
|
|
|
|
2018-11-22 00:28:39 +08:00
|
|
|
// When fixup's offset is a forward declared label, e.g.:
|
|
|
|
//
|
|
|
|
// .reloc 1f, R_MIPS_JALR, foo
|
|
|
|
// 1: nop
|
|
|
|
//
|
|
|
|
// postpone adding it to Fixups vector until the label is defined and its offset
|
|
|
|
// is known.
|
|
|
|
void MCObjectStreamer::resolvePendingFixups() {
|
|
|
|
for (PendingMCFixup &PendingFixup : PendingFixups) {
|
|
|
|
if (!PendingFixup.Sym || PendingFixup.Sym->isUndefined ()) {
|
|
|
|
getContext().reportError(PendingFixup.Fixup.getLoc(),
|
|
|
|
"unresolved relocation offset");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
flushPendingLabels(PendingFixup.DF, PendingFixup.DF->getContents().size());
|
|
|
|
PendingFixup.Fixup.setOffset(PendingFixup.Sym->getOffset());
|
|
|
|
PendingFixup.DF->getFixups().push_back(PendingFixup.Fixup);
|
|
|
|
}
|
|
|
|
PendingFixups.clear();
|
|
|
|
}
|
|
|
|
|
2018-02-10 01:00:25 +08:00
|
|
|
// As a compile-time optimization, avoid allocating and evaluating an MCExpr
|
|
|
|
// tree for (Hi - Lo) when Hi and Lo are offsets into the same fragment.
|
2018-08-16 19:26:37 +08:00
|
|
|
static Optional<uint64_t>
|
|
|
|
absoluteSymbolDiff(MCAssembler &Asm, const MCSymbol *Hi, const MCSymbol *Lo) {
|
2018-03-16 05:24:04 +08:00
|
|
|
assert(Hi && Lo);
|
2018-08-16 19:26:37 +08:00
|
|
|
if (Asm.getBackendPtr()->requiresDiffExpressionRelocations())
|
|
|
|
return None;
|
|
|
|
|
2018-02-10 01:00:25 +08:00
|
|
|
if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment() ||
|
|
|
|
Hi->isVariable() || Lo->isVariable())
|
|
|
|
return None;
|
|
|
|
|
|
|
|
return Hi->getOffset() - Lo->getOffset();
|
|
|
|
}
|
|
|
|
|
2015-06-12 02:58:08 +08:00
|
|
|
void MCObjectStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi,
|
2015-05-21 10:41:23 +08:00
|
|
|
const MCSymbol *Lo,
|
|
|
|
unsigned Size) {
|
2018-08-16 19:26:37 +08:00
|
|
|
if (Optional<uint64_t> Diff = absoluteSymbolDiff(getAssembler(), Hi, Lo)) {
|
2020-02-15 14:40:47 +08:00
|
|
|
emitIntValue(*Diff, Size);
|
2015-06-12 02:58:08 +08:00
|
|
|
return;
|
|
|
|
}
|
2018-02-10 01:00:25 +08:00
|
|
|
MCStreamer::emitAbsoluteSymbolDiff(Hi, Lo, Size);
|
|
|
|
}
|
2015-05-21 10:41:23 +08:00
|
|
|
|
2018-02-10 01:00:25 +08:00
|
|
|
void MCObjectStreamer::emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
|
|
|
|
const MCSymbol *Lo) {
|
2018-08-16 19:26:37 +08:00
|
|
|
if (Optional<uint64_t> Diff = absoluteSymbolDiff(getAssembler(), Hi, Lo)) {
|
2020-02-14 05:26:21 +08:00
|
|
|
emitULEB128IntValue(*Diff);
|
2018-02-10 01:00:25 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
MCStreamer::emitAbsoluteSymbolDiffAsULEB128(Hi, Lo);
|
2015-05-21 10:41:23 +08:00
|
|
|
}
|
|
|
|
|
2012-12-13 06:59:46 +08:00
|
|
|
void MCObjectStreamer::reset() {
|
2012-12-15 02:52:11 +08:00
|
|
|
if (Assembler)
|
|
|
|
Assembler->reset();
|
2015-05-27 23:14:11 +08:00
|
|
|
CurInsertionPoint = MCSection::iterator();
|
2014-05-12 22:02:44 +08:00
|
|
|
EmitEHFrame = true;
|
|
|
|
EmitDebugFrame = false;
|
2014-10-23 06:38:06 +08:00
|
|
|
PendingLabels.clear();
|
[ MC ] Match labels to existing fragments even when switching sections.
(This commit restores the original branch (4272372c571) and applies an
additional change dropped from the original in a bad merge. This change
should address the previous bot failures. Both changes reviewed by pete.)
Summary:
This commit builds upon Derek Schuff's 2014 commit for attaching labels to
existing fragments ( Diff Revision: http://reviews.llvm.org/D5915 )
When temporary labels appear ahead of a fragment, MCObjectStreamer will
track the temporary label symbol in a "Pending Labels" list. Labels are
associated with fragments when a real fragment arrives; otherwise, an empty
data fragment will be created if the streamer's section changes or if the
stream finishes.
This commit moves the "Pending Labels" list into each MCStream, so that
this label-fragment matching process is resilient to section changes. If
the streamer emits a label in a new section, switches to another section to
do other work, then switches back to the first section and emits a
fragment, that initial label will be associated with this new fragment.
Labels will only receive empty data fragments in the case where no other
fragment exists for that section.
The downstream effects of this can be seen in Mach-O relocations. The
previous approach could produce local section relocations and external
symbol relocations for the same data in an object file, and this mix of
relocation types resulted in problems in the ld64 Mach-O linker. This
commit ensures relocations triggered by temporary labels are consistent.
Reviewers: pete, ab, dschuff
Reviewed By: pete, dschuff
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71368
2019-12-12 02:42:37 +08:00
|
|
|
PendingLabelSections.clear();
|
2012-12-13 06:59:46 +08:00
|
|
|
MCStreamer::reset();
|
|
|
|
}
|
|
|
|
|
2020-04-21 10:28:13 +08:00
|
|
|
void MCObjectStreamer::emitFrames(MCAsmBackend *MAB) {
|
2014-05-12 22:02:44 +08:00
|
|
|
if (!getNumFrameInfos())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (EmitEHFrame)
|
|
|
|
MCDwarfFrameEmitter::Emit(*this, MAB, true);
|
|
|
|
|
|
|
|
if (EmitDebugFrame)
|
|
|
|
MCDwarfFrameEmitter::Emit(*this, MAB, false);
|
|
|
|
}
|
|
|
|
|
2010-07-19 14:13:10 +08:00
|
|
|
MCFragment *MCObjectStreamer::getCurrentFragment() const {
|
2015-05-28 05:04:14 +08:00
|
|
|
assert(getCurrentSectionOnly() && "No current section!");
|
2010-07-19 14:13:10 +08:00
|
|
|
|
2015-05-28 05:04:14 +08:00
|
|
|
if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
|
2015-10-10 08:13:11 +08:00
|
|
|
return &*std::prev(CurInsertionPoint);
|
2010-07-19 14:13:10 +08:00
|
|
|
|
2014-04-13 12:57:38 +08:00
|
|
|
return nullptr;
|
2010-07-19 14:13:10 +08:00
|
|
|
}
|
|
|
|
|
2020-05-09 12:47:44 +08:00
|
|
|
static bool canReuseDataFragment(const MCDataFragment &F,
|
2018-06-06 17:40:06 +08:00
|
|
|
const MCAssembler &Assembler,
|
|
|
|
const MCSubtargetInfo *STI) {
|
|
|
|
if (!F.hasInstructions())
|
|
|
|
return true;
|
2013-02-16 06:50:52 +08:00
|
|
|
// When bundling is enabled, we don't want to add data to a fragment that
|
2020-04-20 17:53:00 +08:00
|
|
|
// already has instructions (see MCELFStreamer::emitInstToData for details)
|
2018-06-06 17:40:06 +08:00
|
|
|
if (Assembler.isBundlingEnabled())
|
|
|
|
return Assembler.getRelaxAll();
|
|
|
|
// If the subtarget is changed mid fragment we start a new fragment to record
|
|
|
|
// the new STI.
|
|
|
|
return !STI || F.getSubtargetInfo() == STI;
|
|
|
|
}
|
|
|
|
|
|
|
|
MCDataFragment *
|
|
|
|
MCObjectStreamer::getOrCreateDataFragment(const MCSubtargetInfo *STI) {
|
|
|
|
MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
|
2020-05-09 12:47:44 +08:00
|
|
|
if (!F || !canReuseDataFragment(*F, *Assembler, STI)) {
|
2014-04-11 05:53:47 +08:00
|
|
|
F = new MCDataFragment();
|
2013-04-18 05:18:16 +08:00
|
|
|
insert(F);
|
|
|
|
}
|
2010-07-19 14:13:10 +08:00
|
|
|
return F;
|
|
|
|
}
|
|
|
|
|
2014-06-25 23:29:54 +08:00
|
|
|
void MCObjectStreamer::visitUsedSymbol(const MCSymbol &Sym) {
|
2015-05-30 04:21:02 +08:00
|
|
|
Assembler->registerSymbol(Sym);
|
2014-06-25 23:29:54 +08:00
|
|
|
}
|
|
|
|
|
2020-02-14 13:58:16 +08:00
|
|
|
void MCObjectStreamer::emitCFISections(bool EH, bool Debug) {
|
|
|
|
MCStreamer::emitCFISections(EH, Debug);
|
2014-05-12 22:02:44 +08:00
|
|
|
EmitEHFrame = EH;
|
|
|
|
EmitDebugFrame = Debug;
|
|
|
|
}
|
|
|
|
|
2020-02-15 11:21:58 +08:00
|
|
|
void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
|
2015-09-21 07:35:59 +08:00
|
|
|
SMLoc Loc) {
|
2020-02-15 11:21:58 +08:00
|
|
|
MCStreamer::emitValueImpl(Value, Size, Loc);
|
2010-11-29 07:08:47 +08:00
|
|
|
MCDataFragment *DF = getOrCreateDataFragment();
|
2015-06-27 09:54:17 +08:00
|
|
|
flushPendingLabels(DF, DF->getContents().size());
|
2010-11-29 07:08:47 +08:00
|
|
|
|
2016-10-14 13:47:37 +08:00
|
|
|
MCDwarfLineEntry::Make(this, getCurrentSectionOnly());
|
2013-05-26 05:56:53 +08:00
|
|
|
|
2010-11-29 07:08:47 +08:00
|
|
|
// Avoid fixups when possible.
|
|
|
|
int64_t AbsValue;
|
[MC] Change AsmParser to leverage Assembler during evaluation
Teach AsmParser to check with Assembler for when evaluating constant
expressions. This improves the handing of preprocessor expressions
that must be resolved at parse time. This idiom can be found as
assembling-time assertion checks in source-level assemblers. Note that
this relies on the MCStreamer to keep sufficient tabs on Section /
Fragment information which the MCAsmStreamer does not. As a result the
textual output may fail where the equivalent object generation would
pass. This can most easily be resolved by folding the MCAsmStreamer
and MCObjectStreamer together which is planned for in a separate
patch.
Currently, this feature is only enabled for assembly input, keeping IR
compilation consistent between assembly and object generation.
Reviewers: echristo, rnk, probinson, espindola, peter.smith
Reviewed By: peter.smith
Subscribers: eraman, peter.smith, arichardson, jyknight, hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D45164
llvm-svn: 331218
2018-05-01 03:22:40 +08:00
|
|
|
if (Value->evaluateAsAbsolute(AbsValue, getAssemblerPtr())) {
|
2017-05-15 16:43:27 +08:00
|
|
|
if (!isUIntN(8 * Size, AbsValue) && !isIntN(8 * Size, AbsValue)) {
|
|
|
|
getContext().reportError(
|
|
|
|
Loc, "value evaluated as " + Twine(AbsValue) + " is out of range.");
|
|
|
|
return;
|
|
|
|
}
|
2020-02-15 14:40:47 +08:00
|
|
|
emitIntValue(AbsValue, Size);
|
2010-12-03 10:54:21 +08:00
|
|
|
return;
|
2010-11-29 07:08:47 +08:00
|
|
|
}
|
2012-12-08 03:13:57 +08:00
|
|
|
DF->getFixups().push_back(
|
2015-05-16 03:13:05 +08:00
|
|
|
MCFixup::create(DF->getContents().size(), Value,
|
2014-04-23 01:27:29 +08:00
|
|
|
MCFixup::getKindForSize(Size, false), Loc));
|
2010-12-03 10:54:21 +08:00
|
|
|
DF->getContents().resize(DF->getContents().size() + Size, 0);
|
2010-11-29 07:08:47 +08:00
|
|
|
}
|
|
|
|
|
2020-02-14 13:58:16 +08:00
|
|
|
MCSymbol *MCObjectStreamer::emitCFILabel() {
|
[MC] Suppress .Lcfi labels when emitting textual assembly
Summary:
This suppresses the generation of .Lcfi labels in our textual assembler.
It was annoying that this generated cascading .Lcfi labels:
llc foo.ll -o - | llvm-mc | llvm-mc
After three trips through MCAsmStreamer, we'd have three labels in the
output when none are necessary. We should only bother creating the
labels and frame data when making a real object file.
This supercedes D38605, which moved the entire .seh_ implementation into
MCObjectStreamer.
This has the advantage that we do more checking when emitting textual
assembly, as a minor efficiency cost. Outputting textual assembly is not
performance critical, so this shouldn't matter.
Reviewers: majnemer, MatzeB
Subscribers: qcolombet, nemanjai, javed.absar, eraman, hiraditya, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D38638
llvm-svn: 315259
2017-10-10 08:57:36 +08:00
|
|
|
MCSymbol *Label = getContext().createTempSymbol("cfi", true);
|
2020-02-15 11:21:58 +08:00
|
|
|
emitLabel(Label);
|
[MC] Suppress .Lcfi labels when emitting textual assembly
Summary:
This suppresses the generation of .Lcfi labels in our textual assembler.
It was annoying that this generated cascading .Lcfi labels:
llc foo.ll -o - | llvm-mc | llvm-mc
After three trips through MCAsmStreamer, we'd have three labels in the
output when none are necessary. We should only bother creating the
labels and frame data when making a real object file.
This supercedes D38605, which moved the entire .seh_ implementation into
MCObjectStreamer.
This has the advantage that we do more checking when emitting textual
assembly, as a minor efficiency cost. Outputting textual assembly is not
performance critical, so this shouldn't matter.
Reviewers: majnemer, MatzeB
Subscribers: qcolombet, nemanjai, javed.absar, eraman, hiraditya, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D38638
llvm-svn: 315259
2017-10-10 08:57:36 +08:00
|
|
|
return Label;
|
|
|
|
}
|
|
|
|
|
2020-02-14 13:58:16 +08:00
|
|
|
void MCObjectStreamer::emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
|
2014-11-03 20:19:03 +08:00
|
|
|
// We need to create a local symbol to avoid relocations.
|
2015-05-19 02:43:14 +08:00
|
|
|
Frame.Begin = getContext().createTempSymbol();
|
2020-02-15 11:21:58 +08:00
|
|
|
emitLabel(Frame.Begin);
|
2012-01-08 06:42:19 +08:00
|
|
|
}
|
|
|
|
|
2020-02-14 13:58:16 +08:00
|
|
|
void MCObjectStreamer::emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
|
2015-05-19 02:43:14 +08:00
|
|
|
Frame.End = getContext().createTempSymbol();
|
2020-02-15 11:21:58 +08:00
|
|
|
emitLabel(Frame.End);
|
2012-01-09 08:17:29 +08:00
|
|
|
}
|
|
|
|
|
2020-02-15 11:21:58 +08:00
|
|
|
void MCObjectStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
|
|
|
|
MCStreamer::emitLabel(Symbol, Loc);
|
2010-11-29 01:18:55 +08:00
|
|
|
|
2015-05-30 04:21:02 +08:00
|
|
|
getAssembler().registerSymbol(*Symbol);
|
2014-10-23 06:38:06 +08:00
|
|
|
|
|
|
|
// 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.
|
2015-04-13 07:42:25 +08:00
|
|
|
auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
|
|
|
|
if (F && !(getAssembler().isBundlingEnabled() &&
|
|
|
|
getAssembler().getRelaxAll())) {
|
2015-05-30 05:45:01 +08:00
|
|
|
Symbol->setFragment(F);
|
2015-05-30 01:48:04 +08:00
|
|
|
Symbol->setOffset(F->getContents().size());
|
2014-10-23 06:38:06 +08:00
|
|
|
} else {
|
2019-11-11 05:12:29 +08:00
|
|
|
// Assign all pending labels to offset 0 within the dummy "pending"
|
|
|
|
// fragment. (They will all be reassigned to a real fragment in
|
|
|
|
// flushPendingLabels())
|
|
|
|
Symbol->setOffset(0);
|
[ MC ] Match labels to existing fragments even when switching sections.
(This commit restores the original branch (4272372c571) and applies an
additional change dropped from the original in a bad merge. This change
should address the previous bot failures. Both changes reviewed by pete.)
Summary:
This commit builds upon Derek Schuff's 2014 commit for attaching labels to
existing fragments ( Diff Revision: http://reviews.llvm.org/D5915 )
When temporary labels appear ahead of a fragment, MCObjectStreamer will
track the temporary label symbol in a "Pending Labels" list. Labels are
associated with fragments when a real fragment arrives; otherwise, an empty
data fragment will be created if the streamer's section changes or if the
stream finishes.
This commit moves the "Pending Labels" list into each MCStream, so that
this label-fragment matching process is resilient to section changes. If
the streamer emits a label in a new section, switches to another section to
do other work, then switches back to the first section and emits a
fragment, that initial label will be associated with this new fragment.
Labels will only receive empty data fragments in the case where no other
fragment exists for that section.
The downstream effects of this can be seen in Mach-O relocations. The
previous approach could produce local section relocations and external
symbol relocations for the same data in an object file, and this mix of
relocation types resulted in problems in the ld64 Mach-O linker. This
commit ensures relocations triggered by temporary labels are consistent.
Reviewers: pete, ab, dschuff
Reviewed By: pete, dschuff
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71368
2019-12-12 02:42:37 +08:00
|
|
|
addPendingLabel(Symbol);
|
2014-10-23 06:38:06 +08:00
|
|
|
}
|
2010-11-29 01:18:55 +08:00
|
|
|
}
|
|
|
|
|
2019-11-11 05:12:29 +08:00
|
|
|
// Emit a label at a previously emitted fragment/offset position. This must be
|
|
|
|
// within the currently-active section.
|
2020-02-14 05:26:21 +08:00
|
|
|
void MCObjectStreamer::emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc,
|
2019-11-11 05:12:29 +08:00
|
|
|
MCFragment *F, uint64_t Offset) {
|
|
|
|
assert(F->getParent() == getCurrentSectionOnly());
|
|
|
|
|
2020-02-15 11:21:58 +08:00
|
|
|
MCStreamer::emitLabel(Symbol, Loc);
|
2017-04-04 05:50:04 +08:00
|
|
|
getAssembler().registerSymbol(*Symbol);
|
|
|
|
auto *DF = dyn_cast_or_null<MCDataFragment>(F);
|
2019-11-11 05:12:29 +08:00
|
|
|
Symbol->setOffset(Offset);
|
|
|
|
if (DF) {
|
2017-04-04 05:50:04 +08:00
|
|
|
Symbol->setFragment(F);
|
2019-11-11 05:12:29 +08:00
|
|
|
} else {
|
|
|
|
assert(isa<MCDummyFragment>(F) &&
|
|
|
|
"F must either be an MCDataFragment or the pending MCDummyFragment");
|
|
|
|
assert(Offset == 0);
|
[ MC ] Match labels to existing fragments even when switching sections.
(This commit restores the original branch (4272372c571) and applies an
additional change dropped from the original in a bad merge. This change
should address the previous bot failures. Both changes reviewed by pete.)
Summary:
This commit builds upon Derek Schuff's 2014 commit for attaching labels to
existing fragments ( Diff Revision: http://reviews.llvm.org/D5915 )
When temporary labels appear ahead of a fragment, MCObjectStreamer will
track the temporary label symbol in a "Pending Labels" list. Labels are
associated with fragments when a real fragment arrives; otherwise, an empty
data fragment will be created if the streamer's section changes or if the
stream finishes.
This commit moves the "Pending Labels" list into each MCStream, so that
this label-fragment matching process is resilient to section changes. If
the streamer emits a label in a new section, switches to another section to
do other work, then switches back to the first section and emits a
fragment, that initial label will be associated with this new fragment.
Labels will only receive empty data fragments in the case where no other
fragment exists for that section.
The downstream effects of this can be seen in Mach-O relocations. The
previous approach could produce local section relocations and external
symbol relocations for the same data in an object file, and this mix of
relocation types resulted in problems in the ld64 Mach-O linker. This
commit ensures relocations triggered by temporary labels are consistent.
Reviewers: pete, ab, dschuff
Reviewed By: pete, dschuff
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71368
2019-12-12 02:42:37 +08:00
|
|
|
addPendingLabel(Symbol);
|
2019-11-11 05:12:29 +08:00
|
|
|
}
|
2017-04-04 05:50:04 +08:00
|
|
|
}
|
|
|
|
|
2020-02-14 05:26:21 +08:00
|
|
|
void MCObjectStreamer::emitULEB128Value(const MCExpr *Value) {
|
2010-12-03 09:19:49 +08:00
|
|
|
int64_t IntValue;
|
[MC] Change AsmParser to leverage Assembler during evaluation
Teach AsmParser to check with Assembler for when evaluating constant
expressions. This improves the handing of preprocessor expressions
that must be resolved at parse time. This idiom can be found as
assembling-time assertion checks in source-level assemblers. Note that
this relies on the MCStreamer to keep sufficient tabs on Section /
Fragment information which the MCAsmStreamer does not. As a result the
textual output may fail where the equivalent object generation would
pass. This can most easily be resolved by folding the MCAsmStreamer
and MCObjectStreamer together which is planned for in a separate
patch.
Currently, this feature is only enabled for assembly input, keeping IR
compilation consistent between assembly and object generation.
Reviewers: echristo, rnk, probinson, espindola, peter.smith
Reviewed By: peter.smith
Subscribers: eraman, peter.smith, arichardson, jyknight, hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D45164
llvm-svn: 331218
2018-05-01 03:22:40 +08:00
|
|
|
if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
|
2020-02-14 05:26:21 +08:00
|
|
|
emitULEB128IntValue(IntValue);
|
2010-12-03 09:19:49 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-04-18 05:18:16 +08:00
|
|
|
insert(new MCLEBFragment(*Value, false));
|
2010-11-03 01:22:24 +08:00
|
|
|
}
|
|
|
|
|
2020-02-14 05:26:21 +08:00
|
|
|
void MCObjectStreamer::emitSLEB128Value(const MCExpr *Value) {
|
2010-12-03 09:19:49 +08:00
|
|
|
int64_t IntValue;
|
[MC] Change AsmParser to leverage Assembler during evaluation
Teach AsmParser to check with Assembler for when evaluating constant
expressions. This improves the handing of preprocessor expressions
that must be resolved at parse time. This idiom can be found as
assembling-time assertion checks in source-level assemblers. Note that
this relies on the MCStreamer to keep sufficient tabs on Section /
Fragment information which the MCAsmStreamer does not. As a result the
textual output may fail where the equivalent object generation would
pass. This can most easily be resolved by folding the MCAsmStreamer
and MCObjectStreamer together which is planned for in a separate
patch.
Currently, this feature is only enabled for assembly input, keeping IR
compilation consistent between assembly and object generation.
Reviewers: echristo, rnk, probinson, espindola, peter.smith
Reviewed By: peter.smith
Subscribers: eraman, peter.smith, arichardson, jyknight, hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D45164
llvm-svn: 331218
2018-05-01 03:22:40 +08:00
|
|
|
if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
|
2020-02-14 05:26:21 +08:00
|
|
|
emitSLEB128IntValue(IntValue);
|
2010-12-03 09:19:49 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-04-18 05:18:16 +08:00
|
|
|
insert(new MCLEBFragment(*Value, true));
|
2010-11-03 01:22:24 +08:00
|
|
|
}
|
|
|
|
|
2020-02-15 10:16:24 +08:00
|
|
|
void MCObjectStreamer::emitWeakReference(MCSymbol *Alias,
|
2010-11-01 22:28:48 +08:00
|
|
|
const MCSymbol *Symbol) {
|
|
|
|
report_fatal_error("This file format doesn't support weak aliases.");
|
|
|
|
}
|
|
|
|
|
2020-04-21 10:28:13 +08:00
|
|
|
void MCObjectStreamer::changeSection(MCSection *Section,
|
2013-04-18 05:18:16 +08:00
|
|
|
const MCExpr *Subsection) {
|
2015-03-21 04:00:01 +08:00
|
|
|
changeSectionImpl(Section, Subsection);
|
|
|
|
}
|
|
|
|
|
2015-05-22 03:20:38 +08:00
|
|
|
bool MCObjectStreamer::changeSectionImpl(MCSection *Section,
|
2015-03-21 04:00:01 +08:00
|
|
|
const MCExpr *Subsection) {
|
2010-06-17 04:04:25 +08:00
|
|
|
assert(Section && "Cannot switch to a null section!");
|
2017-03-16 08:52:18 +08:00
|
|
|
getContext().clearDwarfLocSeen();
|
2010-06-17 04:04:25 +08:00
|
|
|
|
2015-05-26 23:07:25 +08:00
|
|
|
bool Created = getAssembler().registerSection(*Section);
|
2013-04-18 05:18:16 +08:00
|
|
|
|
|
|
|
int64_t IntSubsection = 0;
|
|
|
|
if (Subsection &&
|
[MC] Change AsmParser to leverage Assembler during evaluation
Teach AsmParser to check with Assembler for when evaluating constant
expressions. This improves the handing of preprocessor expressions
that must be resolved at parse time. This idiom can be found as
assembling-time assertion checks in source-level assemblers. Note that
this relies on the MCStreamer to keep sufficient tabs on Section /
Fragment information which the MCAsmStreamer does not. As a result the
textual output may fail where the equivalent object generation would
pass. This can most easily be resolved by folding the MCAsmStreamer
and MCObjectStreamer together which is planned for in a separate
patch.
Currently, this feature is only enabled for assembly input, keeping IR
compilation consistent between assembly and object generation.
Reviewers: echristo, rnk, probinson, espindola, peter.smith
Reviewed By: peter.smith
Subscribers: eraman, peter.smith, arichardson, jyknight, hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D45164
llvm-svn: 331218
2018-05-01 03:22:40 +08:00
|
|
|
!Subsection->evaluateAsAbsolute(IntSubsection, getAssemblerPtr()))
|
2013-04-18 05:18:16 +08:00
|
|
|
report_fatal_error("Cannot evaluate subsection number");
|
|
|
|
if (IntSubsection < 0 || IntSubsection > 8192)
|
|
|
|
report_fatal_error("Subsection number out of range");
|
[ MC ] Match labels to existing fragments even when switching sections.
(This commit restores the original branch (4272372c571) and applies an
additional change dropped from the original in a bad merge. This change
should address the previous bot failures. Both changes reviewed by pete.)
Summary:
This commit builds upon Derek Schuff's 2014 commit for attaching labels to
existing fragments ( Diff Revision: http://reviews.llvm.org/D5915 )
When temporary labels appear ahead of a fragment, MCObjectStreamer will
track the temporary label symbol in a "Pending Labels" list. Labels are
associated with fragments when a real fragment arrives; otherwise, an empty
data fragment will be created if the streamer's section changes or if the
stream finishes.
This commit moves the "Pending Labels" list into each MCStream, so that
this label-fragment matching process is resilient to section changes. If
the streamer emits a label in a new section, switches to another section to
do other work, then switches back to the first section and emits a
fragment, that initial label will be associated with this new fragment.
Labels will only receive empty data fragments in the case where no other
fragment exists for that section.
The downstream effects of this can be seen in Mach-O relocations. The
previous approach could produce local section relocations and external
symbol relocations for the same data in an object file, and this mix of
relocation types resulted in problems in the ld64 Mach-O linker. This
commit ensures relocations triggered by temporary labels are consistent.
Reviewers: pete, ab, dschuff
Reviewed By: pete, dschuff
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71368
2019-12-12 02:42:37 +08:00
|
|
|
CurSubsectionIdx = unsigned(IntSubsection);
|
2013-04-18 05:18:16 +08:00
|
|
|
CurInsertionPoint =
|
[ MC ] Match labels to existing fragments even when switching sections.
(This commit restores the original branch (4272372c571) and applies an
additional change dropped from the original in a bad merge. This change
should address the previous bot failures. Both changes reviewed by pete.)
Summary:
This commit builds upon Derek Schuff's 2014 commit for attaching labels to
existing fragments ( Diff Revision: http://reviews.llvm.org/D5915 )
When temporary labels appear ahead of a fragment, MCObjectStreamer will
track the temporary label symbol in a "Pending Labels" list. Labels are
associated with fragments when a real fragment arrives; otherwise, an empty
data fragment will be created if the streamer's section changes or if the
stream finishes.
This commit moves the "Pending Labels" list into each MCStream, so that
this label-fragment matching process is resilient to section changes. If
the streamer emits a label in a new section, switches to another section to
do other work, then switches back to the first section and emits a
fragment, that initial label will be associated with this new fragment.
Labels will only receive empty data fragments in the case where no other
fragment exists for that section.
The downstream effects of this can be seen in Mach-O relocations. The
previous approach could produce local section relocations and external
symbol relocations for the same data in an object file, and this mix of
relocation types resulted in problems in the ld64 Mach-O linker. This
commit ensures relocations triggered by temporary labels are consistent.
Reviewers: pete, ab, dschuff
Reviewed By: pete, dschuff
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71368
2019-12-12 02:42:37 +08:00
|
|
|
Section->getSubsectionInsertionPoint(CurSubsectionIdx);
|
2015-03-21 04:00:01 +08:00
|
|
|
return Created;
|
2010-06-17 04:04:25 +08:00
|
|
|
}
|
|
|
|
|
2020-02-15 10:16:24 +08:00
|
|
|
void MCObjectStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
|
2015-05-30 04:21:02 +08:00
|
|
|
getAssembler().registerSymbol(*Symbol);
|
2020-02-15 10:16:24 +08:00
|
|
|
MCStreamer::emitAssignment(Symbol, Value);
|
2012-12-08 01:42:41 +08:00
|
|
|
}
|
|
|
|
|
2015-05-26 02:34:26 +08:00
|
|
|
bool MCObjectStreamer::mayHaveInstructions(MCSection &Sec) const {
|
|
|
|
return Sec.hasInstructions();
|
|
|
|
}
|
|
|
|
|
2020-02-14 13:58:16 +08:00
|
|
|
void MCObjectStreamer::emitInstruction(const MCInst &Inst,
|
2019-02-04 20:51:26 +08:00
|
|
|
const MCSubtargetInfo &STI) {
|
2020-04-15 02:05:21 +08:00
|
|
|
const MCSection &Sec = *getCurrentSectionOnly();
|
|
|
|
if (Sec.isVirtualSection()) {
|
|
|
|
getContext().reportError(Inst.getLoc(), Twine(Sec.getVirtualSectionKind()) +
|
|
|
|
" section '" + Sec.getName() +
|
|
|
|
"' cannot have instructions");
|
|
|
|
return;
|
|
|
|
}
|
2020-03-16 16:52:31 +08:00
|
|
|
getAssembler().getBackend().emitInstructionBegin(*this, Inst);
|
2020-02-14 13:58:16 +08:00
|
|
|
emitInstructionImpl(Inst, STI);
|
2020-03-16 16:52:31 +08:00
|
|
|
getAssembler().getBackend().emitInstructionEnd(*this, Inst);
|
Align branches within 32-Byte boundary (NOP padding)
WARNING: If you're looking at this patch because you're looking for a full
performace mitigation of the Intel JCC Erratum, this is not it!
This is a preliminary patch on the patch towards mitigating the performance
regressions caused by Intel's microcode update for Jump Conditional Code
Erratum. For context, see:
https://www.intel.com/content/www/us/en/support/articles/000055650.html
The patch adds the required assembler infrastructure and command line options
needed to exercise the logic for INTERNAL TESTING. These are NOT public flags,
and should not be used for anything other than LLVM's own testing/debugging
purposes. They are likely to change both in spelling and meaning.
WARNING: This patch is knowingly incorrect in some cornercases. We need, and
do not yet provide, a mechanism to selective enable/disable the padding.
Conversation on this will continue in parellel with work on extending this
infrastructure to support prefix padding.
The goal here is to have the assembler align specific instructions such that
they neither cross or end at a 32 byte boundary. The impacted instructions are:
a. Conditional jump.
b. Fused conditional jump.
c. Unconditional jump.
d. Indirect jump.
e. Ret.
f. Call.
The new options for llvm-mc are:
-x86-align-branch-boundary=NUM aligns branches within NUM byte boundary.
-x86-align-branch=TYPE[+TYPE...] specifies types of branches to align.
A new MCFragment type, MCBoundaryAlignFragment, is added, which may emit
NOP to align the fused/unfused branch.
alignBranchesBegin inserts MCBoundaryAlignFragment before instructions,
alignBranchesEnd marks the end of the branch to be aligned,
relaxBoundaryAlign grows or shrinks sizes of NOP to align the target branch.
Nop padding is disabled when the instruction may be rewritten by the linker,
such as TLS Call.
Process Note: I am landing a patch by skan as it has been LGTMed, and
continuing to iterate on the review is simply slowing us down at this point.
We can and will continue to iterate in tree.
Patch By: skan
Differential Revision: https://reviews.llvm.org/D70157
2019-12-21 02:51:05 +08:00
|
|
|
}
|
|
|
|
|
2020-02-14 13:58:16 +08:00
|
|
|
void MCObjectStreamer::emitInstructionImpl(const MCInst &Inst,
|
Align branches within 32-Byte boundary (NOP padding)
WARNING: If you're looking at this patch because you're looking for a full
performace mitigation of the Intel JCC Erratum, this is not it!
This is a preliminary patch on the patch towards mitigating the performance
regressions caused by Intel's microcode update for Jump Conditional Code
Erratum. For context, see:
https://www.intel.com/content/www/us/en/support/articles/000055650.html
The patch adds the required assembler infrastructure and command line options
needed to exercise the logic for INTERNAL TESTING. These are NOT public flags,
and should not be used for anything other than LLVM's own testing/debugging
purposes. They are likely to change both in spelling and meaning.
WARNING: This patch is knowingly incorrect in some cornercases. We need, and
do not yet provide, a mechanism to selective enable/disable the padding.
Conversation on this will continue in parellel with work on extending this
infrastructure to support prefix padding.
The goal here is to have the assembler align specific instructions such that
they neither cross or end at a 32 byte boundary. The impacted instructions are:
a. Conditional jump.
b. Fused conditional jump.
c. Unconditional jump.
d. Indirect jump.
e. Ret.
f. Call.
The new options for llvm-mc are:
-x86-align-branch-boundary=NUM aligns branches within NUM byte boundary.
-x86-align-branch=TYPE[+TYPE...] specifies types of branches to align.
A new MCFragment type, MCBoundaryAlignFragment, is added, which may emit
NOP to align the fused/unfused branch.
alignBranchesBegin inserts MCBoundaryAlignFragment before instructions,
alignBranchesEnd marks the end of the branch to be aligned,
relaxBoundaryAlign grows or shrinks sizes of NOP to align the target branch.
Nop padding is disabled when the instruction may be rewritten by the linker,
such as TLS Call.
Process Note: I am landing a patch by skan as it has been LGTMed, and
continuing to iterate on the review is simply slowing us down at this point.
We can and will continue to iterate in tree.
Patch By: skan
Differential Revision: https://reviews.llvm.org/D70157
2019-12-21 02:51:05 +08:00
|
|
|
const MCSubtargetInfo &STI) {
|
2020-02-14 13:58:16 +08:00
|
|
|
MCStreamer::emitInstruction(Inst, STI);
|
2010-11-02 00:27:31 +08:00
|
|
|
|
2015-05-28 05:04:14 +08:00
|
|
|
MCSection *Sec = getCurrentSectionOnly();
|
2015-05-26 22:48:11 +08:00
|
|
|
Sec->setHasInstructions(true);
|
2010-11-02 00:27:31 +08:00
|
|
|
|
|
|
|
// Now that a machine instruction has been assembled into this section, make
|
|
|
|
// a line entry for any .loc directive that has been seen.
|
2016-10-14 13:47:37 +08:00
|
|
|
MCDwarfLineEntry::Make(this, getCurrentSectionOnly());
|
2010-11-02 00:27:31 +08:00
|
|
|
|
|
|
|
// If this instruction doesn't need relaxation, just emit it as data.
|
2012-12-21 03:05:53 +08:00
|
|
|
MCAssembler &Assembler = getAssembler();
|
[X86][MC] Support enhanced relaxation for branch align
Summary:
Since D75300 has been landed, I want to support enhanced relaxation when we need to align branches and allow prefix padding. "Enhanced Relaxtion" means we allow an instruction that could not be traditionally relaxed to be emitted into RelaxableFragment so that we increase its length by adding prefixes for optimization.
The motivation is straightforward, RelaxFragment is mostly for relative jumps and we can not increase the length of jumps when we need to align them, so if we need to achieve D75300's purpose (reducing the bytes of nops) when need to align jumps, we have to make more instructions "relaxable".
Reviewers: reames, MaskRay, craig.topper, LuoYuanke, jyknight
Reviewed By: reames
Subscribers: hiraditya, llvm-commits, annita.zhang
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D76286
2020-04-07 12:27:45 +08:00
|
|
|
MCAsmBackend &Backend = Assembler.getBackend();
|
|
|
|
if (!(Backend.mayNeedRelaxation(Inst, STI) ||
|
|
|
|
Backend.allowEnhancedRelaxation())) {
|
2020-04-20 17:53:00 +08:00
|
|
|
emitInstToData(Inst, STI);
|
2010-11-02 00:27:31 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-21 03:05:53 +08:00
|
|
|
// Otherwise, relax and emit it as data if either:
|
|
|
|
// - The RelaxAll flag was passed
|
|
|
|
// - Bundling is enabled and this instruction is inside a bundle-locked
|
|
|
|
// group. We want to emit all such instructions into the same data
|
|
|
|
// fragment.
|
|
|
|
if (Assembler.getRelaxAll() ||
|
2015-05-26 22:48:11 +08:00
|
|
|
(Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
|
2020-04-10 18:37:24 +08:00
|
|
|
MCInst Relaxed = Inst;
|
2020-05-09 12:47:44 +08:00
|
|
|
while (Backend.mayNeedRelaxation(Relaxed, STI))
|
|
|
|
Backend.relaxInstruction(Relaxed, STI);
|
2020-04-20 17:53:00 +08:00
|
|
|
emitInstToData(Relaxed, STI);
|
2010-11-02 00:27:31 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise emit to a separate fragment.
|
2020-04-21 10:28:13 +08:00
|
|
|
emitInstToFragment(Inst, STI);
|
2010-11-02 00:27:31 +08:00
|
|
|
}
|
|
|
|
|
2020-04-21 10:28:13 +08:00
|
|
|
void MCObjectStreamer::emitInstToFragment(const MCInst &Inst,
|
2014-01-29 07:12:49 +08:00
|
|
|
const MCSubtargetInfo &STI) {
|
2015-04-13 07:42:25 +08:00
|
|
|
if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
|
|
|
|
llvm_unreachable("All instructions should have already been relaxed");
|
|
|
|
|
2012-12-21 03:05:53 +08:00
|
|
|
// Always create a new, separate fragment here, because its size can change
|
|
|
|
// during relaxation.
|
2014-01-29 07:12:53 +08:00
|
|
|
MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
|
2013-04-18 05:18:16 +08:00
|
|
|
insert(IF);
|
2010-12-02 13:44:06 +08:00
|
|
|
|
2011-04-19 04:54:46 +08:00
|
|
|
SmallString<128> Code;
|
|
|
|
raw_svector_ostream VecOS(Code);
|
2015-05-16 03:13:16 +08:00
|
|
|
getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(),
|
2014-01-29 07:13:07 +08:00
|
|
|
STI);
|
2012-12-08 03:13:57 +08:00
|
|
|
IF->getContents().append(Code.begin(), Code.end());
|
2010-12-02 13:44:06 +08:00
|
|
|
}
|
|
|
|
|
2013-02-16 07:12:33 +08:00
|
|
|
#ifndef NDEBUG
|
2013-07-16 09:17:10 +08:00
|
|
|
static const char *const BundlingNotImplementedMsg =
|
2012-12-21 03:05:53 +08:00
|
|
|
"Aligned bundling is not implemented for this object format";
|
2013-02-16 07:12:33 +08:00
|
|
|
#endif
|
2012-12-21 03:05:53 +08:00
|
|
|
|
2020-02-16 00:52:56 +08:00
|
|
|
void MCObjectStreamer::emitBundleAlignMode(unsigned AlignPow2) {
|
2012-12-21 03:05:53 +08:00
|
|
|
llvm_unreachable(BundlingNotImplementedMsg);
|
|
|
|
}
|
|
|
|
|
2020-02-16 00:52:56 +08:00
|
|
|
void MCObjectStreamer::emitBundleLock(bool AlignToEnd) {
|
2012-12-21 03:05:53 +08:00
|
|
|
llvm_unreachable(BundlingNotImplementedMsg);
|
|
|
|
}
|
|
|
|
|
2020-02-16 00:52:56 +08:00
|
|
|
void MCObjectStreamer::emitBundleUnlock() {
|
2012-12-21 03:05:53 +08:00
|
|
|
llvm_unreachable(BundlingNotImplementedMsg);
|
|
|
|
}
|
|
|
|
|
2020-02-14 05:26:21 +08:00
|
|
|
void MCObjectStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,
|
2013-06-20 05:27:27 +08:00
|
|
|
unsigned Column, unsigned Flags,
|
|
|
|
unsigned Isa,
|
|
|
|
unsigned Discriminator,
|
|
|
|
StringRef FileName) {
|
|
|
|
// In case we see two .loc directives in a row, make sure the
|
|
|
|
// first one gets a line entry.
|
2016-10-14 13:47:37 +08:00
|
|
|
MCDwarfLineEntry::Make(this, getCurrentSectionOnly());
|
2013-06-20 05:27:27 +08:00
|
|
|
|
2020-02-14 05:26:21 +08:00
|
|
|
this->MCStreamer::emitDwarfLocDirective(FileNo, Line, Column, Flags, Isa,
|
|
|
|
Discriminator, FileName);
|
2013-06-20 05:27:27 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 22:31:47 +08:00
|
|
|
static const MCExpr *buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A,
|
|
|
|
const MCSymbol *B) {
|
|
|
|
MCContext &Context = OS.getContext();
|
|
|
|
MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
|
|
|
|
const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
|
2014-08-15 22:31:47 +08:00
|
|
|
const MCExpr *AddrDelta =
|
2015-05-30 09:25:56 +08:00
|
|
|
MCBinaryExpr::create(MCBinaryExpr::Sub, ARef, BRef, Context);
|
2014-08-15 22:31:47 +08:00
|
|
|
return AddrDelta;
|
|
|
|
}
|
|
|
|
|
2015-08-07 23:14:08 +08:00
|
|
|
static void emitDwarfSetLineAddr(MCObjectStreamer &OS,
|
|
|
|
MCDwarfLineTableParams Params,
|
|
|
|
int64_t LineDelta, const MCSymbol *Label,
|
|
|
|
int PointerSize) {
|
2014-08-15 22:43:02 +08:00
|
|
|
// emit the sequence to set the address
|
2020-02-15 14:40:47 +08:00
|
|
|
OS.emitIntValue(dwarf::DW_LNS_extended_op, 1);
|
2020-02-14 05:26:21 +08:00
|
|
|
OS.emitULEB128IntValue(PointerSize + 1);
|
2020-02-15 14:40:47 +08:00
|
|
|
OS.emitIntValue(dwarf::DW_LNE_set_address, 1);
|
2020-02-15 11:21:58 +08:00
|
|
|
OS.emitSymbolValue(Label, PointerSize);
|
2014-08-15 22:43:02 +08:00
|
|
|
|
|
|
|
// emit the sequence for the LineDelta (from 1) and a zero address delta.
|
2015-08-07 23:14:08 +08:00
|
|
|
MCDwarfLineAddr::Emit(&OS, Params, LineDelta, 0);
|
2014-08-15 22:43:02 +08:00
|
|
|
}
|
|
|
|
|
2020-02-14 05:26:21 +08:00
|
|
|
void MCObjectStreamer::emitDwarfAdvanceLineAddr(int64_t LineDelta,
|
2010-12-03 08:55:40 +08:00
|
|
|
const MCSymbol *LastLabel,
|
2011-07-14 13:43:07 +08:00
|
|
|
const MCSymbol *Label,
|
|
|
|
unsigned PointerSize) {
|
2010-12-03 08:55:40 +08:00
|
|
|
if (!LastLabel) {
|
2015-08-07 23:14:08 +08:00
|
|
|
emitDwarfSetLineAddr(*this, Assembler->getDWARFLinetableParams(), LineDelta,
|
|
|
|
Label, PointerSize);
|
2010-12-03 08:55:40 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-08-15 22:31:47 +08:00
|
|
|
const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
|
2010-12-03 08:55:40 +08:00
|
|
|
int64_t Res;
|
[MC] Change AsmParser to leverage Assembler during evaluation
Teach AsmParser to check with Assembler for when evaluating constant
expressions. This improves the handing of preprocessor expressions
that must be resolved at parse time. This idiom can be found as
assembling-time assertion checks in source-level assemblers. Note that
this relies on the MCStreamer to keep sufficient tabs on Section /
Fragment information which the MCAsmStreamer does not. As a result the
textual output may fail where the equivalent object generation would
pass. This can most easily be resolved by folding the MCAsmStreamer
and MCObjectStreamer together which is planned for in a separate
patch.
Currently, this feature is only enabled for assembly input, keeping IR
compilation consistent between assembly and object generation.
Reviewers: echristo, rnk, probinson, espindola, peter.smith
Reviewed By: peter.smith
Subscribers: eraman, peter.smith, arichardson, jyknight, hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D45164
llvm-svn: 331218
2018-05-01 03:22:40 +08:00
|
|
|
if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
|
2015-08-07 23:14:08 +08:00
|
|
|
MCDwarfLineAddr::Emit(this, Assembler->getDWARFLinetableParams(), LineDelta,
|
|
|
|
Res);
|
2010-12-03 08:55:40 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-04-18 05:18:16 +08:00
|
|
|
insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
|
2010-12-03 08:55:40 +08:00
|
|
|
}
|
|
|
|
|
2020-02-14 05:26:21 +08:00
|
|
|
void MCObjectStreamer::emitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
|
2010-12-28 13:39:27 +08:00
|
|
|
const MCSymbol *Label) {
|
2014-08-15 22:31:47 +08:00
|
|
|
const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
|
2010-12-28 13:39:27 +08:00
|
|
|
int64_t Res;
|
[MC] Change AsmParser to leverage Assembler during evaluation
Teach AsmParser to check with Assembler for when evaluating constant
expressions. This improves the handing of preprocessor expressions
that must be resolved at parse time. This idiom can be found as
assembling-time assertion checks in source-level assemblers. Note that
this relies on the MCStreamer to keep sufficient tabs on Section /
Fragment information which the MCAsmStreamer does not. As a result the
textual output may fail where the equivalent object generation would
pass. This can most easily be resolved by folding the MCAsmStreamer
and MCObjectStreamer together which is planned for in a separate
patch.
Currently, this feature is only enabled for assembly input, keeping IR
compilation consistent between assembly and object generation.
Reviewers: echristo, rnk, probinson, espindola, peter.smith
Reviewed By: peter.smith
Subscribers: eraman, peter.smith, arichardson, jyknight, hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D45164
llvm-svn: 331218
2018-05-01 03:22:40 +08:00
|
|
|
if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
|
2010-12-28 13:39:27 +08:00
|
|
|
MCDwarfFrameEmitter::EmitAdvanceLoc(*this, Res);
|
|
|
|
return;
|
|
|
|
}
|
2013-04-18 05:18:16 +08:00
|
|
|
insert(new MCDwarfCallFrameFragment(*AddrDelta));
|
2010-12-28 13:39:27 +08:00
|
|
|
}
|
|
|
|
|
2020-04-21 10:28:13 +08:00
|
|
|
void MCObjectStreamer::emitCVLocDirective(unsigned FunctionId, unsigned FileNo,
|
2016-01-29 08:49:42 +08:00
|
|
|
unsigned Line, unsigned Column,
|
|
|
|
bool PrologueEnd, bool IsStmt,
|
2016-09-08 00:15:31 +08:00
|
|
|
StringRef FileName, SMLoc Loc) {
|
2018-08-29 07:25:59 +08:00
|
|
|
// Validate the directive.
|
|
|
|
if (!checkCVLocSection(FunctionId, FileNo, Loc))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Emit a label at the current position and record it in the CodeViewContext.
|
|
|
|
MCSymbol *LineSym = getContext().createTempSymbol();
|
2020-02-15 11:21:58 +08:00
|
|
|
emitLabel(LineSym);
|
2018-08-29 07:25:59 +08:00
|
|
|
getContext().getCVContext().recordCVLoc(getContext(), LineSym, FunctionId,
|
|
|
|
FileNo, Line, Column, PrologueEnd,
|
|
|
|
IsStmt);
|
2016-01-29 08:49:42 +08:00
|
|
|
}
|
|
|
|
|
2020-04-21 10:28:13 +08:00
|
|
|
void MCObjectStreamer::emitCVLinetableDirective(unsigned FunctionId,
|
2016-01-29 08:49:42 +08:00
|
|
|
const MCSymbol *Begin,
|
|
|
|
const MCSymbol *End) {
|
|
|
|
getContext().getCVContext().emitLineTableForFunction(*this, FunctionId, Begin,
|
|
|
|
End);
|
2020-04-21 10:28:13 +08:00
|
|
|
this->MCStreamer::emitCVLinetableDirective(FunctionId, Begin, End);
|
2016-01-29 08:49:42 +08:00
|
|
|
}
|
|
|
|
|
2020-04-21 10:28:13 +08:00
|
|
|
void MCObjectStreamer::emitCVInlineLinetableDirective(
|
2016-01-30 03:24:12 +08:00
|
|
|
unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum,
|
2016-09-08 00:15:31 +08:00
|
|
|
const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) {
|
2016-01-30 03:24:12 +08:00
|
|
|
getContext().getCVContext().emitInlineLineTableForFunction(
|
2016-02-03 01:41:18 +08:00
|
|
|
*this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
|
2016-09-08 00:15:31 +08:00
|
|
|
FnEndSym);
|
2020-04-21 10:28:13 +08:00
|
|
|
this->MCStreamer::emitCVInlineLinetableDirective(
|
2016-09-08 00:15:31 +08:00
|
|
|
PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
|
2016-01-30 03:24:12 +08:00
|
|
|
}
|
|
|
|
|
2020-04-21 10:28:13 +08:00
|
|
|
void MCObjectStreamer::emitCVDefRangeDirective(
|
2016-02-05 09:55:49 +08:00
|
|
|
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
|
|
|
|
StringRef FixedSizePortion) {
|
2018-12-18 05:49:35 +08:00
|
|
|
MCFragment *Frag =
|
|
|
|
getContext().getCVContext().emitDefRange(*this, Ranges, FixedSizePortion);
|
|
|
|
// Attach labels that were pending before we created the defrange fragment to
|
|
|
|
// the beginning of the new fragment.
|
|
|
|
flushPendingLabels(Frag, 0);
|
2020-04-21 10:28:13 +08:00
|
|
|
this->MCStreamer::emitCVDefRangeDirective(Ranges, FixedSizePortion);
|
2016-02-05 09:55:49 +08:00
|
|
|
}
|
|
|
|
|
2020-04-21 10:28:13 +08:00
|
|
|
void MCObjectStreamer::emitCVStringTableDirective() {
|
2016-01-29 08:49:42 +08:00
|
|
|
getContext().getCVContext().emitStringTable(*this);
|
|
|
|
}
|
2020-04-21 10:28:13 +08:00
|
|
|
void MCObjectStreamer::emitCVFileChecksumsDirective() {
|
2016-01-29 08:49:42 +08:00
|
|
|
getContext().getCVContext().emitFileChecksums(*this);
|
|
|
|
}
|
|
|
|
|
2020-04-21 10:28:13 +08:00
|
|
|
void MCObjectStreamer::emitCVFileChecksumOffsetDirective(unsigned FileNo) {
|
2017-09-20 02:14:45 +08:00
|
|
|
getContext().getCVContext().emitFileChecksumOffset(*this, FileNo);
|
|
|
|
}
|
2016-01-29 08:49:42 +08:00
|
|
|
|
2020-02-15 10:16:24 +08:00
|
|
|
void MCObjectStreamer::emitBytes(StringRef Data) {
|
2016-10-14 13:47:37 +08:00
|
|
|
MCDwarfLineEntry::Make(this, getCurrentSectionOnly());
|
2015-06-27 09:54:17 +08:00
|
|
|
MCDataFragment *DF = getOrCreateDataFragment();
|
|
|
|
flushPendingLabels(DF, DF->getContents().size());
|
|
|
|
DF->getContents().append(Data.begin(), Data.end());
|
2012-10-04 21:12:43 +08:00
|
|
|
}
|
|
|
|
|
2020-02-15 11:21:58 +08:00
|
|
|
void MCObjectStreamer::emitValueToAlignment(unsigned ByteAlignment,
|
2012-10-04 21:12:43 +08:00
|
|
|
int64_t Value,
|
|
|
|
unsigned ValueSize,
|
|
|
|
unsigned MaxBytesToEmit) {
|
|
|
|
if (MaxBytesToEmit == 0)
|
|
|
|
MaxBytesToEmit = ByteAlignment;
|
2013-04-18 05:18:16 +08:00
|
|
|
insert(new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit));
|
2012-10-04 21:12:43 +08:00
|
|
|
|
|
|
|
// Update the maximum alignment on the current section if necessary.
|
2016-10-14 13:47:37 +08:00
|
|
|
MCSection *CurSec = getCurrentSectionOnly();
|
2015-05-22 05:02:35 +08:00
|
|
|
if (ByteAlignment > CurSec->getAlignment())
|
2019-09-27 20:54:21 +08:00
|
|
|
CurSec->setAlignment(Align(ByteAlignment));
|
2012-10-04 21:12:43 +08:00
|
|
|
}
|
|
|
|
|
2020-02-15 11:21:58 +08:00
|
|
|
void MCObjectStreamer::emitCodeAlignment(unsigned ByteAlignment,
|
2012-10-04 21:12:43 +08:00
|
|
|
unsigned MaxBytesToEmit) {
|
2020-02-15 11:21:58 +08:00
|
|
|
emitValueToAlignment(ByteAlignment, 0, 1, MaxBytesToEmit);
|
2012-10-04 21:12:43 +08:00
|
|
|
cast<MCAlignFragment>(getCurrentFragment())->setEmitNops(true);
|
|
|
|
}
|
|
|
|
|
2015-11-05 07:59:18 +08:00
|
|
|
void MCObjectStreamer::emitValueToOffset(const MCExpr *Offset,
|
2016-12-14 18:43:58 +08:00
|
|
|
unsigned char Value,
|
|
|
|
SMLoc Loc) {
|
|
|
|
insert(new MCOrgFragment(*Offset, Value, Loc));
|
2010-12-02 13:59:38 +08:00
|
|
|
}
|
|
|
|
|
2016-08-23 00:18:42 +08:00
|
|
|
// Associate DTPRel32 fixup with data and resize data area
|
2020-02-15 11:21:58 +08:00
|
|
|
void MCObjectStreamer::emitDTPRel32Value(const MCExpr *Value) {
|
2016-08-23 00:18:42 +08:00
|
|
|
MCDataFragment *DF = getOrCreateDataFragment();
|
|
|
|
flushPendingLabels(DF, DF->getContents().size());
|
|
|
|
|
|
|
|
DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
|
|
|
|
Value, FK_DTPRel_4));
|
|
|
|
DF->getContents().resize(DF->getContents().size() + 4, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Associate DTPRel64 fixup with data and resize data area
|
2020-02-15 11:21:58 +08:00
|
|
|
void MCObjectStreamer::emitDTPRel64Value(const MCExpr *Value) {
|
2016-08-23 00:18:42 +08:00
|
|
|
MCDataFragment *DF = getOrCreateDataFragment();
|
|
|
|
flushPendingLabels(DF, DF->getContents().size());
|
|
|
|
|
|
|
|
DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
|
|
|
|
Value, FK_DTPRel_8));
|
|
|
|
DF->getContents().resize(DF->getContents().size() + 8, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Associate TPRel32 fixup with data and resize data area
|
2020-02-15 11:21:58 +08:00
|
|
|
void MCObjectStreamer::emitTPRel32Value(const MCExpr *Value) {
|
2016-08-23 00:18:42 +08:00
|
|
|
MCDataFragment *DF = getOrCreateDataFragment();
|
|
|
|
flushPendingLabels(DF, DF->getContents().size());
|
|
|
|
|
|
|
|
DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
|
|
|
|
Value, FK_TPRel_4));
|
|
|
|
DF->getContents().resize(DF->getContents().size() + 4, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Associate TPRel64 fixup with data and resize data area
|
2020-02-15 11:21:58 +08:00
|
|
|
void MCObjectStreamer::emitTPRel64Value(const MCExpr *Value) {
|
2016-08-23 00:18:42 +08:00
|
|
|
MCDataFragment *DF = getOrCreateDataFragment();
|
|
|
|
flushPendingLabels(DF, DF->getContents().size());
|
|
|
|
|
|
|
|
DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
|
|
|
|
Value, FK_TPRel_8));
|
|
|
|
DF->getContents().resize(DF->getContents().size() + 8, 0);
|
|
|
|
}
|
|
|
|
|
2011-11-24 06:18:04 +08:00
|
|
|
// Associate GPRel32 fixup with data and resize data area
|
2020-02-15 11:21:58 +08:00
|
|
|
void MCObjectStreamer::emitGPRel32Value(const MCExpr *Value) {
|
2011-11-24 06:18:04 +08:00
|
|
|
MCDataFragment *DF = getOrCreateDataFragment();
|
2015-06-27 09:54:17 +08:00
|
|
|
flushPendingLabels(DF, DF->getContents().size());
|
2011-11-24 06:18:04 +08:00
|
|
|
|
2017-04-04 05:50:04 +08:00
|
|
|
DF->getFixups().push_back(
|
|
|
|
MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
|
2011-11-24 06:18:04 +08:00
|
|
|
DF->getContents().resize(DF->getContents().size() + 4, 0);
|
|
|
|
}
|
|
|
|
|
2016-08-23 00:18:42 +08:00
|
|
|
// Associate GPRel64 fixup with data and resize data area
|
2020-02-15 11:21:58 +08:00
|
|
|
void MCObjectStreamer::emitGPRel64Value(const MCExpr *Value) {
|
2012-08-22 08:49:30 +08:00
|
|
|
MCDataFragment *DF = getOrCreateDataFragment();
|
2015-06-27 09:54:17 +08:00
|
|
|
flushPendingLabels(DF, DF->getContents().size());
|
2012-08-22 08:49:30 +08:00
|
|
|
|
2017-04-04 05:50:04 +08:00
|
|
|
DF->getFixups().push_back(
|
|
|
|
MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
|
2012-08-22 08:49:30 +08:00
|
|
|
DF->getContents().resize(DF->getContents().size() + 8, 0);
|
|
|
|
}
|
|
|
|
|
2020-02-16 00:52:56 +08:00
|
|
|
bool MCObjectStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
|
2018-06-06 17:40:06 +08:00
|
|
|
const MCExpr *Expr, SMLoc Loc,
|
|
|
|
const MCSubtargetInfo &STI) {
|
2016-01-20 07:05:27 +08:00
|
|
|
Optional<MCFixupKind> MaybeKind = Assembler->getBackend().getFixupKind(Name);
|
|
|
|
if (!MaybeKind.hasValue())
|
2015-11-12 21:33:00 +08:00
|
|
|
return true;
|
|
|
|
|
2016-01-20 07:05:27 +08:00
|
|
|
MCFixupKind Kind = *MaybeKind;
|
|
|
|
|
2015-11-12 21:33:00 +08:00
|
|
|
if (Expr == nullptr)
|
|
|
|
Expr =
|
|
|
|
MCSymbolRefExpr::create(getContext().createTempSymbol(), getContext());
|
2018-11-22 00:28:39 +08:00
|
|
|
|
|
|
|
MCDataFragment *DF = getOrCreateDataFragment(&STI);
|
|
|
|
flushPendingLabels(DF, DF->getContents().size());
|
|
|
|
|
|
|
|
int64_t OffsetValue;
|
|
|
|
if (Offset.evaluateAsAbsolute(OffsetValue)) {
|
|
|
|
if (OffsetValue < 0)
|
|
|
|
llvm_unreachable(".reloc offset is negative");
|
|
|
|
DF->getFixups().push_back(MCFixup::create(OffsetValue, Expr, Kind, Loc));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Offset.getKind() != llvm::MCExpr::SymbolRef)
|
|
|
|
llvm_unreachable(".reloc offset is not absolute nor a label");
|
|
|
|
|
|
|
|
const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(Offset);
|
|
|
|
if (SRE.getSymbol().isDefined()) {
|
|
|
|
DF->getFixups().push_back(MCFixup::create(SRE.getSymbol().getOffset(),
|
|
|
|
Expr, Kind, Loc));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PendingFixups.emplace_back(&SRE.getSymbol(), DF,
|
|
|
|
MCFixup::create(-1, Expr, Kind, Loc));
|
2015-11-12 21:33:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-28 13:57:48 +08:00
|
|
|
void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
|
|
|
|
SMLoc Loc) {
|
|
|
|
MCDataFragment *DF = getOrCreateDataFragment();
|
|
|
|
flushPendingLabels(DF, DF->getContents().size());
|
|
|
|
|
2018-01-10 03:29:33 +08:00
|
|
|
assert(getCurrentSectionOnly() && "need a section");
|
2018-05-19 01:45:48 +08:00
|
|
|
insert(new MCFillFragment(FillValue, 1, NumBytes, Loc));
|
2016-05-28 13:57:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
|
|
|
|
int64_t Expr, SMLoc Loc) {
|
|
|
|
int64_t IntNumValues;
|
2018-05-19 01:45:48 +08:00
|
|
|
// Do additional checking now if we can resolve the value.
|
|
|
|
if (NumValues.evaluateAsAbsolute(IntNumValues, getAssemblerPtr())) {
|
|
|
|
if (IntNumValues < 0) {
|
|
|
|
getContext().getSourceManager()->PrintMessage(
|
|
|
|
Loc, SourceMgr::DK_Warning,
|
|
|
|
"'.fill' directive with negative repeat count has no effect");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Emit now if we can for better errors.
|
|
|
|
int64_t NonZeroSize = Size > 4 ? 4 : Size;
|
|
|
|
Expr &= ~0ULL >> (64 - NonZeroSize * 8);
|
|
|
|
for (uint64_t i = 0, e = IntNumValues; i != e; ++i) {
|
2020-02-15 14:40:47 +08:00
|
|
|
emitIntValue(Expr, NonZeroSize);
|
2018-05-19 01:45:48 +08:00
|
|
|
if (NonZeroSize < Size)
|
2020-02-15 14:40:47 +08:00
|
|
|
emitIntValue(0, Size - NonZeroSize);
|
2018-05-19 01:45:48 +08:00
|
|
|
}
|
2016-05-28 13:57:48 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-19 01:45:48 +08:00
|
|
|
// Otherwise emit as fragment.
|
|
|
|
MCDataFragment *DF = getOrCreateDataFragment();
|
|
|
|
flushPendingLabels(DF, DF->getContents().size());
|
2016-05-28 13:57:48 +08:00
|
|
|
|
2018-05-19 01:45:48 +08:00
|
|
|
assert(getCurrentSectionOnly() && "need a section");
|
|
|
|
insert(new MCFillFragment(Expr, Size, NumValues, Loc));
|
2016-05-28 13:57:48 +08:00
|
|
|
}
|
|
|
|
|
2020-02-16 00:52:56 +08:00
|
|
|
void MCObjectStreamer::emitFileDirective(StringRef Filename) {
|
2017-03-04 05:22:06 +08:00
|
|
|
getAssembler().addFileName(Filename);
|
|
|
|
}
|
|
|
|
|
2020-02-16 00:52:56 +08:00
|
|
|
void MCObjectStreamer::emitAddrsig() {
|
2018-07-18 06:17:18 +08:00
|
|
|
getAssembler().getWriter().emitAddrsigSection();
|
|
|
|
}
|
|
|
|
|
2020-02-16 00:52:56 +08:00
|
|
|
void MCObjectStreamer::emitAddrsigSym(const MCSymbol *Sym) {
|
2018-07-18 06:17:18 +08:00
|
|
|
getAssembler().registerSymbol(*Sym);
|
|
|
|
getAssembler().getWriter().addAddrsigSymbol(Sym);
|
|
|
|
}
|
|
|
|
|
2020-04-21 10:28:13 +08:00
|
|
|
void MCObjectStreamer::finishImpl() {
|
2018-07-11 20:30:35 +08:00
|
|
|
getContext().RemapDebugPaths();
|
2018-07-10 22:41:54 +08:00
|
|
|
|
2011-12-10 02:09:40 +08:00
|
|
|
// If we are generating dwarf for assembly source files dump out the sections.
|
|
|
|
if (getContext().getGenDwarfForAssembly())
|
2014-04-01 15:35:52 +08:00
|
|
|
MCGenDwarfInfo::Emit(this);
|
|
|
|
|
|
|
|
// Dump out the dwarf file & directory tables and line tables.
|
2015-08-07 23:14:08 +08:00
|
|
|
MCDwarfLineTable::Emit(this, getAssembler().getDWARFLinetableParams());
|
2011-12-10 02:09:40 +08:00
|
|
|
|
[ MC ] Match labels to existing fragments even when switching sections.
(This commit restores the original branch (4272372c571) and applies an
additional change dropped from the original in a bad merge. This change
should address the previous bot failures. Both changes reviewed by pete.)
Summary:
This commit builds upon Derek Schuff's 2014 commit for attaching labels to
existing fragments ( Diff Revision: http://reviews.llvm.org/D5915 )
When temporary labels appear ahead of a fragment, MCObjectStreamer will
track the temporary label symbol in a "Pending Labels" list. Labels are
associated with fragments when a real fragment arrives; otherwise, an empty
data fragment will be created if the streamer's section changes or if the
stream finishes.
This commit moves the "Pending Labels" list into each MCStream, so that
this label-fragment matching process is resilient to section changes. If
the streamer emits a label in a new section, switches to another section to
do other work, then switches back to the first section and emits a
fragment, that initial label will be associated with this new fragment.
Labels will only receive empty data fragments in the case where no other
fragment exists for that section.
The downstream effects of this can be seen in Mach-O relocations. The
previous approach could produce local section relocations and external
symbol relocations for the same data in an object file, and this mix of
relocation types resulted in problems in the ld64 Mach-O linker. This
commit ensures relocations triggered by temporary labels are consistent.
Reviewers: pete, ab, dschuff
Reviewed By: pete, dschuff
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71368
2019-12-12 02:42:37 +08:00
|
|
|
// Update any remaining pending labels with empty data fragments.
|
2018-07-10 23:32:17 +08:00
|
|
|
flushPendingLabels();
|
[ MC ] Match labels to existing fragments even when switching sections.
(This commit restores the original branch (4272372c571) and applies an
additional change dropped from the original in a bad merge. This change
should address the previous bot failures. Both changes reviewed by pete.)
Summary:
This commit builds upon Derek Schuff's 2014 commit for attaching labels to
existing fragments ( Diff Revision: http://reviews.llvm.org/D5915 )
When temporary labels appear ahead of a fragment, MCObjectStreamer will
track the temporary label symbol in a "Pending Labels" list. Labels are
associated with fragments when a real fragment arrives; otherwise, an empty
data fragment will be created if the streamer's section changes or if the
stream finishes.
This commit moves the "Pending Labels" list into each MCStream, so that
this label-fragment matching process is resilient to section changes. If
the streamer emits a label in a new section, switches to another section to
do other work, then switches back to the first section and emits a
fragment, that initial label will be associated with this new fragment.
Labels will only receive empty data fragments in the case where no other
fragment exists for that section.
The downstream effects of this can be seen in Mach-O relocations. The
previous approach could produce local section relocations and external
symbol relocations for the same data in an object file, and this mix of
relocation types resulted in problems in the ld64 Mach-O linker. This
commit ensures relocations triggered by temporary labels are consistent.
Reviewers: pete, ab, dschuff
Reviewed By: pete, dschuff
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71368
2019-12-12 02:42:37 +08:00
|
|
|
|
2018-11-22 00:28:39 +08:00
|
|
|
resolvePendingFixups();
|
2010-06-17 04:04:25 +08:00
|
|
|
getAssembler().Finish();
|
|
|
|
}
|