Skip to content

Commit

Permalink
Defer call to InitSections until after MCContext has been initialized…
Browse files Browse the repository at this point in the history
…. If

InitSections is called before the MCContext is initialized it could cause
duplicate temporary symbols to be emitted later (after context initialization
resets the temporary label counter).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169785 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
lhames committed Dec 10, 2012
1 parent 079e081 commit 07f6a4f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions include/llvm/MC/MCStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ namespace llvm {
SmallVector<std::pair<const MCSection *,
const MCSection *>, 4> SectionStack;

bool AutoInitSections;

protected:
MCStreamer(MCContext &Ctx);

Expand Down Expand Up @@ -214,6 +216,17 @@ namespace llvm {
SectionStack.back().first = Section;
}

/// Initialize the streamer.
void InitStreamer() {
if (AutoInitSections)
InitSections();
}

/// Tell this MCStreamer to call InitSections upon initialization.
void setAutoInitSections(bool AutoInitSections) {
this->AutoInitSections = AutoInitSections;
}

/// InitSections - Create the default sections and set the initial one.
virtual void InitSections() = 0;

Expand Down
2 changes: 2 additions & 0 deletions lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
}

bool AsmPrinter::doInitialization(Module &M) {
OutStreamer.InitStreamer();

MMI = getAnalysisIfAvailable<MachineModuleInfo>();
MMI->AnalyzeModule(M);

Expand Down
2 changes: 1 addition & 1 deletion lib/CodeGen/LLVMTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
*Context, *MAB, Out,
MCE, hasMCRelaxAll(),
hasMCNoExecStack()));
AsmStreamer.get()->InitSections();
AsmStreamer.get()->setAutoInitSections(true);
break;
}
case CGFT_Null:
Expand Down
3 changes: 2 additions & 1 deletion lib/MC/MCStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ using namespace llvm;

MCStreamer::MCStreamer(MCContext &Ctx)
: Context(Ctx), EmitEHFrame(true), EmitDebugFrame(false),
CurrentW64UnwindInfo(0), LastSymbol(0) {
CurrentW64UnwindInfo(0), LastSymbol(0),
AutoInitSections(false) {
const MCSection *section = NULL;
SectionStack.push_back(std::make_pair(section, section));
}
Expand Down

0 comments on commit 07f6a4f

Please sign in to comment.