Skip to content

Commit c046824

Browse files
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 <[email protected]>
1 parent 17c5374 commit c046824

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

shared/source/compiler_interface/linker.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ void LinkerInput::decodeElfSymbolTableAndRelocations(Elf::Elf<Elf::EI_CLASS_64>
177177

178178
auto symbolSectionName = elf.getSectionName(symbol.shndx);
179179
auto symbolSegment = getSegmentForSection(symbolSectionName);
180-
180+
if (NEO::SegmentType::Unknown == symbolSegment) {
181+
continue;
182+
}
181183
switch (type) {
182184
default:
183185
DEBUG_BREAK_IF(type != Elf::SYMBOL_TABLE_TYPE::STT_NOTYPE);

shared/test/unit_test/compiler_interface/linker_tests.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,34 @@ TEST(LinkerInputTests, GivenInvalidTextSectionNameWhenDecodingElfTextRelocations
514514
ASSERT_EQ(0u, relocations.size());
515515
}
516516

517+
TEST(LinkerInputTests, whenSymbolHasShndxReferringToSectionOfUnknownTypehenDoNotAddItToLinkerInput) {
518+
NEO::LinkerInput linkerInput = {};
519+
NEO::Elf::ElfFileHeader<NEO::Elf::EI_CLASS_64> header;
520+
MockElf<NEO::Elf::EI_CLASS_64> elf64;
521+
elf64.elfFileHeader = &header;
522+
523+
std::unordered_map<uint32_t, std::string> sectionNames;
524+
sectionNames[0] = ".invalid.aaa";
525+
elf64.setupSecionNames(std::move(sectionNames));
526+
elf64.overrideSymbolName = true;
527+
528+
NEO::Elf::ElfSymbolEntry<NEO::Elf::EI_CLASS_64> symbol;
529+
symbol.info = NEO::Elf::SYMBOL_TABLE_TYPE::STT_OBJECT | NEO::Elf::SYMBOL_TABLE_BIND::STB_GLOBAL << 4;
530+
symbol.name = 0x20;
531+
symbol.other = 0;
532+
symbol.shndx = 0;
533+
symbol.size = 0x8;
534+
symbol.value = 0x4000;
535+
536+
elf64.symbolTable.emplace_back(symbol);
537+
538+
NEO::LinkerInput::SectionNameToSegmentIdMap nameToKernelId;
539+
linkerInput.decodeElfSymbolTableAndRelocations(elf64, nameToKernelId);
540+
541+
auto symbols = linkerInput.getSymbols();
542+
ASSERT_EQ(0u, symbols.size());
543+
}
544+
517545
TEST(LinkerInputTests, GivenValidZebinRelocationTypesWhenDecodingElfTextRelocationsThenCorrectTypeIsSet) {
518546
NEO::LinkerInput linkerInput = {};
519547
NEO::Elf::ElfFileHeader<NEO::Elf::EI_CLASS_64> header;

0 commit comments

Comments
 (0)