2019-07-09 21:21:01 +02:00
|
|
|
//===- MCSectionXCOFF.h - XCOFF Machine Code Sections -----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// 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 declares the MCSectionXCOFF class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_MC_MCSECTIONXCOFF_H
|
|
|
|
#define LLVM_MC_MCSECTIONXCOFF_H
|
|
|
|
|
|
|
|
#include "llvm/BinaryFormat/XCOFF.h"
|
|
|
|
#include "llvm/MC/MCSection.h"
|
[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 15:26:28 +01:00
|
|
|
#include "llvm/MC/MCSymbolXCOFF.h"
|
2019-07-09 21:21:01 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
// This class represents an XCOFF `Control Section`, more commonly referred to
|
|
|
|
// as a csect. A csect represents the smallest possible unit of data/code which
|
2019-07-22 21:15:29 +02:00
|
|
|
// will be relocated as a single block. A csect can either be:
|
|
|
|
// 1) Initialized: The Type will be XTY_SD, and the symbols inside the csect
|
|
|
|
// will have a label definition representing their offset within the csect.
|
|
|
|
// 2) Uninitialized: The Type will be XTY_CM, it will contain a single symbol,
|
|
|
|
// and may not contain label definitions.
|
2019-07-30 17:37:01 +02:00
|
|
|
// 3) An external reference providing a symbol table entry for a symbol
|
|
|
|
// contained in another XCOFF object file. External reference csects are not
|
|
|
|
// implemented yet.
|
2019-07-09 21:21:01 +02:00
|
|
|
class MCSectionXCOFF final : public MCSection {
|
|
|
|
friend class MCContext;
|
|
|
|
|
2021-02-18 10:41:05 +01:00
|
|
|
Optional<XCOFF::CsectProperties> CsectProp;
|
[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 15:26:28 +01:00
|
|
|
MCSymbolXCOFF *const QualName;
|
2020-07-06 16:18:06 +02:00
|
|
|
StringRef SymbolTableName;
|
2021-03-05 02:47:41 +01:00
|
|
|
Optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags;
|
2020-11-09 16:12:46 +01:00
|
|
|
bool MultiSymbolsAllowed;
|
2020-05-11 20:43:07 +02:00
|
|
|
static constexpr unsigned DefaultAlignVal = 4;
|
2019-07-09 21:21:01 +02:00
|
|
|
|
2020-04-16 00:49:05 +02:00
|
|
|
MCSectionXCOFF(StringRef Name, XCOFF::StorageMappingClass SMC,
|
2020-08-11 21:26:19 +02:00
|
|
|
XCOFF::SymbolType ST, SectionKind K, MCSymbolXCOFF *QualName,
|
2020-11-09 16:12:46 +01:00
|
|
|
MCSymbol *Begin, StringRef SymbolTableName,
|
|
|
|
bool MultiSymbolsAllowed)
|
2021-02-18 10:41:05 +01:00
|
|
|
: MCSection(SV_XCOFF, Name, K, Begin),
|
|
|
|
CsectProp(XCOFF::CsectProperties(SMC, ST)), QualName(QualName),
|
2021-03-05 02:47:41 +01:00
|
|
|
SymbolTableName(SymbolTableName), DwarfSubtypeFlags(None),
|
2020-11-09 16:12:46 +01:00
|
|
|
MultiSymbolsAllowed(MultiSymbolsAllowed) {
|
2021-02-18 10:41:05 +01:00
|
|
|
assert(
|
|
|
|
(ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
|
|
|
|
"Invalid or unhandled type for csect.");
|
[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 15:26:28 +01:00
|
|
|
assert(QualName != nullptr && "QualName is needed.");
|
2021-03-08 21:17:57 +01:00
|
|
|
if (SMC == XCOFF::XMC_UL)
|
|
|
|
assert((ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
|
|
|
|
"Invalid csect type for storage mapping class XCOFF::XMC_UL");
|
2021-03-05 02:47:41 +01:00
|
|
|
|
2020-04-03 15:13:13 +02:00
|
|
|
QualName->setRepresentedCsect(this);
|
2020-08-11 21:26:19 +02:00
|
|
|
QualName->setStorageClass(XCOFF::C_HIDEXT);
|
2020-05-11 20:43:07 +02:00
|
|
|
// A csect is 4 byte aligned by default, except for undefined symbol csects.
|
2021-02-18 10:41:05 +01:00
|
|
|
if (ST != XCOFF::XTY_ER)
|
2020-05-11 20:43:07 +02:00
|
|
|
setAlignment(Align(DefaultAlignVal));
|
2019-07-22 21:15:29 +02:00
|
|
|
}
|
2019-07-09 21:21:01 +02:00
|
|
|
|
2021-02-18 10:41:05 +01:00
|
|
|
MCSectionXCOFF(StringRef Name, SectionKind K, MCSymbolXCOFF *QualName,
|
2021-03-05 02:47:41 +01:00
|
|
|
XCOFF::DwarfSectionSubtypeFlags DwarfSubtypeFlags,
|
2021-02-18 10:41:05 +01:00
|
|
|
MCSymbol *Begin, StringRef SymbolTableName,
|
|
|
|
bool MultiSymbolsAllowed)
|
|
|
|
: MCSection(SV_XCOFF, Name, K, Begin), QualName(QualName),
|
2021-03-05 02:47:41 +01:00
|
|
|
SymbolTableName(SymbolTableName), DwarfSubtypeFlags(DwarfSubtypeFlags),
|
2021-02-18 10:41:05 +01:00
|
|
|
MultiSymbolsAllowed(MultiSymbolsAllowed) {
|
|
|
|
assert(QualName != nullptr && "QualName is needed.");
|
|
|
|
|
|
|
|
// FIXME: use a more meaningful name for non csect sections.
|
|
|
|
QualName->setRepresentedCsect(this);
|
|
|
|
|
|
|
|
// Set default alignment 4 for all non csect sections for now.
|
|
|
|
// FIXME: set different alignments according to section types.
|
|
|
|
setAlignment(Align(DefaultAlignVal));
|
|
|
|
}
|
|
|
|
|
2020-05-11 20:43:07 +02:00
|
|
|
void printCsectDirective(raw_ostream &OS) const;
|
|
|
|
|
2019-07-09 21:21:01 +02:00
|
|
|
public:
|
|
|
|
~MCSectionXCOFF();
|
|
|
|
|
|
|
|
static bool classof(const MCSection *S) {
|
|
|
|
return S->getVariant() == SV_XCOFF;
|
|
|
|
}
|
|
|
|
|
2021-02-18 10:41:05 +01:00
|
|
|
XCOFF::StorageMappingClass getMappingClass() const {
|
|
|
|
assert(isCsect() && "Only csect section has mapping class property!");
|
|
|
|
return CsectProp->MappingClass;
|
|
|
|
}
|
2020-08-11 21:26:19 +02:00
|
|
|
XCOFF::StorageClass getStorageClass() const {
|
|
|
|
return QualName->getStorageClass();
|
|
|
|
}
|
2021-02-18 10:41:05 +01:00
|
|
|
XCOFF::SymbolType getCSectType() const {
|
|
|
|
assert(isCsect() && "Only csect section has symbol type property!");
|
|
|
|
return CsectProp->Type;
|
|
|
|
}
|
[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 15:26:28 +01:00
|
|
|
MCSymbolXCOFF *getQualNameSymbol() const { return QualName; }
|
2019-07-09 21:21:01 +02:00
|
|
|
|
|
|
|
void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
|
|
|
|
raw_ostream &OS,
|
|
|
|
const MCExpr *Subsection) const override;
|
|
|
|
bool UseCodeAlign() const override;
|
|
|
|
bool isVirtualSection() const override;
|
2020-07-06 16:18:06 +02:00
|
|
|
StringRef getSymbolTableName() const { return SymbolTableName; }
|
2020-11-09 16:12:46 +01:00
|
|
|
bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; }
|
2021-02-18 10:41:05 +01:00
|
|
|
bool isCsect() const { return CsectProp.hasValue(); }
|
2021-03-05 02:47:41 +01:00
|
|
|
bool isDwarfSect() const { return DwarfSubtypeFlags.hasValue(); }
|
|
|
|
Optional<XCOFF::DwarfSectionSubtypeFlags> getDwarfSubtypeFlags() const {
|
|
|
|
return DwarfSubtypeFlags;
|
|
|
|
}
|
2019-07-09 21:21:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|