2019-07-09 21:21:01 +02:00
|
|
|
//===-- lib/MC/XCOFFObjectWriter.cpp - XCOFF file writer ------------------===//
|
|
|
|
//
|
|
|
|
// 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 implements XCOFF object file writer information.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-08-21 00:03:18 +02:00
|
|
|
#include "llvm/BinaryFormat/XCOFF.h"
|
2020-01-30 16:50:49 +01:00
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
2019-08-21 00:03:18 +02:00
|
|
|
#include "llvm/MC/MCAsmLayout.h"
|
2019-07-09 21:21:01 +02:00
|
|
|
#include "llvm/MC/MCAssembler.h"
|
2020-01-30 16:50:49 +01:00
|
|
|
#include "llvm/MC/MCFixup.h"
|
|
|
|
#include "llvm/MC/MCFixupKindInfo.h"
|
2019-07-09 21:21:01 +02:00
|
|
|
#include "llvm/MC/MCObjectWriter.h"
|
2019-08-21 00:03:18 +02:00
|
|
|
#include "llvm/MC/MCSectionXCOFF.h"
|
|
|
|
#include "llvm/MC/MCSymbolXCOFF.h"
|
2019-07-09 21:21:01 +02:00
|
|
|
#include "llvm/MC/MCValue.h"
|
|
|
|
#include "llvm/MC/MCXCOFFObjectWriter.h"
|
2019-08-21 00:03:18 +02:00
|
|
|
#include "llvm/MC/StringTableBuilder.h"
|
2020-04-16 20:31:45 +02:00
|
|
|
#include "llvm/Support/EndianStream.h"
|
2019-08-21 00:03:18 +02:00
|
|
|
#include "llvm/Support/Error.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
|
|
|
|
#include <deque>
|
2019-07-09 21:21:01 +02:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2019-08-21 00:03:18 +02:00
|
|
|
// An XCOFF object file has a limited set of predefined sections. The most
|
|
|
|
// important ones for us (right now) are:
|
|
|
|
// .text --> contains program code and read-only data.
|
|
|
|
// .data --> contains initialized data, function descriptors, and the TOC.
|
|
|
|
// .bss --> contains uninitialized data.
|
|
|
|
// Each of these sections is composed of 'Control Sections'. A Control Section
|
|
|
|
// is more commonly referred to as a csect. A csect is an indivisible unit of
|
|
|
|
// code or data, and acts as a container for symbols. A csect is mapped
|
|
|
|
// into a section based on its storage-mapping class, with the exception of
|
|
|
|
// XMC_RW which gets mapped to either .data or .bss based on whether it's
|
|
|
|
// explicitly initialized or not.
|
|
|
|
//
|
|
|
|
// We don't represent the sections in the MC layer as there is nothing
|
|
|
|
// interesting about them at at that level: they carry information that is
|
|
|
|
// only relevant to the ObjectWriter, so we materialize them in this class.
|
2019-07-09 21:21:01 +02:00
|
|
|
namespace {
|
|
|
|
|
2019-08-21 00:03:18 +02:00
|
|
|
constexpr unsigned DefaultSectionAlign = 4;
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
constexpr int16_t MaxSectionIndex = INT16_MAX;
|
2019-08-21 00:03:18 +02:00
|
|
|
|
|
|
|
// Packs the csect's alignment and type into a byte.
|
|
|
|
uint8_t getEncodedType(const MCSectionXCOFF *);
|
|
|
|
|
2020-01-30 16:50:49 +01:00
|
|
|
struct XCOFFRelocation {
|
|
|
|
uint32_t SymbolTableIndex;
|
|
|
|
uint32_t FixupOffsetInCsect;
|
|
|
|
uint8_t SignAndSize;
|
|
|
|
uint8_t Type;
|
|
|
|
};
|
|
|
|
|
2019-08-21 00:03:18 +02:00
|
|
|
// Wrapper around an MCSymbolXCOFF.
|
|
|
|
struct Symbol {
|
|
|
|
const MCSymbolXCOFF *const MCSym;
|
|
|
|
uint32_t SymbolTableIndex;
|
|
|
|
|
|
|
|
XCOFF::StorageClass getStorageClass() const {
|
|
|
|
return MCSym->getStorageClass();
|
|
|
|
}
|
2020-07-06 16:18:06 +02:00
|
|
|
StringRef getSymbolTableName() const { return MCSym->getSymbolTableName(); }
|
2019-08-21 00:03:18 +02:00
|
|
|
Symbol(const MCSymbolXCOFF *MCSym) : MCSym(MCSym), SymbolTableIndex(-1) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Wrapper for an MCSectionXCOFF.
|
2021-07-05 04:53:30 +02:00
|
|
|
// It can be a Csect or debug section or DWARF section and so on.
|
|
|
|
struct XCOFFSection {
|
|
|
|
const MCSectionXCOFF *const MCSec;
|
2019-08-21 00:03:18 +02:00
|
|
|
uint32_t SymbolTableIndex;
|
|
|
|
uint32_t Address;
|
|
|
|
uint32_t Size;
|
|
|
|
|
|
|
|
SmallVector<Symbol, 1> Syms;
|
2020-01-30 16:50:49 +01:00
|
|
|
SmallVector<XCOFFRelocation, 1> Relocations;
|
2021-07-05 04:53:30 +02:00
|
|
|
StringRef getSymbolTableName() const { return MCSec->getSymbolTableName(); }
|
|
|
|
XCOFFSection(const MCSectionXCOFF *MCSec)
|
|
|
|
: MCSec(MCSec), SymbolTableIndex(-1), Address(-1), Size(0) {}
|
2019-08-21 00:03:18 +02:00
|
|
|
};
|
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
// Type to be used for a container representing a set of csects with
|
|
|
|
// (approximately) the same storage mapping class. For example all the csects
|
|
|
|
// with a storage mapping class of `xmc_pr` will get placed into the same
|
|
|
|
// container.
|
2021-07-05 04:53:30 +02:00
|
|
|
using CsectGroup = std::deque<XCOFFSection>;
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
using CsectGroups = std::deque<CsectGroup *>;
|
|
|
|
|
2021-07-05 04:53:30 +02:00
|
|
|
// The basic section entry defination. This Section represents a section entry
|
|
|
|
// in XCOFF section header table.
|
|
|
|
struct SectionEntry {
|
2019-08-21 00:03:18 +02:00
|
|
|
char Name[XCOFF::NameSize];
|
|
|
|
// The physical/virtual address of the section. For an object file
|
|
|
|
// these values are equivalent.
|
|
|
|
uint32_t Address;
|
|
|
|
uint32_t Size;
|
|
|
|
uint32_t FileOffsetToData;
|
|
|
|
uint32_t FileOffsetToRelocations;
|
|
|
|
uint32_t RelocationCount;
|
|
|
|
int32_t Flags;
|
|
|
|
|
[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-15 19:40:41 +02:00
|
|
|
int16_t Index;
|
2019-08-21 00:03:18 +02:00
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
// XCOFF has special section numbers for symbols:
|
|
|
|
// -2 Specifies N_DEBUG, a special symbolic debugging symbol.
|
|
|
|
// -1 Specifies N_ABS, an absolute symbol. The symbol has a value but is not
|
|
|
|
// relocatable.
|
|
|
|
// 0 Specifies N_UNDEF, an undefined external symbol.
|
|
|
|
// Therefore, we choose -3 (N_DEBUG - 1) to represent a section index that
|
|
|
|
// hasn't been initialized.
|
|
|
|
static constexpr int16_t UninitializedIndex =
|
|
|
|
XCOFF::ReservedSectionNum::N_DEBUG - 1;
|
|
|
|
|
2021-07-05 04:53:30 +02:00
|
|
|
SectionEntry(StringRef N, int32_t Flags)
|
|
|
|
: Name(), Address(0), Size(0), FileOffsetToData(0),
|
|
|
|
FileOffsetToRelocations(0), RelocationCount(0), Flags(Flags),
|
|
|
|
Index(UninitializedIndex) {
|
|
|
|
assert(N.size() <= XCOFF::NameSize && "section name too long");
|
|
|
|
memcpy(Name, N.data(), N.size());
|
|
|
|
}
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
|
2021-07-05 04:53:30 +02:00
|
|
|
virtual void reset() {
|
2019-08-21 00:03:18 +02:00
|
|
|
Address = 0;
|
|
|
|
Size = 0;
|
|
|
|
FileOffsetToData = 0;
|
|
|
|
FileOffsetToRelocations = 0;
|
|
|
|
RelocationCount = 0;
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
Index = UninitializedIndex;
|
2019-08-21 00:03:18 +02:00
|
|
|
}
|
|
|
|
|
2021-07-05 04:53:30 +02:00
|
|
|
virtual ~SectionEntry() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Represents the data related to a section excluding the csects that make up
|
|
|
|
// the raw data of the section. The csects are stored separately as not all
|
|
|
|
// sections contain csects, and some sections contain csects which are better
|
|
|
|
// stored separately, e.g. the .data section containing read-write, descriptor,
|
|
|
|
// TOCBase and TOC-entry csects.
|
|
|
|
struct CsectSectionEntry : public SectionEntry {
|
|
|
|
// Virtual sections do not need storage allocated in the object file.
|
|
|
|
const bool IsVirtual;
|
|
|
|
|
|
|
|
// This is a section containing csect groups.
|
|
|
|
CsectGroups Groups;
|
|
|
|
|
|
|
|
CsectSectionEntry(StringRef N, XCOFF::SectionTypeFlags Flags, bool IsVirtual,
|
|
|
|
CsectGroups Groups)
|
|
|
|
: SectionEntry(N, Flags), IsVirtual(IsVirtual), Groups(Groups) {
|
[NFC][AIX][XCOFF] Fix compile warning on strncpy
GCC warning:
```
In file included from /usr/include/string.h:495,
from /usr/include/c++/9/cstring:42,
from /llvm-project/llvm/include/llvm/ADT/Hashing.h:53,
from /llvm-project/llvm/include/llvm/ADT/ArrayRef.h:12,
from /llvm-project/llvm/include/llvm/MC/MCAsmBackend.h:12,
from /llvm-project/llvm/lib/MC/XCOFFObjectWriter.cpp:14:
In function ‘char* strncpy(char*, const char*, size_t)’,
inlined from ‘{anonymous}::Section::Section(const char*, llvm::XCOFF::SectionTypeFlags, bool, {anonymous}::CsectGroups)’ at /llvm-project/llvm/lib/MC/XCOFFObjectWriter.cpp:146:12:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ specified bound 8 equals destination size [-Wstringop-truncation]
106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Reviewed By: hubert.reinterpretcast
Differential Revision: https://reviews.llvm.org/D94872
2021-01-17 05:35:01 +01:00
|
|
|
assert(N.size() <= XCOFF::NameSize && "section name too long");
|
|
|
|
memcpy(Name, N.data(), N.size());
|
2019-08-21 00:03:18 +02:00
|
|
|
}
|
2021-07-05 04:53:30 +02:00
|
|
|
|
|
|
|
void reset() override {
|
|
|
|
SectionEntry::reset();
|
|
|
|
// Clear any csects we have stored.
|
|
|
|
for (auto *Group : Groups)
|
|
|
|
Group->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~CsectSectionEntry() {}
|
2019-08-21 00:03:18 +02:00
|
|
|
};
|
|
|
|
|
2019-07-09 21:21:01 +02:00
|
|
|
class XCOFFObjectWriter : public MCObjectWriter {
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
|
|
|
|
uint32_t SymbolTableEntryCount = 0;
|
|
|
|
uint32_t SymbolTableOffset = 0;
|
2019-10-28 22:46:22 +01:00
|
|
|
uint16_t SectionCount = 0;
|
2020-01-30 16:50:49 +01:00
|
|
|
uint32_t RelocationEntryOffset = 0;
|
2019-08-21 00:03:18 +02:00
|
|
|
|
2019-07-09 21:21:01 +02:00
|
|
|
support::endian::Writer W;
|
|
|
|
std::unique_ptr<MCXCOFFObjectTargetWriter> TargetObjectWriter;
|
2019-08-21 00:03:18 +02:00
|
|
|
StringTableBuilder Strings;
|
|
|
|
|
2021-07-05 04:53:30 +02:00
|
|
|
// Maps the MCSection representation to its corresponding XCOFFSection
|
|
|
|
// wrapper. Needed for finding the XCOFFSection to insert an MCSymbol into
|
2020-01-30 16:50:49 +01:00
|
|
|
// from its containing MCSectionXCOFF.
|
2021-07-05 04:53:30 +02:00
|
|
|
DenseMap<const MCSectionXCOFF *, XCOFFSection *> SectionMap;
|
2020-01-30 16:50:49 +01:00
|
|
|
|
|
|
|
// Maps the MCSymbol representation to its corrresponding symbol table index.
|
|
|
|
// Needed for relocation.
|
|
|
|
DenseMap<const MCSymbol *, uint32_t> SymbolIndexMap;
|
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
// CsectGroups. These store the csects which make up different parts of
|
|
|
|
// the sections. Should have one for each set of csects that get mapped into
|
|
|
|
// the same section and get handled in a 'similar' way.
|
2019-11-25 16:02:01 +01:00
|
|
|
CsectGroup UndefinedCsects;
|
[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
|
|
|
CsectGroup ProgramCodeCsects;
|
2019-11-22 16:36:46 +01:00
|
|
|
CsectGroup ReadOnlyCsects;
|
[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
|
|
|
CsectGroup DataCsects;
|
2019-11-19 16:09:07 +01:00
|
|
|
CsectGroup FuncDSCsects;
|
|
|
|
CsectGroup TOCCsects;
|
[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
|
|
|
CsectGroup BSSCsects;
|
2021-04-06 16:58:39 +02:00
|
|
|
CsectGroup TDataCsects;
|
|
|
|
CsectGroup TBSSCsects;
|
2019-08-21 00:03:18 +02:00
|
|
|
|
|
|
|
// The Predefined sections.
|
2021-07-05 04:53:30 +02:00
|
|
|
CsectSectionEntry Text;
|
|
|
|
CsectSectionEntry Data;
|
|
|
|
CsectSectionEntry BSS;
|
|
|
|
CsectSectionEntry TData;
|
|
|
|
CsectSectionEntry TBSS;
|
2019-08-21 00:03:18 +02:00
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
// All the XCOFF sections, in the order they will appear in the section header
|
|
|
|
// table.
|
2021-07-05 04:53:30 +02:00
|
|
|
std::array<CsectSectionEntry *const, 5> Sections{
|
|
|
|
{&Text, &Data, &BSS, &TData, &TBSS}};
|
2019-08-21 00:03:18 +02:00
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
CsectGroup &getCsectGroup(const MCSectionXCOFF *MCSec);
|
2019-08-21 00:03:18 +02:00
|
|
|
|
|
|
|
virtual void reset() override;
|
2019-07-09 21:21:01 +02:00
|
|
|
|
|
|
|
void executePostLayoutBinding(MCAssembler &, const MCAsmLayout &) override;
|
|
|
|
|
|
|
|
void recordRelocation(MCAssembler &, const MCAsmLayout &, const MCFragment *,
|
|
|
|
const MCFixup &, MCValue, uint64_t &) override;
|
|
|
|
|
|
|
|
uint64_t writeObject(MCAssembler &, const MCAsmLayout &) override;
|
|
|
|
|
[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-15 19:40:41 +02:00
|
|
|
static bool nameShouldBeInStringTable(const StringRef &);
|
|
|
|
void writeSymbolName(const StringRef &);
|
|
|
|
void writeSymbolTableEntryForCsectMemberLabel(const Symbol &,
|
2021-07-05 04:53:30 +02:00
|
|
|
const XCOFFSection &, int16_t,
|
[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-15 19:40:41 +02:00
|
|
|
uint64_t);
|
2021-07-05 04:53:30 +02:00
|
|
|
void writeSymbolTableEntryForControlSection(const XCOFFSection &, int16_t,
|
[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-15 19:40:41 +02:00
|
|
|
XCOFF::StorageClass);
|
2019-08-21 00:03:18 +02:00
|
|
|
void writeFileHeader();
|
|
|
|
void writeSectionHeaderTable();
|
[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-15 19:40:41 +02:00
|
|
|
void writeSections(const MCAssembler &Asm, const MCAsmLayout &Layout);
|
|
|
|
void writeSymbolTable(const MCAsmLayout &Layout);
|
2020-01-30 16:50:49 +01:00
|
|
|
void writeRelocations();
|
2021-07-05 04:53:30 +02:00
|
|
|
void writeRelocation(XCOFFRelocation Reloc, const XCOFFSection &CSection);
|
2019-08-21 00:03:18 +02:00
|
|
|
|
|
|
|
// Called after all the csects and symbols have been processed by
|
|
|
|
// `executePostLayoutBinding`, this function handles building up the majority
|
|
|
|
// of the structures in the object file representation. Namely:
|
|
|
|
// *) Calculates physical/virtual addresses, raw-pointer offsets, and section
|
|
|
|
// sizes.
|
|
|
|
// *) Assigns symbol table indices.
|
|
|
|
// *) Builds up the section header table by adding any non-empty sections to
|
|
|
|
// `Sections`.
|
[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-15 19:40:41 +02:00
|
|
|
void assignAddressesAndIndices(const MCAsmLayout &);
|
2020-01-30 16:50:49 +01:00
|
|
|
void finalizeSectionInfo();
|
2019-08-21 00:03:18 +02:00
|
|
|
|
|
|
|
bool
|
|
|
|
needsAuxiliaryHeader() const { /* TODO aux header support not implemented. */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the size of the auxiliary header to be written to the object file.
|
|
|
|
size_t auxiliaryHeaderSize() const {
|
|
|
|
assert(!needsAuxiliaryHeader() &&
|
|
|
|
"Auxiliary header support not implemented.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-09 21:21:01 +02:00
|
|
|
public:
|
|
|
|
XCOFFObjectWriter(std::unique_ptr<MCXCOFFObjectTargetWriter> MOTW,
|
|
|
|
raw_pwrite_stream &OS);
|
|
|
|
};
|
|
|
|
|
|
|
|
XCOFFObjectWriter::XCOFFObjectWriter(
|
|
|
|
std::unique_ptr<MCXCOFFObjectTargetWriter> MOTW, raw_pwrite_stream &OS)
|
2019-08-21 00:03:18 +02:00
|
|
|
: W(OS, support::big), TargetObjectWriter(std::move(MOTW)),
|
|
|
|
Strings(StringTableBuilder::XCOFF),
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
Text(".text", XCOFF::STYP_TEXT, /* IsVirtual */ false,
|
2019-11-22 16:36:46 +01:00
|
|
|
CsectGroups{&ProgramCodeCsects, &ReadOnlyCsects}),
|
[PowerPC][AIX] Adds support for writing the data section in object files
Adds support for generating the XCOFF data section in object files for global variables with initialization.
Merged aix-xcoff-common.ll into aix-xcoff-data.ll.
Changed variable name charr to chrarray in the test case to test if readobj works with 8-character names.
Authored by: xingxue
Reviewers: hubert.reinterptrtcast, sfertile, jasonliu, daltenty, Xiangling_L.
Reviewed by: hubert.reinterpretcast, sfertile, daltenty.
Subscribers: DiggerLin, Wuzish, nemanjai, hiraditya, MaskRay, jsji, shchenz, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67125
2019-10-30 19:31:31 +01:00
|
|
|
Data(".data", XCOFF::STYP_DATA, /* IsVirtual */ false,
|
2019-11-19 16:09:07 +01:00
|
|
|
CsectGroups{&DataCsects, &FuncDSCsects, &TOCCsects}),
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
BSS(".bss", XCOFF::STYP_BSS, /* IsVirtual */ true,
|
2021-04-06 16:58:39 +02:00
|
|
|
CsectGroups{&BSSCsects}),
|
|
|
|
TData(".tdata", XCOFF::STYP_TDATA, /* IsVirtual */ false,
|
|
|
|
CsectGroups{&TDataCsects}),
|
|
|
|
TBSS(".tbss", XCOFF::STYP_TBSS, /* IsVirtual */ true,
|
|
|
|
CsectGroups{&TBSSCsects}) {}
|
2019-08-21 00:03:18 +02:00
|
|
|
|
|
|
|
void XCOFFObjectWriter::reset() {
|
2020-01-30 16:50:49 +01:00
|
|
|
// Clear the mappings we created.
|
|
|
|
SymbolIndexMap.clear();
|
|
|
|
SectionMap.clear();
|
2019-11-25 16:02:01 +01:00
|
|
|
|
2020-01-30 16:50:49 +01:00
|
|
|
UndefinedCsects.clear();
|
2019-08-21 00:03:18 +02:00
|
|
|
// Reset any sections we have written to, and empty the section header table.
|
|
|
|
for (auto *Sec : Sections)
|
|
|
|
Sec->reset();
|
|
|
|
|
2020-01-30 16:50:49 +01:00
|
|
|
// Reset states in XCOFFObjectWriter.
|
2019-08-21 00:03:18 +02:00
|
|
|
SymbolTableEntryCount = 0;
|
|
|
|
SymbolTableOffset = 0;
|
2019-10-28 22:46:22 +01:00
|
|
|
SectionCount = 0;
|
2020-01-30 16:50:49 +01:00
|
|
|
RelocationEntryOffset = 0;
|
2019-08-21 00:03:18 +02:00
|
|
|
Strings.clear();
|
|
|
|
|
|
|
|
MCObjectWriter::reset();
|
|
|
|
}
|
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
CsectGroup &XCOFFObjectWriter::getCsectGroup(const MCSectionXCOFF *MCSec) {
|
|
|
|
switch (MCSec->getMappingClass()) {
|
|
|
|
case XCOFF::XMC_PR:
|
|
|
|
assert(XCOFF::XTY_SD == MCSec->getCSectType() &&
|
|
|
|
"Only an initialized csect can contain program code.");
|
|
|
|
return ProgramCodeCsects;
|
2019-11-22 16:36:46 +01:00
|
|
|
case XCOFF::XMC_RO:
|
|
|
|
assert(XCOFF::XTY_SD == MCSec->getCSectType() &&
|
|
|
|
"Only an initialized csect can contain read only data.");
|
|
|
|
return ReadOnlyCsects;
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
case XCOFF::XMC_RW:
|
|
|
|
if (XCOFF::XTY_CM == MCSec->getCSectType())
|
|
|
|
return BSSCsects;
|
|
|
|
|
[PowerPC][AIX] Adds support for writing the data section in object files
Adds support for generating the XCOFF data section in object files for global variables with initialization.
Merged aix-xcoff-common.ll into aix-xcoff-data.ll.
Changed variable name charr to chrarray in the test case to test if readobj works with 8-character names.
Authored by: xingxue
Reviewers: hubert.reinterptrtcast, sfertile, jasonliu, daltenty, Xiangling_L.
Reviewed by: hubert.reinterpretcast, sfertile, daltenty.
Subscribers: DiggerLin, Wuzish, nemanjai, hiraditya, MaskRay, jsji, shchenz, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67125
2019-10-30 19:31:31 +01:00
|
|
|
if (XCOFF::XTY_SD == MCSec->getCSectType())
|
|
|
|
return DataCsects;
|
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
report_fatal_error("Unhandled mapping of read-write csect to section.");
|
2019-11-19 16:09:07 +01:00
|
|
|
case XCOFF::XMC_DS:
|
|
|
|
return FuncDSCsects;
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
case XCOFF::XMC_BS:
|
|
|
|
assert(XCOFF::XTY_CM == MCSec->getCSectType() &&
|
|
|
|
"Mapping invalid csect. CSECT with bss storage class must be "
|
|
|
|
"common type.");
|
|
|
|
return BSSCsects;
|
2021-04-06 16:58:39 +02:00
|
|
|
case XCOFF::XMC_TL:
|
|
|
|
assert(XCOFF::XTY_SD == MCSec->getCSectType() &&
|
|
|
|
"Mapping invalid csect. CSECT with tdata storage class must be "
|
|
|
|
"an initialized csect.");
|
|
|
|
return TDataCsects;
|
|
|
|
case XCOFF::XMC_UL:
|
|
|
|
assert(XCOFF::XTY_CM == MCSec->getCSectType() &&
|
|
|
|
"Mapping invalid csect. CSECT with tbss storage class must be "
|
|
|
|
"an uninitialized csect.");
|
|
|
|
return TBSSCsects;
|
2019-11-19 16:09:07 +01:00
|
|
|
case XCOFF::XMC_TC0:
|
|
|
|
assert(XCOFF::XTY_SD == MCSec->getCSectType() &&
|
|
|
|
"Only an initialized csect can contain TOC-base.");
|
|
|
|
assert(TOCCsects.empty() &&
|
|
|
|
"We should have only one TOC-base, and it should be the first csect "
|
|
|
|
"in this CsectGroup.");
|
|
|
|
return TOCCsects;
|
2019-12-04 17:22:57 +01:00
|
|
|
case XCOFF::XMC_TC:
|
2020-08-26 18:08:43 +02:00
|
|
|
case XCOFF::XMC_TE:
|
2019-12-04 17:22:57 +01:00
|
|
|
assert(XCOFF::XTY_SD == MCSec->getCSectType() &&
|
|
|
|
"Only an initialized csect can contain TC entry.");
|
|
|
|
assert(!TOCCsects.empty() &&
|
|
|
|
"We should at least have a TOC-base in this CsectGroup.");
|
|
|
|
return TOCCsects;
|
2021-04-30 16:48:02 +02:00
|
|
|
case XCOFF::XMC_TD:
|
|
|
|
report_fatal_error("toc-data not yet supported when writing object files.");
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
default:
|
|
|
|
report_fatal_error("Unhandled mapping of csect to section.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-03 15:13:13 +02:00
|
|
|
static MCSectionXCOFF *getContainingCsect(const MCSymbolXCOFF *XSym) {
|
|
|
|
if (XSym->isDefined())
|
|
|
|
return cast<MCSectionXCOFF>(XSym->getFragment()->getParent());
|
|
|
|
return XSym->getRepresentedCsect();
|
|
|
|
}
|
|
|
|
|
[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-15 19:40:41 +02:00
|
|
|
void XCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
|
|
|
|
const MCAsmLayout &Layout) {
|
2019-08-21 00:03:18 +02:00
|
|
|
if (TargetObjectWriter->is64Bit())
|
|
|
|
report_fatal_error("64-bit XCOFF object files are not supported yet.");
|
|
|
|
|
|
|
|
for (const auto &S : Asm) {
|
2019-10-14 18:46:11 +02:00
|
|
|
const auto *MCSec = cast<const MCSectionXCOFF>(&S);
|
2020-01-30 16:50:49 +01:00
|
|
|
assert(SectionMap.find(MCSec) == SectionMap.end() &&
|
2021-07-05 04:53:30 +02:00
|
|
|
"Cannot add a section twice.");
|
2019-11-25 16:02:01 +01:00
|
|
|
assert(XCOFF::XTY_ER != MCSec->getCSectType() &&
|
|
|
|
"An undefined csect should not get registered.");
|
2019-08-21 00:03:18 +02:00
|
|
|
|
[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-15 19:40:41 +02:00
|
|
|
// If the name does not fit in the storage provided in the symbol table
|
|
|
|
// entry, add it to the string table.
|
2020-07-06 16:18:06 +02:00
|
|
|
if (nameShouldBeInStringTable(MCSec->getSymbolTableName()))
|
|
|
|
Strings.add(MCSec->getSymbolTableName());
|
[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-15 19:40:41 +02:00
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
CsectGroup &Group = getCsectGroup(MCSec);
|
[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
|
|
|
Group.emplace_back(MCSec);
|
2020-01-30 16:50:49 +01:00
|
|
|
SectionMap[MCSec] = &Group.back();
|
2019-08-21 00:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const MCSymbol &S : Asm.symbols()) {
|
|
|
|
// Nothing to do for temporary symbols.
|
|
|
|
if (S.isTemporary())
|
|
|
|
continue;
|
|
|
|
|
2019-12-19 21:30:12 +01:00
|
|
|
const MCSymbolXCOFF *XSym = cast<MCSymbolXCOFF>(&S);
|
2020-04-03 15:13:13 +02:00
|
|
|
const MCSectionXCOFF *ContainingCsect = getContainingCsect(XSym);
|
2019-08-21 00:03:18 +02:00
|
|
|
|
2019-12-19 21:30:12 +01:00
|
|
|
if (ContainingCsect->getCSectType() == XCOFF::XTY_ER) {
|
2020-02-21 18:20:45 +01:00
|
|
|
// Handle undefined symbol.
|
2019-12-19 21:30:12 +01:00
|
|
|
UndefinedCsects.emplace_back(ContainingCsect);
|
2020-01-30 16:50:49 +01:00
|
|
|
SectionMap[ContainingCsect] = &UndefinedCsects.back();
|
2020-07-06 16:18:06 +02:00
|
|
|
if (nameShouldBeInStringTable(ContainingCsect->getSymbolTableName()))
|
|
|
|
Strings.add(ContainingCsect->getSymbolTableName());
|
2020-04-30 15:53:41 +02:00
|
|
|
continue;
|
2019-12-19 21:30:12 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 15:53:41 +02:00
|
|
|
// If the symbol is the csect itself, we don't need to put the symbol
|
|
|
|
// into csect's Syms.
|
|
|
|
if (XSym == ContainingCsect->getQualNameSymbol())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Only put a label into the symbol table when it is an external label.
|
|
|
|
if (!XSym->isExternal())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
assert(SectionMap.find(ContainingCsect) != SectionMap.end() &&
|
|
|
|
"Expected containing csect to exist in map");
|
2021-07-05 04:53:30 +02:00
|
|
|
XCOFFSection *Csect = SectionMap[ContainingCsect];
|
2020-04-30 15:53:41 +02:00
|
|
|
// Lookup the containing csect and add the symbol to it.
|
2021-07-05 04:53:30 +02:00
|
|
|
assert(Csect->MCSec->isCsect() && "only csect is supported now!");
|
|
|
|
Csect->Syms.emplace_back(XSym);
|
2020-04-30 15:53:41 +02:00
|
|
|
|
2019-08-21 00:03:18 +02:00
|
|
|
// If the name does not fit in the storage provided in the symbol table
|
|
|
|
// entry, add it to the string table.
|
2020-07-06 16:18:06 +02:00
|
|
|
if (nameShouldBeInStringTable(XSym->getSymbolTableName()))
|
|
|
|
Strings.add(XSym->getSymbolTableName());
|
2020-02-21 18:20:45 +01:00
|
|
|
}
|
2019-08-21 00:03:18 +02:00
|
|
|
|
|
|
|
Strings.finalize();
|
|
|
|
assignAddressesAndIndices(Layout);
|
2019-07-09 21:21:01 +02:00
|
|
|
}
|
|
|
|
|
2020-01-30 16:50:49 +01:00
|
|
|
void XCOFFObjectWriter::recordRelocation(MCAssembler &Asm,
|
|
|
|
const MCAsmLayout &Layout,
|
|
|
|
const MCFragment *Fragment,
|
|
|
|
const MCFixup &Fixup, MCValue Target,
|
|
|
|
uint64_t &FixedValue) {
|
2020-04-15 16:00:34 +02:00
|
|
|
auto getIndex = [this](const MCSymbol *Sym,
|
|
|
|
const MCSectionXCOFF *ContainingCsect) {
|
|
|
|
// If we could not find the symbol directly in SymbolIndexMap, this symbol
|
|
|
|
// could either be a temporary symbol or an undefined symbol. In this case,
|
|
|
|
// we would need to have the relocation reference its csect instead.
|
|
|
|
return SymbolIndexMap.find(Sym) != SymbolIndexMap.end()
|
|
|
|
? SymbolIndexMap[Sym]
|
|
|
|
: SymbolIndexMap[ContainingCsect->getQualNameSymbol()];
|
|
|
|
};
|
|
|
|
|
|
|
|
auto getVirtualAddress = [this,
|
|
|
|
&Layout](const MCSymbol *Sym,
|
|
|
|
const MCSectionXCOFF *ContainingCsect) {
|
|
|
|
// If Sym is a csect, return csect's address.
|
|
|
|
// If Sym is a label, return csect's address + label's offset from the csect.
|
|
|
|
return SectionMap[ContainingCsect]->Address +
|
|
|
|
(Sym->isDefined() ? Layout.getSymbolOffset(*Sym) : 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
const MCSymbol *const SymA = &Target.getSymA()->getSymbol();
|
2020-01-30 16:50:49 +01:00
|
|
|
|
|
|
|
MCAsmBackend &Backend = Asm.getBackend();
|
|
|
|
bool IsPCRel = Backend.getFixupKindInfo(Fixup.getKind()).Flags &
|
|
|
|
MCFixupKindInfo::FKF_IsPCRel;
|
|
|
|
|
|
|
|
uint8_t Type;
|
|
|
|
uint8_t SignAndSize;
|
|
|
|
std::tie(Type, SignAndSize) =
|
|
|
|
TargetObjectWriter->getRelocTypeAndSignSize(Target, Fixup, IsPCRel);
|
|
|
|
|
2020-04-15 16:00:34 +02:00
|
|
|
const MCSectionXCOFF *SymASec = getContainingCsect(cast<MCSymbolXCOFF>(SymA));
|
2021-04-30 16:48:02 +02:00
|
|
|
|
|
|
|
if (SymASec->isCsect() && SymASec->getMappingClass() == XCOFF::XMC_TD)
|
|
|
|
report_fatal_error("toc-data not yet supported when writing object files.");
|
|
|
|
|
2020-01-30 16:50:49 +01:00
|
|
|
assert(SectionMap.find(SymASec) != SectionMap.end() &&
|
|
|
|
"Expected containing csect to exist in map.");
|
|
|
|
|
2020-04-15 16:00:34 +02:00
|
|
|
const uint32_t Index = getIndex(SymA, SymASec);
|
2021-05-06 15:37:09 +02:00
|
|
|
if (Type == XCOFF::RelocationType::R_POS ||
|
|
|
|
Type == XCOFF::RelocationType::R_TLS)
|
2020-01-30 16:50:49 +01:00
|
|
|
// The FixedValue should be symbol's virtual address in this object file
|
|
|
|
// plus any constant value that we might get.
|
2020-04-15 16:00:34 +02:00
|
|
|
FixedValue = getVirtualAddress(SymA, SymASec) + Target.getConstant();
|
2021-05-06 15:37:09 +02:00
|
|
|
else if (Type == XCOFF::RelocationType::R_TLSM)
|
|
|
|
// The FixedValue should always be zero since the region handle is only
|
|
|
|
// known at load time.
|
|
|
|
FixedValue = 0;
|
2020-08-26 18:08:43 +02:00
|
|
|
else if (Type == XCOFF::RelocationType::R_TOC ||
|
|
|
|
Type == XCOFF::RelocationType::R_TOCL) {
|
2020-09-11 16:26:26 +02:00
|
|
|
// The FixedValue should be the TOC entry offset from the TOC-base plus any
|
|
|
|
// constant offset value.
|
|
|
|
const int64_t TOCEntryOffset = SectionMap[SymASec]->Address -
|
|
|
|
TOCCsects.front().Address +
|
|
|
|
Target.getConstant();
|
|
|
|
if (Type == XCOFF::RelocationType::R_TOC && !isInt<16>(TOCEntryOffset))
|
|
|
|
report_fatal_error("TOCEntryOffset overflows in small code model mode");
|
|
|
|
|
|
|
|
FixedValue = TOCEntryOffset;
|
2020-08-26 18:08:43 +02:00
|
|
|
}
|
2020-01-30 16:50:49 +01:00
|
|
|
|
|
|
|
assert(
|
|
|
|
(TargetObjectWriter->is64Bit() ||
|
|
|
|
Fixup.getOffset() <= UINT32_MAX - Layout.getFragmentOffset(Fragment)) &&
|
|
|
|
"Fragment offset + fixup offset is overflowed in 32-bit mode.");
|
|
|
|
uint32_t FixupOffsetInCsect =
|
|
|
|
Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
|
|
|
|
|
|
|
|
XCOFFRelocation Reloc = {Index, FixupOffsetInCsect, SignAndSize, Type};
|
|
|
|
MCSectionXCOFF *RelocationSec = cast<MCSectionXCOFF>(Fragment->getParent());
|
|
|
|
assert(SectionMap.find(RelocationSec) != SectionMap.end() &&
|
|
|
|
"Expected containing csect to exist in map.");
|
|
|
|
SectionMap[RelocationSec]->Relocations.push_back(Reloc);
|
2020-04-15 16:00:34 +02:00
|
|
|
|
|
|
|
if (!Target.getSymB())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const MCSymbol *const SymB = &Target.getSymB()->getSymbol();
|
|
|
|
if (SymA == SymB)
|
|
|
|
report_fatal_error("relocation for opposite term is not yet supported");
|
|
|
|
|
|
|
|
const MCSectionXCOFF *SymBSec = getContainingCsect(cast<MCSymbolXCOFF>(SymB));
|
|
|
|
assert(SectionMap.find(SymBSec) != SectionMap.end() &&
|
|
|
|
"Expected containing csect to exist in map.");
|
|
|
|
if (SymASec == SymBSec)
|
|
|
|
report_fatal_error(
|
|
|
|
"relocation for paired relocatable term is not yet supported");
|
|
|
|
|
|
|
|
assert(Type == XCOFF::RelocationType::R_POS &&
|
|
|
|
"SymA must be R_POS here if it's not opposite term or paired "
|
|
|
|
"relocatable term.");
|
|
|
|
const uint32_t IndexB = getIndex(SymB, SymBSec);
|
|
|
|
// SymB must be R_NEG here, given the general form of Target(MCValue) is
|
|
|
|
// "SymbolA - SymbolB + imm64".
|
|
|
|
const uint8_t TypeB = XCOFF::RelocationType::R_NEG;
|
|
|
|
XCOFFRelocation RelocB = {IndexB, FixupOffsetInCsect, SignAndSize, TypeB};
|
|
|
|
SectionMap[RelocationSec]->Relocations.push_back(RelocB);
|
|
|
|
// We already folded "SymbolA + imm64" above when Type is R_POS for SymbolA,
|
|
|
|
// now we just need to fold "- SymbolB" here.
|
|
|
|
FixedValue -= getVirtualAddress(SymB, SymBSec);
|
2019-07-09 21:21:01 +02:00
|
|
|
}
|
|
|
|
|
[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-15 19:40:41 +02:00
|
|
|
void XCOFFObjectWriter::writeSections(const MCAssembler &Asm,
|
|
|
|
const MCAsmLayout &Layout) {
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
uint32_t CurrentAddressLocation = 0;
|
|
|
|
for (const auto *Section : Sections) {
|
|
|
|
// Nothing to write for this Section.
|
2021-07-05 04:53:30 +02:00
|
|
|
if (Section->Index == SectionEntry::UninitializedIndex ||
|
|
|
|
Section->IsVirtual)
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
continue;
|
|
|
|
|
2020-03-03 16:02:40 +01:00
|
|
|
// There could be a gap (without corresponding zero padding) between
|
|
|
|
// sections.
|
2021-04-06 16:58:39 +02:00
|
|
|
assert(((CurrentAddressLocation <= Section->Address) ||
|
|
|
|
(Section->Flags == XCOFF::STYP_TDATA) ||
|
|
|
|
(Section->Flags == XCOFF::STYP_TBSS)) &&
|
2020-03-03 16:02:40 +01:00
|
|
|
"CurrentAddressLocation should be less than or equal to section "
|
2021-04-06 16:58:39 +02:00
|
|
|
"address if the section is not TData or TBSS.");
|
2020-03-03 16:02:40 +01:00
|
|
|
|
|
|
|
CurrentAddressLocation = Section->Address;
|
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
for (const auto *Group : Section->Groups) {
|
[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
|
|
|
for (const auto &Csect : *Group) {
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
if (uint32_t PaddingSize = Csect.Address - CurrentAddressLocation)
|
|
|
|
W.OS.write_zeros(PaddingSize);
|
2019-12-06 18:41:38 +01:00
|
|
|
if (Csect.Size)
|
2021-07-05 04:53:30 +02:00
|
|
|
Asm.writeSectionData(W.OS, Csect.MCSec, Layout);
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
CurrentAddressLocation = Csect.Address + Csect.Size;
|
|
|
|
}
|
|
|
|
}
|
[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-15 19:40:41 +02:00
|
|
|
|
|
|
|
// The size of the tail padding in a section is the end virtual address of
|
|
|
|
// the current section minus the the end virtual address of the last csect
|
|
|
|
// in that section.
|
|
|
|
if (uint32_t PaddingSize =
|
2019-12-10 17:14:49 +01:00
|
|
|
Section->Address + Section->Size - CurrentAddressLocation) {
|
[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-15 19:40:41 +02:00
|
|
|
W.OS.write_zeros(PaddingSize);
|
2019-12-10 17:14:49 +01:00
|
|
|
CurrentAddressLocation += PaddingSize;
|
|
|
|
}
|
[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-15 19:40:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t XCOFFObjectWriter::writeObject(MCAssembler &Asm,
|
|
|
|
const MCAsmLayout &Layout) {
|
2019-07-09 21:21:01 +02:00
|
|
|
// We always emit a timestamp of 0 for reproducibility, so ensure incremental
|
|
|
|
// linking is not enabled, in case, like with Windows COFF, such a timestamp
|
|
|
|
// is incompatible with incremental linking of XCOFF.
|
|
|
|
if (Asm.isIncrementalLinkerCompatible())
|
|
|
|
report_fatal_error("Incremental linking not supported for XCOFF.");
|
|
|
|
|
|
|
|
if (TargetObjectWriter->is64Bit())
|
|
|
|
report_fatal_error("64-bit XCOFF object files are not supported yet.");
|
|
|
|
|
2020-01-30 16:50:49 +01:00
|
|
|
finalizeSectionInfo();
|
2019-07-09 21:21:01 +02:00
|
|
|
uint64_t StartOffset = W.OS.tell();
|
|
|
|
|
2019-08-21 00:03:18 +02:00
|
|
|
writeFileHeader();
|
|
|
|
writeSectionHeaderTable();
|
[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-15 19:40:41 +02:00
|
|
|
writeSections(Asm, Layout);
|
2020-01-30 16:50:49 +01:00
|
|
|
writeRelocations();
|
2019-07-09 21:21:01 +02:00
|
|
|
|
[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-15 19:40:41 +02:00
|
|
|
writeSymbolTable(Layout);
|
2019-08-21 00:03:18 +02:00
|
|
|
// Write the string table.
|
|
|
|
Strings.write(W.OS);
|
2019-07-09 21:21:01 +02:00
|
|
|
|
2019-08-21 00:03:18 +02:00
|
|
|
return W.OS.tell() - StartOffset;
|
|
|
|
}
|
|
|
|
|
[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-15 19:40:41 +02:00
|
|
|
bool XCOFFObjectWriter::nameShouldBeInStringTable(const StringRef &SymbolName) {
|
|
|
|
return SymbolName.size() > XCOFF::NameSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void XCOFFObjectWriter::writeSymbolName(const StringRef &SymbolName) {
|
|
|
|
if (nameShouldBeInStringTable(SymbolName)) {
|
|
|
|
W.write<int32_t>(0);
|
|
|
|
W.write<uint32_t>(Strings.getOffset(SymbolName));
|
|
|
|
} else {
|
2019-12-06 18:22:28 +01:00
|
|
|
char Name[XCOFF::NameSize+1];
|
[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-15 19:40:41 +02:00
|
|
|
std::strncpy(Name, SymbolName.data(), XCOFF::NameSize);
|
|
|
|
ArrayRef<char> NameRef(Name, XCOFF::NameSize);
|
|
|
|
W.write(NameRef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void XCOFFObjectWriter::writeSymbolTableEntryForCsectMemberLabel(
|
2021-07-05 04:53:30 +02:00
|
|
|
const Symbol &SymbolRef, const XCOFFSection &CSectionRef,
|
[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-15 19:40:41 +02:00
|
|
|
int16_t SectionIndex, uint64_t SymbolOffset) {
|
|
|
|
// Name or Zeros and string table offset
|
2020-07-06 16:18:06 +02:00
|
|
|
writeSymbolName(SymbolRef.getSymbolTableName());
|
[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-15 19:40:41 +02:00
|
|
|
assert(SymbolOffset <= UINT32_MAX - CSectionRef.Address &&
|
|
|
|
"Symbol address overflows.");
|
|
|
|
W.write<uint32_t>(CSectionRef.Address + SymbolOffset);
|
|
|
|
W.write<int16_t>(SectionIndex);
|
|
|
|
// Basic/Derived type. See the description of the n_type field for symbol
|
2020-08-27 17:07:58 +02:00
|
|
|
// table entries for a detailed description. Since we don't yet support
|
|
|
|
// visibility, and all other bits are either optionally set or reserved, this
|
|
|
|
// is always zero.
|
|
|
|
// TODO FIXME How to assert a symbol's visibilty is default?
|
[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-15 19:40:41 +02:00
|
|
|
// TODO Set the function indicator (bit 10, 0x0020) for functions
|
|
|
|
// when debugging is enabled.
|
2020-08-27 17:07:58 +02:00
|
|
|
W.write<uint16_t>(0);
|
[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-15 19:40:41 +02:00
|
|
|
W.write<uint8_t>(SymbolRef.getStorageClass());
|
|
|
|
// Always 1 aux entry for now.
|
|
|
|
W.write<uint8_t>(1);
|
|
|
|
|
|
|
|
// Now output the auxiliary entry.
|
|
|
|
W.write<uint32_t>(CSectionRef.SymbolTableIndex);
|
|
|
|
// Parameter typecheck hash. Not supported.
|
|
|
|
W.write<uint32_t>(0);
|
|
|
|
// Typecheck section number. Not supported.
|
|
|
|
W.write<uint16_t>(0);
|
|
|
|
// Symbol type: Label
|
|
|
|
W.write<uint8_t>(XCOFF::XTY_LD);
|
|
|
|
// Storage mapping class.
|
2021-07-05 04:53:30 +02:00
|
|
|
W.write<uint8_t>(CSectionRef.MCSec->getMappingClass());
|
[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-15 19:40:41 +02:00
|
|
|
// Reserved (x_stab).
|
|
|
|
W.write<uint32_t>(0);
|
|
|
|
// Reserved (x_snstab).
|
|
|
|
W.write<uint16_t>(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void XCOFFObjectWriter::writeSymbolTableEntryForControlSection(
|
2021-07-05 04:53:30 +02:00
|
|
|
const XCOFFSection &CSectionRef, int16_t SectionIndex,
|
[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-15 19:40:41 +02:00
|
|
|
XCOFF::StorageClass StorageClass) {
|
|
|
|
// n_name, n_zeros, n_offset
|
2020-07-06 16:18:06 +02:00
|
|
|
writeSymbolName(CSectionRef.getSymbolTableName());
|
[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-15 19:40:41 +02:00
|
|
|
// n_value
|
|
|
|
W.write<uint32_t>(CSectionRef.Address);
|
|
|
|
// n_scnum
|
|
|
|
W.write<int16_t>(SectionIndex);
|
|
|
|
// Basic/Derived type. See the description of the n_type field for symbol
|
2020-08-27 17:07:58 +02:00
|
|
|
// table entries for a detailed description. Since we don't yet support
|
|
|
|
// visibility, and all other bits are either optionally set or reserved, this
|
|
|
|
// is always zero.
|
|
|
|
// TODO FIXME How to assert a symbol's visibilty is default?
|
[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-15 19:40:41 +02:00
|
|
|
// TODO Set the function indicator (bit 10, 0x0020) for functions
|
|
|
|
// when debugging is enabled.
|
2020-08-27 17:07:58 +02:00
|
|
|
W.write<uint16_t>(0);
|
[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-15 19:40:41 +02:00
|
|
|
// n_sclass
|
|
|
|
W.write<uint8_t>(StorageClass);
|
|
|
|
// Always 1 aux entry for now.
|
|
|
|
W.write<uint8_t>(1);
|
|
|
|
|
|
|
|
// Now output the auxiliary entry.
|
|
|
|
W.write<uint32_t>(CSectionRef.Size);
|
|
|
|
// Parameter typecheck hash. Not supported.
|
|
|
|
W.write<uint32_t>(0);
|
|
|
|
// Typecheck section number. Not supported.
|
|
|
|
W.write<uint16_t>(0);
|
|
|
|
// Symbol type.
|
2021-07-05 04:53:30 +02:00
|
|
|
W.write<uint8_t>(getEncodedType(CSectionRef.MCSec));
|
[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-15 19:40:41 +02:00
|
|
|
// Storage mapping class.
|
2021-07-05 04:53:30 +02:00
|
|
|
W.write<uint8_t>(CSectionRef.MCSec->getMappingClass());
|
[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-15 19:40:41 +02:00
|
|
|
// Reserved (x_stab).
|
|
|
|
W.write<uint32_t>(0);
|
|
|
|
// Reserved (x_snstab).
|
|
|
|
W.write<uint16_t>(0);
|
|
|
|
}
|
|
|
|
|
2019-08-21 00:03:18 +02:00
|
|
|
void XCOFFObjectWriter::writeFileHeader() {
|
2019-07-09 21:21:01 +02:00
|
|
|
// Magic.
|
|
|
|
W.write<uint16_t>(0x01df);
|
|
|
|
// Number of sections.
|
2019-10-28 22:46:22 +01:00
|
|
|
W.write<uint16_t>(SectionCount);
|
2019-07-09 21:21:01 +02:00
|
|
|
// Timestamp field. For reproducible output we write a 0, which represents no
|
|
|
|
// timestamp.
|
|
|
|
W.write<int32_t>(0);
|
|
|
|
// Byte Offset to the start of the symbol table.
|
2019-08-21 00:03:18 +02:00
|
|
|
W.write<uint32_t>(SymbolTableOffset);
|
2019-07-09 21:21:01 +02:00
|
|
|
// Number of entries in the symbol table.
|
2019-08-21 00:03:18 +02:00
|
|
|
W.write<int32_t>(SymbolTableEntryCount);
|
2019-07-09 21:21:01 +02:00
|
|
|
// Size of the optional header.
|
|
|
|
W.write<uint16_t>(0);
|
|
|
|
// Flags.
|
|
|
|
W.write<uint16_t>(0);
|
2019-08-21 00:03:18 +02:00
|
|
|
}
|
2019-07-09 21:21:01 +02:00
|
|
|
|
2019-08-21 00:03:18 +02:00
|
|
|
void XCOFFObjectWriter::writeSectionHeaderTable() {
|
|
|
|
for (const auto *Sec : Sections) {
|
2019-10-28 22:46:22 +01:00
|
|
|
// Nothing to write for this Section.
|
2021-07-05 04:53:30 +02:00
|
|
|
if (Sec->Index == SectionEntry::UninitializedIndex)
|
2019-10-28 22:46:22 +01:00
|
|
|
continue;
|
|
|
|
|
2019-08-21 00:03:18 +02:00
|
|
|
// Write Name.
|
|
|
|
ArrayRef<char> NameRef(Sec->Name, XCOFF::NameSize);
|
|
|
|
W.write(NameRef);
|
|
|
|
|
|
|
|
// Write the Physical Address and Virtual Address. In an object file these
|
|
|
|
// are the same.
|
|
|
|
W.write<uint32_t>(Sec->Address);
|
|
|
|
W.write<uint32_t>(Sec->Address);
|
|
|
|
|
|
|
|
W.write<uint32_t>(Sec->Size);
|
|
|
|
W.write<uint32_t>(Sec->FileOffsetToData);
|
2020-01-30 16:50:49 +01:00
|
|
|
W.write<uint32_t>(Sec->FileOffsetToRelocations);
|
2019-08-21 00:03:18 +02:00
|
|
|
|
2020-01-30 16:50:49 +01:00
|
|
|
// Line number pointer. Not supported yet.
|
2019-08-21 00:03:18 +02:00
|
|
|
W.write<uint32_t>(0);
|
|
|
|
|
2020-01-30 16:50:49 +01:00
|
|
|
W.write<uint16_t>(Sec->RelocationCount);
|
|
|
|
|
|
|
|
// Line number counts. Not supported yet.
|
2019-08-21 00:03:18 +02:00
|
|
|
W.write<uint16_t>(0);
|
|
|
|
|
|
|
|
W.write<int32_t>(Sec->Flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-30 16:50:49 +01:00
|
|
|
void XCOFFObjectWriter::writeRelocation(XCOFFRelocation Reloc,
|
2021-07-05 04:53:30 +02:00
|
|
|
const XCOFFSection &CSection) {
|
2020-01-30 16:50:49 +01:00
|
|
|
W.write<uint32_t>(CSection.Address + Reloc.FixupOffsetInCsect);
|
|
|
|
W.write<uint32_t>(Reloc.SymbolTableIndex);
|
|
|
|
W.write<uint8_t>(Reloc.SignAndSize);
|
|
|
|
W.write<uint8_t>(Reloc.Type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void XCOFFObjectWriter::writeRelocations() {
|
|
|
|
for (const auto *Section : Sections) {
|
2021-07-05 04:53:30 +02:00
|
|
|
if (Section->Index == SectionEntry::UninitializedIndex)
|
2020-01-30 16:50:49 +01:00
|
|
|
// Nothing to write for this Section.
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (const auto *Group : Section->Groups) {
|
|
|
|
if (Group->empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (const auto &Csect : *Group) {
|
|
|
|
for (const auto Reloc : Csect.Relocations)
|
|
|
|
writeRelocation(Reloc, Csect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[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-15 19:40:41 +02:00
|
|
|
void XCOFFObjectWriter::writeSymbolTable(const MCAsmLayout &Layout) {
|
2021-02-24 03:48:58 +01:00
|
|
|
// Write symbol 0 as C_FILE.
|
|
|
|
// FIXME: support 64-bit C_FILE symbol.
|
|
|
|
//
|
|
|
|
// n_name. The n_name of a C_FILE symbol is the source filename when no
|
|
|
|
// auxiliary entries are present. The source filename is alternatively
|
|
|
|
// provided by an auxiliary entry, in which case the n_name of the C_FILE
|
|
|
|
// symbol is `.file`.
|
|
|
|
// FIXME: add the real source filename.
|
|
|
|
writeSymbolName(".file");
|
|
|
|
// n_value. The n_value of a C_FILE symbol is its symbol table index.
|
|
|
|
W.write<uint32_t>(0);
|
|
|
|
// n_scnum. N_DEBUG is a reserved section number for indicating a special
|
|
|
|
// symbolic debugging symbol.
|
|
|
|
W.write<int16_t>(XCOFF::ReservedSectionNum::N_DEBUG);
|
|
|
|
// n_type. The n_type field of a C_FILE symbol encodes the source language and
|
|
|
|
// CPU version info; zero indicates no info.
|
|
|
|
W.write<uint16_t>(0);
|
|
|
|
// n_sclass. The C_FILE symbol provides source file-name information,
|
|
|
|
// source-language ID and CPU-version ID information and some other optional
|
|
|
|
// infos.
|
|
|
|
W.write<uint8_t>(XCOFF::C_FILE);
|
|
|
|
// n_numaux. No aux entry for now.
|
|
|
|
W.write<uint8_t>(0);
|
|
|
|
|
2019-11-25 16:02:01 +01:00
|
|
|
for (const auto &Csect : UndefinedCsects) {
|
2021-07-05 04:53:30 +02:00
|
|
|
writeSymbolTableEntryForControlSection(Csect,
|
|
|
|
XCOFF::ReservedSectionNum::N_UNDEF,
|
|
|
|
Csect.MCSec->getStorageClass());
|
2019-11-25 16:02:01 +01:00
|
|
|
}
|
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
for (const auto *Section : Sections) {
|
2021-07-05 04:53:30 +02:00
|
|
|
if (Section->Index == SectionEntry::UninitializedIndex)
|
2020-01-30 16:50:49 +01:00
|
|
|
// Nothing to write for this Section.
|
2019-10-28 22:46:22 +01:00
|
|
|
continue;
|
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
for (const auto *Group : Section->Groups) {
|
[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
|
|
|
if (Group->empty())
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
const int16_t SectionIndex = Section->Index;
|
[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
|
|
|
for (const auto &Csect : *Group) {
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
// Write out the control section first and then each symbol in it.
|
2021-07-05 04:53:30 +02:00
|
|
|
writeSymbolTableEntryForControlSection(Csect, SectionIndex,
|
|
|
|
Csect.MCSec->getStorageClass());
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
|
2020-01-01 17:23:21 +01:00
|
|
|
for (const auto &Sym : Csect.Syms)
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
writeSymbolTableEntryForCsectMemberLabel(
|
|
|
|
Sym, Csect, SectionIndex, Layout.getSymbolOffset(*(Sym.MCSym)));
|
|
|
|
}
|
|
|
|
}
|
2019-08-21 00:03:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-30 16:50:49 +01:00
|
|
|
void XCOFFObjectWriter::finalizeSectionInfo() {
|
|
|
|
for (auto *Section : Sections) {
|
2021-07-05 04:53:30 +02:00
|
|
|
if (Section->Index == SectionEntry::UninitializedIndex)
|
2020-01-30 16:50:49 +01:00
|
|
|
// Nothing to record for this Section.
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (const auto *Group : Section->Groups) {
|
|
|
|
if (Group->empty())
|
|
|
|
continue;
|
|
|
|
|
2020-06-08 20:51:33 +02:00
|
|
|
for (auto &Csect : *Group) {
|
|
|
|
const size_t CsectRelocCount = Csect.Relocations.size();
|
|
|
|
if (CsectRelocCount >= XCOFF::RelocOverflow ||
|
|
|
|
Section->RelocationCount >= XCOFF::RelocOverflow - CsectRelocCount)
|
|
|
|
report_fatal_error(
|
|
|
|
"relocation entries overflowed; overflow section is "
|
|
|
|
"not implemented yet");
|
|
|
|
|
|
|
|
Section->RelocationCount += CsectRelocCount;
|
|
|
|
}
|
2020-01-30 16:50:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the file offset to the relocation entries.
|
|
|
|
uint64_t RawPointer = RelocationEntryOffset;
|
|
|
|
for (auto Sec : Sections) {
|
2021-07-05 04:53:30 +02:00
|
|
|
if (Sec->Index == SectionEntry::UninitializedIndex || !Sec->RelocationCount)
|
2020-01-30 16:50:49 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Sec->FileOffsetToRelocations = RawPointer;
|
|
|
|
const uint32_t RelocationSizeInSec =
|
|
|
|
Sec->RelocationCount * XCOFF::RelocationSerializationSize32;
|
|
|
|
RawPointer += RelocationSizeInSec;
|
|
|
|
if (RawPointer > UINT32_MAX)
|
|
|
|
report_fatal_error("Relocation data overflowed this object file.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Error check that the number of symbol table entries fits in 32-bits
|
|
|
|
// signed ...
|
|
|
|
if (SymbolTableEntryCount)
|
|
|
|
SymbolTableOffset = RawPointer;
|
|
|
|
}
|
|
|
|
|
[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-15 19:40:41 +02:00
|
|
|
void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) {
|
2021-02-24 03:48:58 +01:00
|
|
|
// The first symbol table entry (at index 0) is for the file name.
|
|
|
|
uint32_t SymbolTableIndex = 1;
|
2019-11-25 16:02:01 +01:00
|
|
|
|
2019-11-26 17:05:26 +01:00
|
|
|
// Calculate indices for undefined symbols.
|
2019-11-25 16:02:01 +01:00
|
|
|
for (auto &Csect : UndefinedCsects) {
|
|
|
|
Csect.Size = 0;
|
|
|
|
Csect.Address = 0;
|
|
|
|
Csect.SymbolTableIndex = SymbolTableIndex;
|
2021-07-05 04:53:30 +02:00
|
|
|
SymbolIndexMap[Csect.MCSec->getQualNameSymbol()] = Csect.SymbolTableIndex;
|
2019-11-25 16:02:01 +01:00
|
|
|
// 1 main and 1 auxiliary symbol table entry for each contained symbol.
|
|
|
|
SymbolTableIndex += 2;
|
|
|
|
}
|
|
|
|
|
2019-08-21 00:03:18 +02:00
|
|
|
// The address corrresponds to the address of sections and symbols in the
|
|
|
|
// object file. We place the shared address 0 immediately after the
|
|
|
|
// section header table.
|
|
|
|
uint32_t Address = 0;
|
|
|
|
// Section indices are 1-based in XCOFF.
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
int32_t SectionIndex = 1;
|
2021-04-06 16:58:39 +02:00
|
|
|
bool HasTDataSection = false;
|
2019-08-21 00:03:18 +02:00
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
for (auto *Section : Sections) {
|
|
|
|
const bool IsEmpty =
|
[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
|
|
|
llvm::all_of(Section->Groups,
|
|
|
|
[](const CsectGroup *Group) { return Group->empty(); });
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
if (IsEmpty)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (SectionIndex > MaxSectionIndex)
|
|
|
|
report_fatal_error("Section index overflow!");
|
|
|
|
Section->Index = SectionIndex++;
|
2019-10-28 22:46:22 +01:00
|
|
|
SectionCount++;
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
|
|
|
|
bool SectionAddressSet = false;
|
2021-04-06 16:58:39 +02:00
|
|
|
// Reset the starting address to 0 for TData section.
|
|
|
|
if (Section->Flags == XCOFF::STYP_TDATA) {
|
|
|
|
Address = 0;
|
|
|
|
HasTDataSection = true;
|
|
|
|
}
|
|
|
|
// Reset the starting address to 0 for TBSS section if the object file does
|
|
|
|
// not contain TData Section.
|
|
|
|
if ((Section->Flags == XCOFF::STYP_TBSS) && !HasTDataSection)
|
|
|
|
Address = 0;
|
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
for (auto *Group : Section->Groups) {
|
[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
|
|
|
if (Group->empty())
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
continue;
|
|
|
|
|
[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
|
|
|
for (auto &Csect : *Group) {
|
2021-07-05 04:53:30 +02:00
|
|
|
const MCSectionXCOFF *MCSec = Csect.MCSec;
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
Csect.Address = alignTo(Address, MCSec->getAlignment());
|
|
|
|
Csect.Size = Layout.getSectionAddressSize(MCSec);
|
|
|
|
Address = Csect.Address + Csect.Size;
|
|
|
|
Csect.SymbolTableIndex = SymbolTableIndex;
|
2020-01-30 16:50:49 +01:00
|
|
|
SymbolIndexMap[MCSec->getQualNameSymbol()] = Csect.SymbolTableIndex;
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
// 1 main and 1 auxiliary symbol table entry for the csect.
|
[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-15 19:40:41 +02:00
|
|
|
SymbolTableIndex += 2;
|
2020-02-18 03:48:38 +01:00
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
for (auto &Sym : Csect.Syms) {
|
|
|
|
Sym.SymbolTableIndex = SymbolTableIndex;
|
2020-01-30 16:50:49 +01:00
|
|
|
SymbolIndexMap[Sym.MCSym] = Sym.SymbolTableIndex;
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
// 1 main and 1 auxiliary symbol table entry for each contained
|
|
|
|
// symbol.
|
|
|
|
SymbolTableIndex += 2;
|
|
|
|
}
|
|
|
|
}
|
[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-15 19:40:41 +02:00
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
if (!SectionAddressSet) {
|
[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
|
|
|
Section->Address = Group->front().Address;
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
SectionAddressSet = true;
|
|
|
|
}
|
2019-08-21 00:03:18 +02:00
|
|
|
}
|
[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-15 19:40:41 +02:00
|
|
|
|
[NFC][XCOFF][AIX] Serialize object file writing for each CsectGroup
Summary:
Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects)
individually when assigning indices, writing symbol table, and
writing section raw data. However, there is already a pattern there,
and we could common up those actions for every CsectGroup. This will
make adding new CsectGroup(Read Write data, Read only data, TC/TOC,
mergeable string) easier, and less error prone.
Reviewed by: sfertile, daltenty, DiggerLin
Approved by: daltenty
Differential Revision: https://reviews.llvm.org/D69112
2019-10-24 17:19:12 +02:00
|
|
|
// Make sure the address of the next section aligned to
|
|
|
|
// DefaultSectionAlign.
|
|
|
|
Address = alignTo(Address, DefaultSectionAlign);
|
|
|
|
Section->Size = Address - Section->Address;
|
2019-08-21 00:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SymbolTableEntryCount = SymbolTableIndex;
|
|
|
|
|
|
|
|
// Calculate the RawPointer value for each section.
|
2021-06-10 13:10:45 +02:00
|
|
|
uint64_t RawPointer = XCOFF::FileHeaderSize32 + auxiliaryHeaderSize() +
|
|
|
|
SectionCount * XCOFF::SectionHeaderSize32;
|
2019-08-21 00:03:18 +02:00
|
|
|
for (auto *Sec : Sections) {
|
2021-07-05 04:53:30 +02:00
|
|
|
if (Sec->Index == SectionEntry::UninitializedIndex || Sec->IsVirtual)
|
2019-10-28 22:46:22 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Sec->FileOffsetToData = RawPointer;
|
|
|
|
RawPointer += Sec->Size;
|
2020-01-30 16:50:49 +01:00
|
|
|
if (RawPointer > UINT32_MAX)
|
|
|
|
report_fatal_error("Section raw data overflowed this object file.");
|
2019-08-21 00:03:18 +02:00
|
|
|
}
|
|
|
|
|
2020-01-30 16:50:49 +01:00
|
|
|
RelocationEntryOffset = RawPointer;
|
2019-08-21 00:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Takes the log base 2 of the alignment and shifts the result into the 5 most
|
|
|
|
// significant bits of a byte, then or's in the csect type into the least
|
|
|
|
// significant 3 bits.
|
|
|
|
uint8_t getEncodedType(const MCSectionXCOFF *Sec) {
|
|
|
|
unsigned Align = Sec->getAlignment();
|
|
|
|
assert(isPowerOf2_32(Align) && "Alignment must be a power of 2.");
|
|
|
|
unsigned Log2Align = Log2_32(Align);
|
|
|
|
// Result is a number in the range [0, 31] which fits in the 5 least
|
|
|
|
// significant bits. Shift this value into the 5 most significant bits, and
|
|
|
|
// bitwise-or in the csect type.
|
|
|
|
uint8_t EncodedAlign = Log2Align << 3;
|
|
|
|
return EncodedAlign | Sec->getCSectType();
|
2019-07-09 21:21:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
std::unique_ptr<MCObjectWriter>
|
|
|
|
llvm::createXCOFFObjectWriter(std::unique_ptr<MCXCOFFObjectTargetWriter> MOTW,
|
|
|
|
raw_pwrite_stream &OS) {
|
2019-08-15 17:54:37 +02:00
|
|
|
return std::make_unique<XCOFFObjectWriter>(std::move(MOTW), OS);
|
2019-07-09 21:21:01 +02:00
|
|
|
}
|