@@ -326,6 +326,8 @@ class GOFFObjectWriter : public MCObjectWriter {
326
326
uint32_t EntryEDEsdId;
327
327
uint32_t CodeLDEsdId;
328
328
329
+ std::string FileName;
330
+
329
331
public:
330
332
GOFFObjectWriter (std::unique_ptr<MCGOFFObjectTargetWriter> MOTW,
331
333
raw_pwrite_stream &OS)
@@ -339,16 +341,33 @@ class GOFFObjectWriter : public MCObjectWriter {
339
341
340
342
void writeSymbol (const GOFFSymbol &Symbol, const MCAsmLayout &Layout);
341
343
342
- void writeADAandCodeSectionSymbols (MCAssembler &Asm,
343
- const MCAsmLayout &Layout);
344
+ const MCSectionGOFF *getCodeSection (const MCAssembler &Asm) const {
345
+ for (const MCSection &MCSec : Asm) {
346
+ auto &GSec = cast<MCSectionGOFF>(MCSec);
347
+ if (GSec.isCode ())
348
+ return &GSec;
349
+ }
350
+ llvm_unreachable (" Code CSect not found!\n " );
351
+ return nullptr ;
352
+ }
353
+
354
+ const MCSectionGOFF *getStaticSection (const MCAssembler &Asm) const {
355
+ for (const MCSection &MCSec : Asm) {
356
+ auto &GSec = cast<MCSectionGOFF>(MCSec);
357
+ if (GSec.isStatic ())
358
+ return &GSec;
359
+ }
360
+ llvm_unreachable (" Static CSect not found!\n " );
361
+ return nullptr ;
362
+ }
344
363
345
364
std::pair<GOFFSymbol, GOFFSymbol> getSDEDSymbolsForSection (const MCSectionGOFF& GSection, const MCAsmLayout Layout);
346
365
347
- // Write out all ESD Symbols that own a section. GOFF doesn't have
366
+ // Write out all ESD Symbols that make up a section. GOFF doesn't have
348
367
// "sections" in the way other object file formats like ELF do; instead
349
368
// a GOFF section is defined as a triple of ESD Symbols (SD, ED, PR/LD).
350
- // The PR/LD symbol should own a TXT record that contains the actual
351
- // data of the section.
369
+ // The ED or PR symbol should own a TXT Record that contains the contents
370
+ // of the section itself
352
371
void writeSectionSymbols (const MCSectionGOFF &GSection, MCAssembler &Asm, const MCAsmLayout &Layout);
353
372
354
373
void writeText (const MCSectionGOFF *MCSec, uint32_t EsdId,
@@ -528,27 +547,10 @@ GOFFSymbol GOFFObjectWriter::createWSASymbol(uint32_t ParentEsdId,
528
547
return WSA;
529
548
}
530
549
531
- static uint32_t getADASectionLength (MCAssembler &Asm,
532
- const MCAsmLayout &Layout) {
533
- uint32_t SecLen = 0 ;
534
- for (const MCSection &MCSec : Asm) {
535
- auto &GSec = cast<MCSectionGOFF>(MCSec);
536
- if (GSec.isStatic ()) {
537
- SecLen = Layout.getSectionAddressSize (&MCSec);
538
- }
539
- }
540
-
541
- // The ADA section is not allowed to be zero-length. We also want to
542
- // avoid odd alignments, so we use 2 bytes.
543
- return std::max (SecLen, 2u );
544
- }
545
-
546
550
void GOFFObjectWriter::defineRootSD (MCAssembler &Asm,
547
551
const MCAsmLayout &Layout) {
548
- StringRef FileName = " " ;
549
- if (!Asm.getFileNames ().empty ())
550
- FileName = sys::path::stem ((*(Asm.getFileNames ().begin ())).first );
551
- RootSD = createSDSymbol (FileName.str ().append (" #C" ));
552
+ std::string RootName = FileName + " #C" ;
553
+ RootSD = createSDSymbol (RootName);
552
554
RootSD.BindingScope = GOFF::ESD_BSC_Section;
553
555
RootSD.Executable = GOFF::ESD_EXE_CODE;
554
556
}
@@ -659,8 +661,8 @@ void GOFFObjectWriter::writeSymbolDeclaredInModule(const MCSymbolGOFF &Symbol,
659
661
660
662
void GOFFObjectWriter::executePostLayoutBinding (MCAssembler &Asm,
661
663
const MCAsmLayout &Layout) {
662
- LLVM_DEBUG ( dbgs () << " Entering " << __FUNCTION__ << " \n " );
663
-
664
+ if (!Asm. getFileNames (). empty ())
665
+ FileName = sys::path::stem ((*(Asm. getFileNames (). begin ())). first );
664
666
defineRootSD (Asm, Layout);
665
667
}
666
668
@@ -863,50 +865,6 @@ void GOFFObjectWriter::writeSymbol(const GOFFSymbol &Symbol,
863
865
OS.write (Name.data (), NameLength); // Name
864
866
}
865
867
866
- void GOFFObjectWriter::writeADAandCodeSectionSymbols (
867
- MCAssembler &Asm, const MCAsmLayout &Layout) {
868
- // Write ESD Records for ADA Section
869
- GOFFSymbol ADAED = createWSASymbol (RootSD.EsdId , true );
870
- StringRef FileName = " " ;
871
- if (!Asm.getFileNames ().empty ())
872
- FileName = sys::path::stem ((*(Asm.getFileNames ().begin ())).first );
873
-
874
- GOFFSymbol ADA;
875
- ADA = createPRSymbol (FileName.str ().append (" #S" ), ADAED.EsdId ,
876
- GOFF::ESD_NS_Parts, GOFF::ESD_EXE_DATA,
877
- GOFF::ESD_ALIGN_Quadword, GOFF::ESD_BSC_Section,
878
- getADASectionLength (Asm, Layout));
879
- writeSymbol (ADAED, Layout);
880
- writeSymbol (ADA, Layout);
881
- ADAPREsdId = ADA.EsdId ;
882
-
883
- // Write ESD Records for Code Section
884
- GOFFSymbol ED =
885
- createEDSymbol (" C_CODE64" , RootSD.EsdId , 0 , GOFF::ESD_EXE_CODE, true );
886
-
887
- for (const MCSection &MCSec : Asm) {
888
- auto &GSec = cast<MCSectionGOFF>(MCSec);
889
- if (GSec.isCode ()) {
890
- if (!ED.SectionLength )
891
- ED.SectionLength = Layout.getSectionAddressSize (&MCSec);
892
- }
893
- }
894
-
895
- GOFFSymbol LD = createLDSymbol (RootSD.Name , ED.EsdId );
896
- LD.Executable = GOFF::ESD_EXE_CODE;
897
- if (RootSD.BindingScope == GOFF::ESD_BSC_Section)
898
- LD.BindingScope = GOFF::ESD_BSC_Section;
899
- else
900
- LD.BindingScope = GOFF::ESD_BSC_Library;
901
-
902
- LD.ADAEsdId = ADAPREsdId;
903
-
904
- EntryEDEsdId = ED.EsdId ;
905
- CodeLDEsdId = LD.EsdId ;
906
- writeSymbol (ED, Layout);
907
- writeSymbol (LD, Layout);
908
- }
909
-
910
868
std::pair<GOFFSymbol, GOFFSymbol> GOFFObjectWriter::getSDEDSymbolsForSection (const MCSectionGOFF& GSection, const MCAsmLayout Layout) {
911
869
GOFFSymbol SD = GSection.getRooted () ? RootSD : createSDSymbol (GSection.getName ());
912
870
@@ -922,7 +880,6 @@ std::pair<GOFFSymbol, GOFFSymbol> GOFFObjectWriter::getSDEDSymbolsForSection(con
922
880
return std::make_pair (SD, ED);
923
881
}
924
882
925
-
926
883
void GOFFObjectWriter::writeSectionSymbols (const MCSectionGOFF &GSection,
927
884
MCAssembler &Asm,
928
885
const MCAsmLayout &Layout) {
@@ -936,6 +893,8 @@ void GOFFObjectWriter::writeSectionSymbols(const MCSectionGOFF &GSection,
936
893
if (GSection.isCode ()) {
937
894
GOFFSymbol LD = createLDSymbol (RootSD.Name , SDEDSymbols.second .EsdId );
938
895
LD.BindingScope = GOFF::ESD_BSC_Section;
896
+ EntryEDEsdId = SDEDSymbols.second .EsdId ;
897
+ CodeLDEsdId = LD.EsdId ;
939
898
GOFFSection GoffSec = GOFFSection (LD.EsdId , SDEDSymbols.second .EsdId , SDEDSymbols.first .EsdId );
940
899
writeSymbol (LD, Layout);
941
900
} else if (!GSection.isTextOwnedByED ()) {
@@ -946,14 +905,17 @@ void GOFFObjectWriter::writeSectionSymbols(const MCSectionGOFF &GSection,
946
905
Executability = GSym.value ()->getExecutable ();
947
906
IsOSLinkage = GSym.value ()->isOSLinkage ();
948
907
}
949
- GOFFSymbol PR = createPRSymbol (GSection.getTextOwnerName (), SDEDSymbols.second .EsdId ,
908
+ std::string ADAName = FileName + " #S" ;
909
+ GOFFSymbol PR = createPRSymbol (GSection.isStatic () ? ADAName : GSection.getTextOwnerName (),
910
+ SDEDSymbols.second .EsdId ,
950
911
GOFF::ESD_NS_Parts,
951
912
Executability,
952
913
GOFFSymbol::setGOFFAlignment (GSection.getAlign ()),
953
914
GOFF::ESD_BSC_Section,
954
915
Layout.getSectionAddressSize (&GSection),
955
916
GSection.getLoadBehavior (),
956
917
IsOSLinkage ? GOFF::ESD_LT_OS : GOFF::ESD_LT_XPLink);
918
+ ADAPREsdId = PR.EsdId ;
957
919
writeSymbol (PR, Layout);
958
920
GOFFSection GoffSec = GOFFSection (PR.EsdId , SDEDSymbols.second .EsdId , SDEDSymbols.first .EsdId );
959
921
SectionMap.insert (std::make_pair (&GSection, GoffSec));
@@ -1061,12 +1023,18 @@ uint64_t GOFFObjectWriter::writeObject(MCAssembler &Asm,
1061
1023
writeHeader ();
1062
1024
writeSymbol (RootSD, Layout);
1063
1025
1026
+ // The static and code sections must be written first because the symbols that make up the aforementioned sections
1027
+ // are referenced by several other symbols/sections.
1028
+ writeSectionSymbols (*getStaticSection (Asm), Asm, Layout);
1029
+ writeSectionSymbols (*getCodeSection (Asm), Asm, Layout);
1030
+
1064
1031
for (MCSection &S : Asm) {
1065
1032
auto &GSection = cast<MCSectionGOFF>(S);
1066
1033
if (!(GSection.isCode () || GSection.isStatic ()))
1067
1034
writeSectionSymbols (GSection, Asm, Layout);
1068
1035
}
1069
1036
1037
+ /*
1070
1038
// Process all MCSymbols and generate the ESD Record(s) for them.
1071
1039
// Symbols that are aliases of other symbols need to be processed
1072
1040
// at the end, after the symbols they alias are processed.
@@ -1088,6 +1056,7 @@ uint64_t GOFFObjectWriter::writeObject(MCAssembler &Asm,
1088
1056
static_cast<GOFF::TXTRecordStyle>(MCGOFFSec.getTextStyle());
1089
1057
writeText(&MCGOFFSec, CurrGSec.PEsdId, TextStyle, Asm, Layout);
1090
1058
}
1059
+ */
1091
1060
1092
1061
writeEnd ();
1093
1062
0 commit comments