Skip to content

Commit c34a091

Browse files
petechouigcbot
authored andcommitted
[Autobackout][FuncReg]Revert of change: c471836
ZEBIN ELF spec update. Clean up the e_type, e_machine and e_flags fields in ELF header, and put the product family, the gfxcore family, and the target metadata into ELF notes.
1 parent 933e594 commit c34a091

File tree

7 files changed

+125
-188
lines changed

7 files changed

+125
-188
lines changed

IGC/AdaptorOCL/OCL/sp/zebin_builder.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,31 @@ ZEBinaryBuilder::ZEBinaryBuilder(
2727
{
2828
G6HWC::InitializeCapsGen8(&mHWCaps);
2929

30-
mBuilder.setProductFamily(plat.eProductFamily);
30+
// IGC only generates executable
31+
mBuilder.setFileType(ELF_TYPE_ZEBIN::ET_ZEBIN_EXE);
32+
33+
mBuilder.setMachine(plat.eProductFamily);
3134

3235
// FIXME: Most fields leaves as 0
33-
TargetMetadata metadata;
34-
metadata.generatorSpecificFlags = TargetMetadata::GeneratorSpecificFlags::NONE;
35-
metadata.minHwRevisionId = plat.usRevId;
36-
metadata.maxHwRevisionId = plat.usRevId;
37-
metadata.generatorId = TargetMetadata::GeneratorId::IGC;
38-
mBuilder.setTargetMetadata(metadata);
36+
TargetFlags tf;
37+
tf.generatorSpecificFlags = TargetFlags::GeneratorSpecificFlags::NONE;
38+
tf.minHwRevisionId = plat.usRevId;
39+
tf.maxHwRevisionId = plat.usRevId;
40+
tf.generatorId = TargetFlags::GeneratorId::IGC;
41+
mBuilder.setTargetFlag(tf);
3942

4043
addProgramScopeInfo(programInfo);
4144

4245
if (spvData != nullptr)
4346
addSPIRV(spvData, spvSize);
4447
}
4548

46-
void ZEBinaryBuilder::setGfxCoreFamily(uint32_t value)
49+
void ZEBinaryBuilder::setGfxCoreFamilyToELFMachine(uint32_t value)
4750
{
48-
mBuilder.setGfxCoreFamily(value);
51+
TargetFlags tf = mBuilder.getTargetFlag();
52+
tf.machineEntryUsesGfxCoreInsteadOfProductFamily = true;
53+
mBuilder.setTargetFlag(tf);
54+
mBuilder.setMachine(value);
4955
}
5056

5157
void ZEBinaryBuilder::createKernel(

IGC/AdaptorOCL/OCL/sp/zebin_builder.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ class ZEBinaryBuilder : DisallowCopy
4040
ZEBinaryBuilder(const PLATFORM plat, bool is64BitPointer,
4141
const IGC::SOpenCLProgramInfo& programInfo, const uint8_t* spvData, uint32_t spvSize);
4242

43-
// Set the given GfxCoreFamily as the specified value.
44-
void setGfxCoreFamily(uint32_t value);
43+
// Set the given GfxCoreFamily value to elfFileHeader::e_machine. Also set the flag
44+
// TargetFlags::machineEntryUsesGfxCoreInsteadOfProductFamily.
45+
// The default value of e_machine is ProductFamily. This API will set e_machine to
46+
// given value which is supposed to be GfxCoreFamily.
47+
void setGfxCoreFamilyToELFMachine(uint32_t value);
4548

46-
/// add kernel information. Also create kernel metadata information for .ze_info
49+
/// add kernel information. Also create kernel metadata inforamtion for .ze_info
4750
/// This function can be called several times for adding different kernel information
4851
/// into this ZEObject
4952
/// The given rawIsaBinary must be lived through the entire ZEBinaryBuilder life

IGC/VectorCompiler/igcdeps/src/PatchTokens.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void CGen8CMProgram::GetZEBinary(llvm::raw_pwrite_stream &programBinary,
180180
llvm::raw_string_ostream ErrLog{m_ErrorLog};
181181
iOpenCL::ZEBinaryBuilder zebuilder{m_Platform, pointerSizeInBytes == 8,
182182
*m_programInfo, nullptr, 0};
183-
zebuilder.setGfxCoreFamily(m_Platform.eRenderCoreFamily);
183+
zebuilder.setGfxCoreFamilyToELFMachine(m_Platform.eRenderCoreFamily);
184184

185185
for (const auto &kernel : m_kernels) {
186186
zebuilder.createKernel(

IGC/ZEBinWriter/zebin/source/ZEELF.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ SPDX-License-Identifier: MIT
2020

2121
namespace zebin {
2222

23-
// ELF machine architecture
24-
enum {
25-
EM_INTELGT = 205,
23+
// ELF file type for ELF32_Ehdr::e_type
24+
enum ELF_TYPE_ZEBIN
25+
{
26+
ET_ZEBIN_NONE = 0x0,
27+
28+
ET_ZEBIN_REL = 0xff11, // A relocatable ZE binary file
29+
ET_ZEBIN_EXE = 0xff12, // An executable ZE binary file
30+
ET_ZEBIN_DYN = 0xff13, // A shared object ZE binary file
2631
};
2732

2833
// ELF section type for ELF32_Shdr::sh_type
@@ -44,14 +49,9 @@ enum R_TYPE_ZEBIN
4449
R_ZE_SYM_ADDR_32_HI = 3 // higher 32bits of 64-bit address
4550
};
4651

47-
// ELF note type for INTELGT
48-
enum {
49-
NT_INTELGT_PRODUCT_FAMILY = 1,
50-
NT_INTELGT_GFXCORE_FAMILY = 2,
51-
NT_INTELGT_TARGET_METADATA = 3,
52-
};
52+
// ELF32_Ehdr::e_flags
53+
struct TargetFlags {
5354

54-
struct TargetMetadata {
5555
// bit[7:0]: dedicated for specific generator (meaning based on generatorId)
5656
enum GeneratorSpecificFlags : uint8_t {
5757
NONE = 0
@@ -76,8 +76,10 @@ struct TargetMetadata {
7676
// 0 - ignore minHwRevisionId and maxHwRevisionId
7777
// 1 - underlying device must match specified revisionId info
7878
bool disableExtendedValidation : 1;
79-
// bit[15:15]: reserved bit for future use
80-
bool reservedBit : 1;
79+
// bit[15:15]:
80+
// 0 - elfFileHeader::machine is PRODUCT_FAMILY
81+
// 1 - elfFileHeader::machine is GFXCORE_FAMILY
82+
bool machineEntryUsesGfxCoreInsteadOfProductFamily : 1;
8183
// bit[20:16]: max compatible device revision Id (stepping)
8284
uint8_t maxHwRevisionId : 5;
8385
// bit[23:21]: generator of this device binary. Value defined in above GeneratorId
@@ -89,8 +91,6 @@ struct TargetMetadata {
8991
};
9092
};
9193

92-
static_assert(sizeof(TargetMetadata) == sizeof(uint32_t), "TargetMetadata should be packed");
93-
9494
} // namespace zebin
9595

9696
#endif // ZE_ELF_H

IGC/ZEBinWriter/zebin/source/ZEELFObjectBuilder.cpp

Lines changed: 11 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ SPDX-License-Identifier: MIT
1616

1717
#include "llvm/MC/StringTableBuilder.h"
1818
#include "llvm/Support/EndianStream.h"
19-
#include "llvm/Support/MathExtras.h"
2019
#include "llvm/Support/raw_ostream.h"
2120

2221
#ifndef ZEBinStandAloneBuild
2322
#include "common/LLVMWarningsPop.hpp"
2423
#endif
2524

2625
#include <iostream>
27-
#include <tuple>
2826
#include "Probe/Assertion.h"
2927

3028
namespace zebin {
@@ -78,19 +76,15 @@ class ELFWriter {
7876
uint64_t writeRelocTab(const RelocationListTy& relocs, bool isRelFormat);
7977
// write ze info section
8078
uint64_t writeZEInfo();
81-
// write .note.intelgt.compat section
82-
std::pair<uint64_t, uint64_t> writeCompatibilityNote();
8379
// write string table
8480
uint64_t writeStrTab();
8581
// write section header
8682
void writeSectionHeader();
8783
// write the section header's offset into ELF header
8884
void writeSectionHdrOffset(uint64_t offset);
89-
// write number of zero bytes
85+
// wirite number of zero bytes
9086
void writePadding(uint32_t size);
9187

92-
// The name writeWord seems confusing. Both ELF32 and ELF64 words are
93-
// uint32_t.
9488
void writeWord(uint64_t Word) {
9589
if (is64Bit())
9690
m_W.write<uint64_t>(Word);
@@ -153,7 +147,7 @@ ZEELFObjectBuilder::addStandardSection(
153147
{
154148
IGC_ASSERT(type != ELF::SHT_NULL);
155149
// calculate the required padding to satisfy alignment requirement
156-
// The original data size is (size + padding)
150+
// The origanl data size is (size + padding)
157151
uint32_t need_padding_for_align = (align == 0) ?
158152
0 : align - ((size + padding) % align);
159153
if (need_padding_for_align == align)
@@ -543,50 +537,6 @@ uint64_t ELFWriter::writeZEInfo()
543537
return m_W.OS.tell() - start_off;
544538
}
545539

546-
std::pair<uint64_t, uint64_t> ELFWriter::writeCompatibilityNote() {
547-
auto padToRequiredAlign = [&]() {
548-
// The alignment of the Elf word, name and descriptor is 4.
549-
// Implementations differ from the specification here: in practice all
550-
// variants align both the name and descriptor to 4-bytes.
551-
uint64_t cur = m_W.OS.tell();
552-
uint64_t next = llvm::alignTo(cur, 4);
553-
writePadding(next - cur);
554-
};
555-
556-
auto writeOneNote = [&](StringRef owner, auto desc, uint32_t type) {
557-
// It's easier to use uint32_t directly now because both Elf32_Word and
558-
// Elf64_Word are uint32_t.
559-
// TODO: Use template implementation to handle ELF32 and ELF64 cases.
560-
m_W.write<uint32_t>(owner.size() + 1);
561-
m_W.write<uint32_t>(sizeof(desc));
562-
m_W.write<uint32_t>(type);
563-
m_W.OS << owner << '\0';
564-
padToRequiredAlign();
565-
m_W.write(desc);
566-
padToRequiredAlign();
567-
};
568-
569-
// Align the section offset to the required alignment first.
570-
// TODO: Handle the section alignment in a more generic place..
571-
padToRequiredAlign();
572-
uint64_t start_off = m_W.OS.tell();
573-
// write NT_INTELGT_PRODUCT_FAMILY
574-
writeOneNote("IntelGT",
575-
m_ObjBuilder.m_productFamily,
576-
NT_INTELGT_PRODUCT_FAMILY);
577-
578-
// write NT_INTELGT_GFXCORE_FAMILY_
579-
writeOneNote("IntelGT",
580-
m_ObjBuilder.m_gfxCoreFamily,
581-
NT_INTELGT_GFXCORE_FAMILY);
582-
583-
// write NT_INTELGT_TARGET_METADATA
584-
writeOneNote("IntelGT",
585-
m_ObjBuilder.m_metadata.packed,
586-
NT_INTELGT_TARGET_METADATA);
587-
return std::make_pair(start_off, m_W.OS.tell() - start_off);
588-
}
589-
590540
uint64_t ELFWriter::writeStrTab()
591541
{
592542
uint64_t start_off = m_W.OS.tell();
@@ -689,21 +639,6 @@ void ELFWriter::writeSections()
689639
(m_SectionHdrEntries.size() + 1) : 0;
690640
break;
691641

692-
case ELF::SHT_NOTE: {
693-
// Currently we don't seem to reorder strings in the .strtab, and
694-
// the offset returned by LLVM StringTableBuilder::add() will still
695-
// be valid, so the section name can be checked in this way. Other
696-
// possibilities are creating a new section kind and set the
697-
// appropriate section pointer, or emitting .strtab before the note
698-
// section.
699-
auto strtabSize = m_StrTabBuilder.getSize();
700-
if (entry.name == m_StrTabBuilder.add(m_ObjBuilder.m_CompatNoteName)) {
701-
IGC_ASSERT(entry.name < strtabSize);
702-
std::tie(entry.offset, entry.size) = writeCompatibilityNote();
703-
break;
704-
}
705-
}
706-
707642
default:
708643
IGC_ASSERT(0);
709644
break;
@@ -747,11 +682,11 @@ void ELFWriter::writeHeader()
747682
// e_ident padding
748683
m_W.OS.write_zeros(ELF::EI_NIDENT - ELF::EI_OSABI);
749684

750-
// e_type: Currently IGC always emits a relocatable file
751-
m_W.write<uint16_t>(ELF::ET_REL);
685+
// e_type
686+
m_W.write<uint16_t>(m_ObjBuilder.m_fileType);
752687

753688
// e_machine
754-
m_W.write<uint16_t>(EM_INTELGT);
689+
m_W.write<uint16_t>(m_ObjBuilder.m_machineType);
755690

756691
// e_version
757692
m_W.write<uint32_t>(0);
@@ -766,7 +701,7 @@ void ELFWriter::writeHeader()
766701
writeWord(0);
767702

768703
// e_flags
769-
m_W.write<uint32_t>(0);
704+
m_W.write<uint32_t>(m_ObjBuilder.m_flags.packed);
770705

771706
// e_ehsize = ELF header size
772707
m_W.write<uint16_t>(is64Bit() ?
@@ -896,16 +831,11 @@ void ELFWriter::createSectionHdrEntries()
896831
}
897832

898833
// .ze_info
899-
// every object must have exactly one ze_info section
900-
IGC_ASSERT(m_ObjBuilder.m_zeInfoSection);
901-
createSectionHdrEntry(m_ObjBuilder.m_ZEInfoName, SHT_ZEBIN_ZEINFO,
902-
m_ObjBuilder.m_zeInfoSection.get());
903-
++index;
904-
905-
// .note.intelgt.compat
906-
// Create the compatibility note section
907-
createSectionHdrEntry(m_ObjBuilder.m_CompatNoteName, ELF::SHT_NOTE);
908-
++index;
834+
if (m_ObjBuilder.m_zeInfoSection) {
835+
createSectionHdrEntry(m_ObjBuilder.m_ZEInfoName, SHT_ZEBIN_ZEINFO,
836+
m_ObjBuilder.m_zeInfoSection.get());
837+
++index;
838+
}
909839

910840
// .strtab
911841
m_StringTableIndex = index;

IGC/ZEBinWriter/zebin/source/ZEELFObjectBuilder.hpp

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,41 @@ class ZEELFObjectBuilder {
4848
typedef int32_t SectionID;
4949

5050
public:
51-
ZEELFObjectBuilder(bool is64Bit) : m_is64Bit(is64Bit)
51+
// Each ZEELFObjectBuilder creates one ELF Object
52+
ZEELFObjectBuilder(bool is64Bit,
53+
ELF_TYPE_ZEBIN fileType,
54+
uint32_t machine,
55+
TargetFlags flags)
56+
: m_is64Bit(is64Bit),
57+
m_fileType(fileType),
58+
m_machineType(machine),
59+
m_flags(flags) {}
60+
61+
ZEELFObjectBuilder(bool is64Bit)
62+
: m_is64Bit(is64Bit)
5263
{
53-
m_metadata.packed = 0;
64+
m_fileType = ET_ZEBIN_NONE;
65+
m_machineType = 0;
66+
m_flags.packed = 0;
5467
}
5568

5669
~ZEELFObjectBuilder() {}
5770

58-
void setProductFamily(uint32_t family) { m_productFamily = family; }
59-
uint32_t getProductFamily() const { return m_productFamily; }
71+
/// Set elfFileHeader::e_type value
72+
void setFileType(ELF_TYPE_ZEBIN fileType)
73+
{ m_fileType = fileType; }
6074

61-
void setGfxCoreFamily(uint32_t family) { m_gfxCoreFamily = family; }
62-
uint32_t getGfxCoreFamily() const { return m_gfxCoreFamily; }
75+
/// Set elfFileHeader::e_machine value
76+
void setMachine(uint32_t machine)
77+
{ m_machineType = machine; }
6378

64-
void setTargetMetadata(TargetMetadata metadata) { m_metadata = metadata; }
65-
TargetMetadata getTargetMetadata() const { return m_metadata; }
79+
/// Set elfFileHeader::e_flags
80+
void setTargetFlag(TargetFlags flags)
81+
{ m_flags = flags; }
82+
83+
/// Get elfFileHeader::e_flags
84+
TargetFlags getTargetFlag() const
85+
{ return m_flags; }
6686

6787
// add a text section contains gen binary
6888
// - name: section name. This is usually the kernel or function name of
@@ -336,29 +356,28 @@ class ZEELFObjectBuilder {
336356

337357
private:
338358
// place holder for section default name
339-
const std::string m_TextName = ".text";
340-
const std::string m_DataName = ".data";
341-
const std::string m_BssName = ".bss";
342-
const std::string m_SymTabName = ".symtab";
343-
const std::string m_RelName = ".rel";
344-
const std::string m_RelaName = ".rela";
345-
const std::string m_SpvName = ".spv";
346-
const std::string m_VISAAsmName = ".visaasm";
347-
const std::string m_DebugName = ".debug_info";
348-
const std::string m_ZEInfoName = ".ze_info";
349-
const std::string m_GTPinInfoName = ".gtpin_info";
350-
const std::string m_MiscName = ".misc";
351-
const std::string m_CompatNoteName = ".note.intelgt.compat";
352-
const std::string m_StrTabName = ".strtab";
359+
const std::string m_TextName = ".text";
360+
const std::string m_DataName = ".data";
361+
const std::string m_BssName = ".bss";
362+
const std::string m_SymTabName = ".symtab";
363+
const std::string m_RelName = ".rel";
364+
const std::string m_RelaName = ".rela";
365+
const std::string m_SpvName = ".spv";
366+
const std::string m_VISAAsmName = ".visaasm";
367+
const std::string m_DebugName = ".debug_info";
368+
const std::string m_ZEInfoName = ".ze_info";
369+
const std::string m_GTPinInfoName = ".gtpin_info";
370+
const std::string m_MiscName = ".misc";
371+
const std::string m_StrTabName = ".strtab";
353372

354373
private:
355374
// 32 or 64 bit object
356375
bool m_is64Bit;
357376

358-
// information used to generate .note.intelgt.compat
359-
uint32_t m_productFamily = 0;
360-
uint32_t m_gfxCoreFamily = 0;
361-
TargetMetadata m_metadata;
377+
// information for ELF header
378+
ELF_TYPE_ZEBIN m_fileType; // e_type
379+
uint32_t m_machineType; // e_machine
380+
TargetFlags m_flags; // e_flags
362381

363382
StandardSectionListTy m_textSections;
364383
StandardSectionListTy m_dataAndbssSections; // data and bss sections

0 commit comments

Comments
 (0)