@@ -388,7 +388,7 @@ TEST(LinkerInputTests, GivenTwoGlobalSymbolsOfTypeFunctionEachPointingToDifferen
388388 sectionNames[1 ] = " .data.const" ;
389389 sectionNames[2 ] = " .text.hello" ;
390390
391- elf64.setupSecionNames (std::move (sectionNames));
391+ elf64.setupSectionNames (std::move (sectionNames));
392392 elf64.overrideSymbolName = true ;
393393
394394 elf64.addSymbol (0 , 0x1234000 , 8 , 0 , Elf::STT_FUNC, Elf::STB_GLOBAL);
@@ -405,7 +405,7 @@ TEST(LinkerInputTests, GivenGlobalSymbolOfTypeObjectPointingToDataGlobalSectionW
405405 std::unordered_map<uint32_t , std::string> sectionNames;
406406 sectionNames[0 ] = " .text.abc" ;
407407 sectionNames[1 ] = " .data.global" ;
408- elf64.setupSecionNames (std::move (sectionNames));
408+ elf64.setupSectionNames (std::move (sectionNames));
409409 elf64.overrideSymbolName = true ;
410410
411411 elf64.addSymbol (0 , 0x20 , 8 , 1 , Elf::STT_OBJECT, Elf::STB_GLOBAL);
@@ -428,7 +428,7 @@ TEST(LinkerInputTests, GivenGlobalSymbolOfTypeObjectPointingToDataConstSectionWh
428428 std::unordered_map<uint32_t , std::string> sectionNames;
429429 sectionNames[0 ] = " .text.abc" ;
430430 sectionNames[1 ] = " .data.const" ;
431- elf64.setupSecionNames (std::move (sectionNames));
431+ elf64.setupSectionNames (std::move (sectionNames));
432432 elf64.overrideSymbolName = true ;
433433
434434 elf64.addSymbol (0 , 0 , 8 , 1 , Elf::STT_OBJECT, Elf::STB_GLOBAL);
@@ -452,7 +452,7 @@ TEST(LinkerInputTests, GivenGlobalSymbolOfTypeFuncPointingToFunctionsSectionWhen
452452 std::unordered_map<uint32_t , std::string> sectionNames;
453453 sectionNames[0 ] = " .text.abc" ;
454454 sectionNames[1 ] = functionsSectionName.str ();
455- elf64.setupSecionNames (std::move (sectionNames));
455+ elf64.setupSectionNames (std::move (sectionNames));
456456 elf64.overrideSymbolName = true ;
457457
458458 elf64.addSymbol (0 , 0 , 32 , 1 , Elf::STT_FUNC, Elf::STB_GLOBAL);
@@ -479,7 +479,7 @@ TEST(LinkerInputTests, GivenGlobalSymbolOfTypeDifferentThantObjectOrFuncWhenDeco
479479 std::unordered_map<uint32_t , std::string> sectionNames;
480480 sectionNames[0 ] = " .text.abc" ;
481481 sectionNames[1 ] = " .data.const" ;
482- elf64.setupSecionNames (std::move (sectionNames));
482+ elf64.setupSectionNames (std::move (sectionNames));
483483 elf64.overrideSymbolName = true ;
484484
485485 elf64.addSymbol (0 , 0 , 8 , 0 , Elf::STT_NOTYPE, Elf::STB_GLOBAL);
@@ -490,21 +490,24 @@ TEST(LinkerInputTests, GivenGlobalSymbolOfTypeDifferentThantObjectOrFuncWhenDeco
490490 EXPECT_EQ (0U , linkerInput.getSymbols ().size ());
491491}
492492
493- TEST (LinkerInputTests, GivenGlobalSymbolPointingToSectionDifferentThanInstructionsOrDataWhenDecodingElfThenItIsIgnored ) {
493+ TEST (LinkerInputTests, GivenGlobalSymbolPointingToSectionDifferentThanInstructionsOrDataWhenDecodingElfThenItIsIgnoredAndAddedToExternalSymbols ) {
494494 MockElf<NEO::Elf::EI_CLASS_64> elf64;
495495
496496 std::unordered_map<uint32_t , std::string> sectionNames;
497497 sectionNames[0 ] = " " ; // UNDEF section
498498 sectionNames[1 ] = " .text.abc" ;
499- elf64.setupSecionNames (std::move (sectionNames));
499+ elf64.setupSectionNames (std::move (sectionNames));
500500 elf64.overrideSymbolName = true ;
501501
502- elf64.addSymbol (0 , 0 , 8 , 0 , Elf::STT_OBJECT, Elf::STB_GLOBAL);
502+ constexpr uint32_t externalSymbol = 3 ;
503+ elf64.addSymbol (externalSymbol, 0 , 8 , 0 , Elf::STT_OBJECT, Elf::STB_GLOBAL);
504+ WhiteBox<NEO::LinkerInput> linkerInput;
503505 NEO::LinkerInput::SectionNameToSegmentIdMap nameToKernelId = {{" abc" , 0 }};
504- NEO::LinkerInput linkerInput = {};
505506 linkerInput.decodeElfSymbolTableAndRelocations (elf64, nameToKernelId);
506507 EXPECT_TRUE (linkerInput.isValid ());
507508 EXPECT_EQ (0U , linkerInput.getSymbols ().size ());
509+ EXPECT_EQ (1U , linkerInput.externalSymbols .size ());
510+ EXPECT_EQ (std::to_string (externalSymbol), linkerInput.externalSymbols [0 ]);
508511}
509512
510513TEST (LInkerInputTests, GivenSymbolPointingToInstructionSegmentAndInvalidInstructionSectionNameMappingWhenDecodingElfThenLinkerInputIsInvalid) {
@@ -513,7 +516,7 @@ TEST(LInkerInputTests, GivenSymbolPointingToInstructionSegmentAndInvalidInstruct
513516
514517 std::unordered_map<uint32_t , std::string> sectionNames;
515518 sectionNames[0 ] = " .text.abc" ;
516- elf64.setupSecionNames (std::move (sectionNames));
519+ elf64.setupSectionNames (std::move (sectionNames));
517520 elf64.overrideSymbolName = true ;
518521
519522 elf64.addSymbol (0 , 0 , 8 , 0 , Elf::STT_FUNC, Elf::STB_GLOBAL);
@@ -532,7 +535,7 @@ TEST(LinkerInputTests, GivenInstructionRelocationAndInvalidInstructionSectionNam
532535 sectionNames[0 ] = " .text.abc" ;
533536 sectionNames[1 ] = " .data.const" ;
534537
535- elf64.setupSecionNames (std::move (sectionNames));
538+ elf64.setupSectionNames (std::move (sectionNames));
536539 elf64.addReloc (64 , 0 , Zebin::Elf::R_ZE_SYM_ADDR, 0 , 0 , " 0" );
537540
538541 elf64.overrideSymbolName = true ;
@@ -548,7 +551,7 @@ TEST(LinkerInputTests, GivenRelocationWithSymbolIdOutOfBoundsOfSymbolTableWhenDe
548551 MockElf<NEO::Elf::EI_CLASS_64> elf64;
549552
550553 std::unordered_map<uint32_t , std::string> sectionNames = {{0 , " .text.abc" }};
551- elf64.setupSecionNames (std::move (sectionNames));
554+ elf64.setupSectionNames (std::move (sectionNames));
552555
553556 elf64.addReloc (64 , 0 , Zebin::Elf::R_ZE_SYM_ADDR, 0 , 2 , " symbol" );
554557
@@ -564,7 +567,7 @@ TEST(LinkerInputTests, GivenRelocationToSectionDifferentThanDataOrInstructionsWh
564567
565568 std::unordered_map<uint32_t , std::string> sectionNames = {{0 , " .text.abc" },
566569 {1 , " unknown.section" }};
567- elf64.setupSecionNames (std::move (sectionNames));
570+ elf64.setupSectionNames (std::move (sectionNames));
568571 elf64.addReloc (64 , 0 , Zebin::Elf::R_ZE_SYM_ADDR, 1 , 2 , " symbol" );
569572
570573 NEO::LinkerInput::SectionNameToSegmentIdMap nameToKernelId;
@@ -584,7 +587,7 @@ TEST(LinkerInputTests, GivenGlobalDataRelocationWithLocalSymbolPointingToConstDa
584587 sectionNames[1 ] = " .data.const" ;
585588 sectionNames[2 ] = " .data.global" ;
586589
587- elf64.setupSecionNames (std::move (sectionNames));
590+ elf64.setupSectionNames (std::move (sectionNames));
588591 elf64.addReloc (64 , 10 , Zebin::Elf::R_ZE_SYM_ADDR, 2 , 0 , " 0" );
589592
590593 elf64.overrideSymbolName = true ;
@@ -617,7 +620,7 @@ TEST(LinkerInputTests, GivenInstructionRelocationWithLocalSymbolPointingToFuncti
617620 sectionNames[0 ] = " .text.abc" ;
618621 sectionNames[1 ] = functionsSectionName.str ();
619622
620- elf64.setupSecionNames (std::move (sectionNames));
623+ elf64.setupSectionNames (std::move (sectionNames));
621624 elf64.addReloc (64 , 10 , Zebin::Elf::R_ZE_SYM_ADDR, 0 , 0 , " 0" );
622625
623626 elf64.overrideSymbolName = true ;
@@ -791,7 +794,7 @@ TEST(LinkerInputTests, GivenExternalFunctionsSymbolsUsedInKernelRelocationsWhenP
791794 EXPECT_EQ (kernelName, mockLinkerInput.kernelDependencies [0 ].kernelName );
792795}
793796
794- TEST (LinkerInputTests, GivenNonFunctionRelocationInKernelRelocationsWhenParsingRelocationsForExtFuncUsageForKernelThenDoNotAddKernelDependency ) {
797+ TEST (LinkerInputTests, GivenNonFunctionSymbolRelocationInKernelRelocationsWhenParsingRelocationsForExtFuncUsageForKernelThenDoNotAddKernelDependency ) {
795798 WhiteBox<NEO::LinkerInput> mockLinkerInput;
796799
797800 auto &symbols = mockLinkerInput.symbols ;
@@ -806,11 +809,8 @@ TEST(LinkerInputTests, GivenNonFunctionRelocationInKernelRelocationsWhenParsingR
806809 symbols.emplace (" fun" , symbol2);
807810
808811 for (auto nonFuncRelocationName : {
809- implicitArgsRelocationSymbolName,
810812 std::string_view (" .str" ),
811813 std::string_view (" globalVar" ),
812- Linker::perThreadOff,
813- Linker::subDeviceID,
814814 std::string_view (" " )}) {
815815
816816 NEO::LinkerInput::RelocationInfo relocInfo{};
@@ -822,6 +822,35 @@ TEST(LinkerInputTests, GivenNonFunctionRelocationInKernelRelocationsWhenParsingR
822822 EXPECT_EQ (0u , mockLinkerInput.kernelDependencies .size ());
823823 }
824824}
825+
826+ TEST (LinkerInputTests, GivenExternalSymbolRelocationInKernelRelocationsWhenParsingRelocationsForExtFuncUsageForKernelThenAddOptionalKernelDependency) {
827+ WhiteBox<NEO::LinkerInput> mockLinkerInput;
828+
829+ auto &externalSymbols = mockLinkerInput.externalSymbols ;
830+
831+ externalSymbols.push_back (std::string (implicitArgsRelocationSymbolName));
832+ externalSymbols.push_back (std::string (Linker::perThreadOff));
833+ externalSymbols.push_back (std::string (Linker::subDeviceID));
834+
835+ for (auto relocationName : {
836+ implicitArgsRelocationSymbolName,
837+ Linker::perThreadOff,
838+ Linker::subDeviceID}) {
839+
840+ NEO::LinkerInput::RelocationInfo relocInfo{};
841+ relocInfo.symbolName = relocationName;
842+
843+ std::string kernelName = " kernel" ;
844+ mockLinkerInput.parseRelocationForExtFuncUsage (relocInfo, kernelName);
845+ EXPECT_TRUE (mockLinkerInput.extFunDependencies .empty ());
846+ }
847+
848+ EXPECT_EQ (3u , mockLinkerInput.kernelDependencies .size ());
849+ for (auto &kernelDependency : mockLinkerInput.kernelDependencies ) {
850+ EXPECT_TRUE (kernelDependency.optional );
851+ }
852+ }
853+
825854HWTEST_F (LinkerTests, givenEmptyLinkerInputThenLinkerOutputIsEmpty) {
826855 NEO::LinkerInput linkerInput;
827856 NEO::Linker linker (linkerInput);
@@ -2140,7 +2169,7 @@ TEST_F(LinkerTests, GivenDebugDataWhenApplyingDebugDataRelocationsThenRelocation
21402169 sectionNames[4 ] = " .debug_line" ;
21412170 sectionNames[5 ] = " .data.const" ;
21422171
2143- elf64.setupSecionNames (std::move (sectionNames));
2172+ elf64.setupSectionNames (std::move (sectionNames));
21442173
21452174 NEO::Elf::Elf<NEO::Elf::EI_CLASS_64>::RelocationInfo reloc0 = {};
21462175 reloc0.offset = 64 ;
0 commit comments