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"
|
2020-05-12 02:43:07 +08:00
|
|
|
#include "llvm/MC/MCSectionXCOFF.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-11-03 04:32:06 +08:00
|
|
|
bool MCXCOFFStreamer::emitSymbolAttribute(MCSymbol *Sym,
|
|
|
|
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:
|
2020-04-30 21:53:41 +08:00
|
|
|
case MCSA_Extern:
|
[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
|
|
|
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;
|
2020-04-30 21:53:41 +08:00
|
|
|
case llvm::MCSA_Weak:
|
|
|
|
Symbol->setStorageClass(XCOFF::C_WEAKEXT);
|
|
|
|
Symbol->setExternal(true);
|
|
|
|
break;
|
[AIX] supporting the visibility attribute for aix assembly
SUMMARY:
in the aix assembly , it do not have .hidden and .protected directive.
in current llvm. if a function or a variable which has visibility attribute, it will generate something like the .hidden or .protected , it can not recognize by aix as.
in aix assembly, the visibility attribute are support in the pseudo-op like
.extern Name [ , Visibility ]
.globl Name [, Visibility ]
.weak Name [, Visibility ]
in this patch, we implement the visibility attribute for the global variable, function or extern function .
for example.
extern __attribute__ ((visibility ("hidden"))) int
bar(int* ip);
__attribute__ ((visibility ("hidden"))) int b = 0;
__attribute__ ((visibility ("hidden"))) int
foo(int* ip){
return (*ip)++;
}
the visibility of .comm linkage do not support , we will have a separate patch for it.
we have the unsupported cases ("default" and "internal") , we will implement them in a a separate patch for it.
Reviewers: Jason Liu ,hubert.reinterpretcast,James Henderson
Differential Revision: https://reviews.llvm.org/D75866
2020-06-10 04:15:06 +08:00
|
|
|
case llvm::MCSA_Hidden:
|
|
|
|
Symbol->setVisibilityType(XCOFF::SYM_V_HIDDEN);
|
|
|
|
break;
|
|
|
|
case llvm::MCSA_Protected:
|
|
|
|
Symbol->setVisibilityType(XCOFF::SYM_V_PROTECTED);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
[AIX] supporting the visibility attribute for aix assembly
SUMMARY:
in the aix assembly , it do not have .hidden and .protected directive.
in current llvm. if a function or a variable which has visibility attribute, it will generate something like the .hidden or .protected , it can not recognize by aix as.
in aix assembly, the visibility attribute are support in the pseudo-op like
.extern Name [ , Visibility ]
.globl Name [, Visibility ]
.weak Name [, Visibility ]
in this patch, we implement the visibility attribute for the global variable, function or extern function .
for example.
extern __attribute__ ((visibility ("hidden"))) int
bar(int* ip);
__attribute__ ((visibility ("hidden"))) int b = 0;
__attribute__ ((visibility ("hidden"))) int
foo(int* ip){
return (*ip)++;
}
the visibility of .comm linkage do not support , we will have a separate patch for it.
we have the unsupported cases ("default" and "internal") , we will implement them in a a separate patch for it.
Reviewers: Jason Liu ,hubert.reinterpretcast,James Henderson
Differential Revision: https://reviews.llvm.org/D75866
2020-06-10 04:15:06 +08:00
|
|
|
void MCXCOFFStreamer::emitXCOFFSymbolLinkageWithVisibility(
|
|
|
|
MCSymbol *Symbol, MCSymbolAttr Linkage, MCSymbolAttr Visibility) {
|
|
|
|
|
|
|
|
emitSymbolAttribute(Symbol, Linkage);
|
|
|
|
|
|
|
|
// When the caller passes `MCSA_Invalid` for the visibility, do not emit one.
|
|
|
|
if (Visibility == MCSA_Invalid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
emitSymbolAttribute(Symbol, Visibility);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2020-05-12 02:43:07 +08:00
|
|
|
// Default csect align is 4, but common symbols have explicit alignment values
|
|
|
|
// and we should honor it.
|
|
|
|
cast<MCSymbolXCOFF>(Symbol)->getRepresentedCsect()->setAlignment(
|
|
|
|
Align(ByteAlignment));
|
|
|
|
|
2019-08-21 06:03:18 +08:00
|
|
|
// 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.");
|
|
|
|
}
|
|
|
|
|
2020-04-20 17:53:00 +08:00
|
|
|
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
|
|
|
}
|