Skip to content

Commit

Permalink
Linker: do not process relocations for symbols with unknown segment type
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
km-nowak authored and Compute-Runtime-Automation committed Jul 25, 2022
1 parent 17c5374 commit c046824
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion shared/source/compiler_interface/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions shared/test/unit_test/compiler_interface/linker_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c046824

Please sign in to comment.