2019-07-10 03:21:01 +08:00
|
|
|
//===- lib/MC/MCXCOFFStreamer.cpp - XCOFF Object Output -------------------===//
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file assembles .s files and emits XCOFF .o object files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-02-27 23:43:27 +08:00
|
|
|
#include "llvm/MC/MCXCOFFStreamer.h"
|
2019-08-27 23:14:45 +08:00
|
|
|
#include "llvm/BinaryFormat/XCOFF.h"
|
2019-07-10 03:21:01 +08:00
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
|
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
2020-02-27 23:43:27 +08:00
|
|
|
#include "llvm/MC/MCDirectives.h"
|
2019-07-10 03:21:01 +08:00
|
|
|
#include "llvm/MC/MCObjectWriter.h"
|
2019-08-21 06:03:18 +08:00
|
|
|
#include "llvm/MC/MCSymbolXCOFF.h"
|
2019-07-10 03:21:01 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
MCXCOFFStreamer::MCXCOFFStreamer(MCContext &Context,
|
|
|
|
std::unique_ptr<MCAsmBackend> MAB,
|
|
|
|
std::unique_ptr<MCObjectWriter> OW,
|
|
|
|
std::unique_ptr<MCCodeEmitter> Emitter)
|
|
|
|
: MCObjectStreamer(Context, std::move(MAB), std::move(OW),
|
|
|
|
std::move(Emitter)) {}
|
|
|
|
|
2020-02-15 10:16:24 +08:00
|
|
|
bool MCXCOFFStreamer::emitSymbolAttribute(MCSymbol *Sym,
|
2019-07-10 03:21:01 +08:00
|
|
|
MCSymbolAttr Attribute) {
|
[XCOFF] Output object text section header and symbol entry for program code.
This is remaining part of rG41ca91f2995b: [AIX][XCOFF] Output XCOFF
object text section header and symbol entry for rogram code.
SUMMARY:
Original form of this patch is provided by Stefan Pintillie.
1. The patch try to output program code section header , symbol entry for
program code (PR) and Instruction into the raw text section.
2. The patch include how to alignment and layout the CSection in the text
section.
3. The patch also reorganize the code , put some codes into a function.
(XCOFFObjectWriter::writeSymbolTableEntryForControlSection)
Additional: We can not add raw data of text section test in the patch, If want
to output raw text section data,it need a function description patch first.
Reviewers: hubert.reinterpretcast, sfertile, jasonliu, xingxue.
Subscribers: wuzish, nemanjai, hiraditya, MaskRay, jsjji.
Differential Revision: https://reviews.llvm.org/D66969
llvm-svn: 374923
2019-10-16 01:40:41 +08:00
|
|
|
auto *Symbol = cast<MCSymbolXCOFF>(Sym);
|
|
|
|
getAssembler().registerSymbol(*Symbol);
|
|
|
|
|
|
|
|
switch (Attribute) {
|
|
|
|
case MCSA_Global:
|
|
|
|
Symbol->setStorageClass(XCOFF::C_EXT);
|
|
|
|
Symbol->setExternal(true);
|
|
|
|
break;
|
2020-02-27 23:43:27 +08:00
|
|
|
case MCSA_LGlobal:
|
|
|
|
Symbol->setStorageClass(XCOFF::C_HIDEXT);
|
|
|
|
Symbol->setExternal(true);
|
|
|
|
break;
|
[XCOFF] Output object text section header and symbol entry for program code.
This is remaining part of rG41ca91f2995b: [AIX][XCOFF] Output XCOFF
object text section header and symbol entry for rogram code.
SUMMARY:
Original form of this patch is provided by Stefan Pintillie.
1. The patch try to output program code section header , symbol entry for
program code (PR) and Instruction into the raw text section.
2. The patch include how to alignment and layout the CSection in the text
section.
3. The patch also reorganize the code , put some codes into a function.
(XCOFFObjectWriter::writeSymbolTableEntryForControlSection)
Additional: We can not add raw data of text section test in the patch, If want
to output raw text section data,it need a function description patch first.
Reviewers: hubert.reinterpretcast, sfertile, jasonliu, xingxue.
Subscribers: wuzish, nemanjai, hiraditya, MaskRay, jsjji.
Differential Revision: https://reviews.llvm.org/D66969
llvm-svn: 374923
2019-10-16 01:40:41 +08:00
|
|
|
default:
|
|
|
|
report_fatal_error("Not implemented yet.");
|
|
|
|
}
|
|
|
|
return true;
|
2019-07-10 03:21:01 +08:00
|
|
|
}
|
|
|
|
|
2020-02-15 10:16:24 +08:00
|
|
|
void MCXCOFFStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
2019-07-10 03:21:01 +08:00
|
|
|
unsigned ByteAlignment) {
|
2019-08-21 06:03:18 +08:00
|
|
|
getAssembler().registerSymbol(*Symbol);
|
|
|
|
Symbol->setExternal(cast<MCSymbolXCOFF>(Symbol)->getStorageClass() !=
|
|
|
|
XCOFF::C_HIDEXT);
|
|
|
|
Symbol->setCommon(Size, ByteAlignment);
|
|
|
|
|
|
|
|
// Emit the alignment and storage for the variable to the section.
|
2020-02-15 11:21:58 +08:00
|
|
|
emitValueToAlignment(ByteAlignment);
|
2020-02-16 00:52:56 +08:00
|
|
|
emitZeros(Size);
|
2019-07-10 03:21:01 +08:00
|
|
|
}
|
|
|
|
|
2020-02-15 10:16:24 +08:00
|
|
|
void MCXCOFFStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol,
|
2019-07-10 03:21:01 +08:00
|
|
|
uint64_t Size, unsigned ByteAlignment,
|
|
|
|
SMLoc Loc) {
|
|
|
|
report_fatal_error("Zero fill not implemented for XCOFF.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCXCOFFStreamer::EmitInstToData(const MCInst &Inst,
|
[XCOFF] Output object text section header and symbol entry for program code.
This is remaining part of rG41ca91f2995b: [AIX][XCOFF] Output XCOFF
object text section header and symbol entry for rogram code.
SUMMARY:
Original form of this patch is provided by Stefan Pintillie.
1. The patch try to output program code section header , symbol entry for
program code (PR) and Instruction into the raw text section.
2. The patch include how to alignment and layout the CSection in the text
section.
3. The patch also reorganize the code , put some codes into a function.
(XCOFFObjectWriter::writeSymbolTableEntryForControlSection)
Additional: We can not add raw data of text section test in the patch, If want
to output raw text section data,it need a function description patch first.
Reviewers: hubert.reinterpretcast, sfertile, jasonliu, xingxue.
Subscribers: wuzish, nemanjai, hiraditya, MaskRay, jsjji.
Differential Revision: https://reviews.llvm.org/D66969
llvm-svn: 374923
2019-10-16 01:40:41 +08:00
|
|
|
const MCSubtargetInfo &STI) {
|
|
|
|
MCAssembler &Assembler = getAssembler();
|
|
|
|
SmallVector<MCFixup, 4> Fixups;
|
|
|
|
SmallString<256> Code;
|
|
|
|
raw_svector_ostream VecOS(Code);
|
|
|
|
Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
|
|
|
|
|
2020-01-30 23:50:49 +08:00
|
|
|
// Add the fixups and data.
|
[XCOFF] Output object text section header and symbol entry for program code.
This is remaining part of rG41ca91f2995b: [AIX][XCOFF] Output XCOFF
object text section header and symbol entry for rogram code.
SUMMARY:
Original form of this patch is provided by Stefan Pintillie.
1. The patch try to output program code section header , symbol entry for
program code (PR) and Instruction into the raw text section.
2. The patch include how to alignment and layout the CSection in the text
section.
3. The patch also reorganize the code , put some codes into a function.
(XCOFFObjectWriter::writeSymbolTableEntryForControlSection)
Additional: We can not add raw data of text section test in the patch, If want
to output raw text section data,it need a function description patch first.
Reviewers: hubert.reinterpretcast, sfertile, jasonliu, xingxue.
Subscribers: wuzish, nemanjai, hiraditya, MaskRay, jsjji.
Differential Revision: https://reviews.llvm.org/D66969
llvm-svn: 374923
2019-10-16 01:40:41 +08:00
|
|
|
MCDataFragment *DF = getOrCreateDataFragment(&STI);
|
2020-01-30 23:50:49 +08:00
|
|
|
const size_t ContentsSize = DF->getContents().size();
|
|
|
|
auto &DataFragmentFixups = DF->getFixups();
|
|
|
|
for (auto &Fixup : Fixups) {
|
|
|
|
Fixup.setOffset(Fixup.getOffset() + ContentsSize);
|
|
|
|
DataFragmentFixups.push_back(Fixup);
|
|
|
|
}
|
|
|
|
|
[XCOFF] Output object text section header and symbol entry for program code.
This is remaining part of rG41ca91f2995b: [AIX][XCOFF] Output XCOFF
object text section header and symbol entry for rogram code.
SUMMARY:
Original form of this patch is provided by Stefan Pintillie.
1. The patch try to output program code section header , symbol entry for
program code (PR) and Instruction into the raw text section.
2. The patch include how to alignment and layout the CSection in the text
section.
3. The patch also reorganize the code , put some codes into a function.
(XCOFFObjectWriter::writeSymbolTableEntryForControlSection)
Additional: We can not add raw data of text section test in the patch, If want
to output raw text section data,it need a function description patch first.
Reviewers: hubert.reinterpretcast, sfertile, jasonliu, xingxue.
Subscribers: wuzish, nemanjai, hiraditya, MaskRay, jsjji.
Differential Revision: https://reviews.llvm.org/D66969
llvm-svn: 374923
2019-10-16 01:40:41 +08:00
|
|
|
DF->setHasInstructions(STI);
|
|
|
|
DF->getContents().append(Code.begin(), Code.end());
|
2019-07-10 03:21:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MCStreamer *llvm::createXCOFFStreamer(MCContext &Context,
|
|
|
|
std::unique_ptr<MCAsmBackend> &&MAB,
|
|
|
|
std::unique_ptr<MCObjectWriter> &&OW,
|
|
|
|
std::unique_ptr<MCCodeEmitter> &&CE,
|
|
|
|
bool RelaxAll) {
|
|
|
|
MCXCOFFStreamer *S = new MCXCOFFStreamer(Context, std::move(MAB),
|
|
|
|
std::move(OW), std::move(CE));
|
|
|
|
if (RelaxAll)
|
|
|
|
S->getAssembler().setRelaxAll(true);
|
|
|
|
return S;
|
|
|
|
}
|
Enable assembly output of local commons for AIX
Summary:
This patch enable assembly output of local commons for AIX using .lcomm
directives. Adds a EmitXCOFFLocalCommonSymbol to MCStreamer so we can emit the
AIX version of .lcomm assembly directives which include a csect name. Handle the
case of BSS locals in PPCAIXAsmPrinter by using EmitXCOFFLocalCommonSymbol. Adds
a test for generating .lcomm on AIX Targets.
Reviewers: cebowleratibm, hubert.reinterpretcast, Xiangling_L, jasonliu, sfertile
Reviewed By: sfertile
Subscribers: wuzish, nemanjai, hiraditya, kbarton, MaskRay, jsji, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64825
llvm-svn: 368306
2019-08-08 23:40:35 +08:00
|
|
|
|
2020-02-16 00:52:56 +08:00
|
|
|
void MCXCOFFStreamer::emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym,
|
2019-08-27 23:14:45 +08:00
|
|
|
uint64_t Size,
|
[XCOFF][AIX] Differentiate usage of label symbol and csect symbol
Summary:
We are using symbols to represent label and csect interchangeably before, and that could be a problem.
There are cases we would need to add storage mapping class to the symbol if that symbol is actually the name of a csect, but it's hard for us to figure out whether that symbol is a label or csect.
This patch intend to do the following:
1. Construct a QualName (A name include the storage mapping class)
MCSymbolXCOFF for every MCSectionXCOFF.
2. Keep a pointer to that QualName inside of MCSectionXCOFF.
3. Use that QualName whenever we need a symbol refers to that
MCSectionXCOFF.
4. Adapt the snowball effect from the above changes in
XCOFFObjectWriter.cpp.
Reviewers: xingxue, DiggerLin, sfertile, daltenty, hubert.reinterpretcast
Reviewed By: DiggerLin, daltenty
Subscribers: wuzish, nemanjai, mgorny, hiraditya, kbarton, jsji, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69633
2019-11-08 22:26:28 +08:00
|
|
|
MCSymbol *CsectSym,
|
2019-08-27 23:14:45 +08:00
|
|
|
unsigned ByteAlignment) {
|
2020-02-15 10:16:24 +08:00
|
|
|
emitCommonSymbol(CsectSym, Size, ByteAlignment);
|
2019-08-14 01:04:51 +08:00
|
|
|
}
|