Linker: do not process relocations for symbols with unknown segment type

In decodeElfSymbolTableAndRelocations, when symbol's section is of
unknown type, then do not add it to linker's symbol table.
Signed-off-by: Kacper Nowak <kacper.nowak@intel.com>
This commit is contained in:
Kacper Nowak
2022-07-25 17:31:45 +00:00
committed by Compute-Runtime-Automation
parent 17c5374d42
commit c046824c18
2 changed files with 31 additions and 1 deletions

View File

@@ -177,7 +177,9 @@ void LinkerInput::decodeElfSymbolTableAndRelocations(Elf::Elf<Elf::EI_CLASS_64>
auto symbolSectionName = elf.getSectionName(symbol.shndx);
auto symbolSegment = getSegmentForSection(symbolSectionName);
if (NEO::SegmentType::Unknown == symbolSegment) {
continue;
}
switch (type) {
default:
DEBUG_BREAK_IF(type != Elf::SYMBOL_TABLE_TYPE::STT_NOTYPE);

View File

@@ -514,6 +514,34 @@ TEST(LinkerInputTests, GivenInvalidTextSectionNameWhenDecodingElfTextRelocations
ASSERT_EQ(0u, relocations.size());
}
TEST(LinkerInputTests, whenSymbolHasShndxReferringToSectionOfUnknownTypehenDoNotAddItToLinkerInput) {
NEO::LinkerInput linkerInput = {};
NEO::Elf::ElfFileHeader<NEO::Elf::EI_CLASS_64> header;
MockElf<NEO::Elf::EI_CLASS_64> elf64;
elf64.elfFileHeader = &header;
std::unordered_map<uint32_t, std::string> sectionNames;
sectionNames[0] = ".invalid.aaa";
elf64.setupSecionNames(std::move(sectionNames));
elf64.overrideSymbolName = true;
NEO::Elf::ElfSymbolEntry<NEO::Elf::EI_CLASS_64> symbol;
symbol.info = NEO::Elf::SYMBOL_TABLE_TYPE::STT_OBJECT | NEO::Elf::SYMBOL_TABLE_BIND::STB_GLOBAL << 4;
symbol.name = 0x20;
symbol.other = 0;
symbol.shndx = 0;
symbol.size = 0x8;
symbol.value = 0x4000;
elf64.symbolTable.emplace_back(symbol);
NEO::LinkerInput::SectionNameToSegmentIdMap nameToKernelId;
linkerInput.decodeElfSymbolTableAndRelocations(elf64, nameToKernelId);
auto symbols = linkerInput.getSymbols();
ASSERT_EQ(0u, symbols.size());
}
TEST(LinkerInputTests, GivenValidZebinRelocationTypesWhenDecodingElfTextRelocationsThenCorrectTypeIsSet) {
NEO::LinkerInput linkerInput = {};
NEO::Elf::ElfFileHeader<NEO::Elf::EI_CLASS_64> header;