2014-04-27 11:48:12 +08:00
|
|
|
//===-- X86WinCOFFStreamer.cpp - X86 Target WinCOFF Streamer ----*- C++ -*-===//
|
|
|
|
//
|
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
|
2014-04-27 11:48:12 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "X86MCTargetDesc.h"
|
[codeview] Implement FPO data assembler directives
Summary:
This adds a set of new directives that describe 32-bit x86 prologues.
The directives are limited and do not expose the full complexity of
codeview FPO data. They are merely a convenience for the compiler to
generate more readable assembly so we don't need to generate tons of
labels in CodeGen. If our prologue emission changes in the future, we
can change the set of available directives to suit our needs. These are
modelled after the .seh_ directives, which use a different format that
interacts with exception handling.
The directives are:
.cv_fpo_proc _foo
.cv_fpo_pushreg ebp/ebx/etc
.cv_fpo_setframe ebp/esi/etc
.cv_fpo_stackalloc 200
.cv_fpo_endprologue
.cv_fpo_endproc
.cv_fpo_data _foo
I tried to follow the implementation of ARM EHABI CFI directives by
sinking most directives out of MCStreamer and into X86TargetStreamer.
This helps avoid polluting non-X86 code with WinCOFF specific logic.
I used cdb to confirm that this can show locals in parent CSRs in a few
cases, most importantly the one where we use ESI as a frame pointer,
i.e. the one in http://crbug.com/756153#c28
Once we have cdb integration in debuginfo-tests, we can add integration
tests there.
Reviewers: majnemer, hans
Subscribers: aemerson, mgorny, kristof.beyls, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D38776
llvm-svn: 315513
2017-10-12 05:24:33 +08:00
|
|
|
#include "X86TargetStreamer.h"
|
2017-10-11 09:57:21 +08:00
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
2017-10-12 07:34:47 +08:00
|
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
2018-05-19 02:26:45 +08:00
|
|
|
#include "llvm/MC/MCObjectWriter.h"
|
2014-08-07 10:59:41 +08:00
|
|
|
#include "llvm/MC/MCWin64EH.h"
|
2014-04-27 11:48:12 +08:00
|
|
|
#include "llvm/MC/MCWinCOFFStreamer.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class X86WinCOFFStreamer : public MCWinCOFFStreamer {
|
2014-08-07 10:59:41 +08:00
|
|
|
Win64EH::UnwindEmitter EHStreamer;
|
2014-04-27 11:48:12 +08:00
|
|
|
public:
|
2017-10-11 09:57:21 +08:00
|
|
|
X86WinCOFFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> AB,
|
2018-05-19 02:26:45 +08:00
|
|
|
std::unique_ptr<MCCodeEmitter> CE,
|
|
|
|
std::unique_ptr<MCObjectWriter> OW)
|
|
|
|
: MCWinCOFFStreamer(C, std::move(AB), std::move(CE), std::move(OW)) {}
|
2014-04-27 11:48:12 +08:00
|
|
|
|
2017-10-10 09:26:25 +08:00
|
|
|
void EmitWinEHHandlerData(SMLoc Loc) override;
|
2016-10-11 06:49:37 +08:00
|
|
|
void EmitWindowsUnwindTables() override;
|
[codeview] Implement FPO data assembler directives
Summary:
This adds a set of new directives that describe 32-bit x86 prologues.
The directives are limited and do not expose the full complexity of
codeview FPO data. They are merely a convenience for the compiler to
generate more readable assembly so we don't need to generate tons of
labels in CodeGen. If our prologue emission changes in the future, we
can change the set of available directives to suit our needs. These are
modelled after the .seh_ directives, which use a different format that
interacts with exception handling.
The directives are:
.cv_fpo_proc _foo
.cv_fpo_pushreg ebp/ebx/etc
.cv_fpo_setframe ebp/esi/etc
.cv_fpo_stackalloc 200
.cv_fpo_endprologue
.cv_fpo_endproc
.cv_fpo_data _foo
I tried to follow the implementation of ARM EHABI CFI directives by
sinking most directives out of MCStreamer and into X86TargetStreamer.
This helps avoid polluting non-X86 code with WinCOFF specific logic.
I used cdb to confirm that this can show locals in parent CSRs in a few
cases, most importantly the one where we use ESI as a frame pointer,
i.e. the one in http://crbug.com/756153#c28
Once we have cdb integration in debuginfo-tests, we can add integration
tests there.
Reviewers: majnemer, hans
Subscribers: aemerson, mgorny, kristof.beyls, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D38776
llvm-svn: 315513
2017-10-12 05:24:33 +08:00
|
|
|
void EmitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc) override;
|
2014-04-27 11:48:12 +08:00
|
|
|
void FinishImpl() override;
|
|
|
|
};
|
|
|
|
|
2017-10-10 09:26:25 +08:00
|
|
|
void X86WinCOFFStreamer::EmitWinEHHandlerData(SMLoc Loc) {
|
|
|
|
MCStreamer::EmitWinEHHandlerData(Loc);
|
2014-04-27 11:48:12 +08:00
|
|
|
|
|
|
|
// We have to emit the unwind info now, because this directive
|
|
|
|
// actually switches to the .xdata section!
|
2014-08-07 10:59:41 +08:00
|
|
|
EHStreamer.EmitUnwindInfo(*this, getCurrentWinFrameInfo());
|
2014-04-27 11:48:12 +08:00
|
|
|
}
|
|
|
|
|
2014-08-04 02:51:26 +08:00
|
|
|
void X86WinCOFFStreamer::EmitWindowsUnwindTables() {
|
|
|
|
if (!getNumWinFrameInfos())
|
|
|
|
return;
|
2014-08-07 10:59:41 +08:00
|
|
|
EHStreamer.Emit(*this);
|
2014-08-04 02:51:26 +08:00
|
|
|
}
|
|
|
|
|
[codeview] Implement FPO data assembler directives
Summary:
This adds a set of new directives that describe 32-bit x86 prologues.
The directives are limited and do not expose the full complexity of
codeview FPO data. They are merely a convenience for the compiler to
generate more readable assembly so we don't need to generate tons of
labels in CodeGen. If our prologue emission changes in the future, we
can change the set of available directives to suit our needs. These are
modelled after the .seh_ directives, which use a different format that
interacts with exception handling.
The directives are:
.cv_fpo_proc _foo
.cv_fpo_pushreg ebp/ebx/etc
.cv_fpo_setframe ebp/esi/etc
.cv_fpo_stackalloc 200
.cv_fpo_endprologue
.cv_fpo_endproc
.cv_fpo_data _foo
I tried to follow the implementation of ARM EHABI CFI directives by
sinking most directives out of MCStreamer and into X86TargetStreamer.
This helps avoid polluting non-X86 code with WinCOFF specific logic.
I used cdb to confirm that this can show locals in parent CSRs in a few
cases, most importantly the one where we use ESI as a frame pointer,
i.e. the one in http://crbug.com/756153#c28
Once we have cdb integration in debuginfo-tests, we can add integration
tests there.
Reviewers: majnemer, hans
Subscribers: aemerson, mgorny, kristof.beyls, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D38776
llvm-svn: 315513
2017-10-12 05:24:33 +08:00
|
|
|
void X86WinCOFFStreamer::EmitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc) {
|
|
|
|
X86TargetStreamer *XTS =
|
|
|
|
static_cast<X86TargetStreamer *>(getTargetStreamer());
|
|
|
|
XTS->emitFPOData(ProcSym, Loc);
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:48:12 +08:00
|
|
|
void X86WinCOFFStreamer::FinishImpl() {
|
2014-05-12 21:30:10 +08:00
|
|
|
EmitFrames(nullptr);
|
2014-07-14 03:03:36 +08:00
|
|
|
EmitWindowsUnwindTables();
|
2014-04-27 11:48:12 +08:00
|
|
|
|
|
|
|
MCWinCOFFStreamer::FinishImpl();
|
|
|
|
}
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2014-04-27 11:48:12 +08:00
|
|
|
|
2017-10-11 09:57:21 +08:00
|
|
|
MCStreamer *llvm::createX86WinCOFFStreamer(MCContext &C,
|
|
|
|
std::unique_ptr<MCAsmBackend> &&AB,
|
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> &&CE,
|
|
|
|
bool RelaxAll,
|
2015-12-22 06:09:27 +08:00
|
|
|
bool IncrementalLinkerCompatible) {
|
2017-10-12 07:34:47 +08:00
|
|
|
X86WinCOFFStreamer *S =
|
2018-05-19 02:26:45 +08:00
|
|
|
new X86WinCOFFStreamer(C, std::move(AB), std::move(CE), std::move(OW));
|
2014-04-27 11:48:12 +08:00
|
|
|
S->getAssembler().setRelaxAll(RelaxAll);
|
2015-12-22 06:09:27 +08:00
|
|
|
S->getAssembler().setIncrementalLinkerCompatible(IncrementalLinkerCompatible);
|
2014-04-27 11:48:12 +08:00
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|