aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCObjectFileInfo.cpp
diff options
context:
space:
mode:
authorKai Nacke <kai.peter.nacke@ibm.com>2025-06-26 11:52:14 -0400
committerGitHub <noreply@github.com>2025-06-26 11:52:14 -0400
commit33872f12187b352b63e1749652cb18e678fc4f29 (patch)
tree9a3c587a187d4641ed7080e5384ef925463b8372 /llvm/lib/MC/MCObjectFileInfo.cpp
parent6bdfecaea837a07d034b1598a3af38c6f64044f4 (diff)
downloadllvm-33872f12187b352b63e1749652cb18e678fc4f29.zip
llvm-33872f12187b352b63e1749652cb18e678fc4f29.tar.gz
llvm-33872f12187b352b63e1749652cb18e678fc4f29.tar.bz2
[GOFF] Add writing of section symbols (#133799)
Unlike other formats, the GOFF object file format uses a 2 dimensional structure to define the location of data. For example, the equivalent of the ELF .text section is made up of a Section Definition (SD) and a class (Element Definition; ED). The name of the SD symbol depends on the application, while the class has the predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively. Data can be placed into this structure in 2 ways. First, the data (in a text record) can be associated with an ED symbol. To refer to data, a Label Definition (LD) is used to give an offset into the data a name. When binding, the whole data is pulled into the resulting executable, and the addresses given by the LD symbols are resolved. The alternative is to use a Part Definition (PR). In this case, the data (in a text record) is associated with the part. When binding, only the data of referenced PRs is pulled into the resulting binary. Both approaches are used. SD, ED, and PR elements are modeled by nested MCSectionGOFF instances, while LD elements are associated with MCSymbolGOFF instances. At the binary level, a record called "External Symbol Definition" (ESD) is used. The ESD has a type (SD, ED, PR, LD), and depending on the type a different subset of the fields is used.
Diffstat (limited to 'llvm/lib/MC/MCObjectFileInfo.cpp')
-rw-r--r--llvm/lib/MC/MCObjectFileInfo.cpp58
1 files changed, 46 insertions, 12 deletions
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index 9ad56aa..0069d12 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -13,6 +13,7 @@
#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCGOFFAttributes.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSectionCOFF.h"
#include "llvm/MC/MCSectionDXContainer.h"
@@ -546,18 +547,51 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
}
void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
- TextSection = Ctx->getGOFFSection(".text", SectionKind::getText(), nullptr);
- BSSSection = Ctx->getGOFFSection(".bss", SectionKind::getBSS(), nullptr);
- PPA1Section = Ctx->getGOFFSection(".ppa1", SectionKind::getMetadata(),
- TextSection, GOFF::SK_PPA1);
- PPA2Section = Ctx->getGOFFSection(".ppa2", SectionKind::getMetadata(),
- TextSection, GOFF::SK_PPA2);
-
- PPA2ListSection =
- Ctx->getGOFFSection(".ppa2list", SectionKind::getData(), nullptr);
-
- ADASection = Ctx->getGOFFSection(".ada", SectionKind::getData(), nullptr);
- IDRLSection = Ctx->getGOFFSection("B_IDRL", SectionKind::getData(), nullptr);
+ MCSectionGOFF *RootSDSection = Ctx->getGOFFSection(
+ SectionKind::getMetadata(), "#C",
+ GOFF::SDAttr{GOFF::ESD_TA_Rent, GOFF::ESD_BSC_Section});
+
+ MCSectionGOFF *ADAEDSection = Ctx->getGOFFSection(
+ SectionKind::getMetadata(), GOFF::CLASS_WSA,
+ GOFF::EDAttr{false, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
+ GOFF::ESD_TS_ByteOriented, GOFF::ESD_BA_Merge,
+ GOFF::ESD_LB_Deferred, GOFF::ESD_RQ_1,
+ GOFF::ESD_ALIGN_Quadword, 0},
+ RootSDSection);
+ ADASection = Ctx->getGOFFSection(SectionKind::getData(), "#S",
+ GOFF::PRAttr{false, GOFF::ESD_EXE_DATA,
+ GOFF::ESD_LT_XPLink,
+ GOFF::ESD_BSC_Section, 0},
+ ADAEDSection);
+
+ TextSection = Ctx->getGOFFSection(
+ SectionKind::getText(), GOFF::CLASS_CODE,
+ GOFF::EDAttr{true, GOFF::ESD_RMODE_64, GOFF::ESD_NS_NormalName,
+ GOFF::ESD_TS_ByteOriented, GOFF::ESD_BA_Concatenate,
+ GOFF::ESD_LB_Initial, GOFF::ESD_RQ_0,
+ GOFF::ESD_ALIGN_Doubleword, 0},
+ RootSDSection);
+
+ MCSectionGOFF *PPA2ListEDSection = Ctx->getGOFFSection(
+ SectionKind::getMetadata(), GOFF::CLASS_PPA2,
+ GOFF::EDAttr{true, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
+ GOFF::ESD_TS_ByteOriented, GOFF::ESD_BA_Merge,
+ GOFF::ESD_LB_Initial, GOFF::ESD_RQ_0,
+ GOFF::ESD_ALIGN_Doubleword, 0},
+ RootSDSection);
+ PPA2ListSection = Ctx->getGOFFSection(SectionKind::getData(), ".&ppa2",
+ GOFF::PRAttr{true, GOFF::ESD_EXE_DATA,
+ GOFF::ESD_LT_OS,
+ GOFF::ESD_BSC_Section, 0},
+ PPA2ListEDSection);
+
+ IDRLSection = Ctx->getGOFFSection(
+ SectionKind::getData(), "B_IDRL",
+ GOFF::EDAttr{true, GOFF::ESD_RMODE_64, GOFF::ESD_NS_NormalName,
+ GOFF::ESD_TS_Structured, GOFF::ESD_BA_Concatenate,
+ GOFF::ESD_LB_NoLoad, GOFF::ESD_RQ_0,
+ GOFF::ESD_ALIGN_Doubleword, 0},
+ RootSDSection);
}
void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {