@@ -308,3 +308,84 @@ TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmAddressClass) {
308308 auto entry_point_addr = module_sp->GetObjectFile ()->GetEntryPointAddress ();
309309 ASSERT_EQ (entry_point_addr.GetAddressClass (), AddressClass::eCode);
310310}
311+
312+ TEST_F (ObjectFileELFTest, SkipsLocalMappingAndDotLSymbols) {
313+ auto ExpectedFile = TestFile::fromYaml (R"(
314+ --- !ELF
315+ FileHeader:
316+ Class: ELFCLASS64
317+ Data: ELFDATA2LSB
318+ Type: ET_EXEC
319+ Machine: EM_RISCV
320+ Flags: [ EF_RISCV_RVC, EF_RISCV_FLOAT_ABI_SINGLE ]
321+ Entry: 0xC0A1B010
322+ Sections:
323+ - Name: .text
324+ Type: SHT_PROGBITS
325+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
326+ Address: 0x0000000000400180
327+ AddressAlign: 0x0000000000000010
328+ Content: 554889E5
329+ - Name: .data
330+ Type: SHT_PROGBITS
331+ Flags: [ SHF_WRITE, SHF_ALLOC ]
332+ Address: 0x0000000000601000
333+ AddressAlign: 0x0000000000000004
334+ Content: 2F000000
335+ - Name: .riscv.attributes
336+ Type: SHT_PROGBITS
337+ Flags: [ SHF_ALLOC ]
338+ Address: 0x0000000000610000
339+ AddressAlign: 0x0000000000000004
340+ Content: "00"
341+ Symbols:
342+ - Name: $d
343+ Type: STT_NOTYPE
344+ Section: .riscv.attributes
345+ Value: 0x0000000000400180
346+ Size: 0x10
347+ Binding: STB_LOCAL
348+ - Name: $x
349+ Type: STT_NOTYPE
350+ Section: .text
351+ Value: 0xC0A1B010
352+ Size: 0x10
353+ Binding: STB_LOCAL
354+ - Name: .Lfoo
355+ Type: STT_OBJECT
356+ Section: .data
357+ Value: 0x0000000000601000
358+ Size: 0x4
359+ Binding: STB_LOCAL
360+ - Name: global_func
361+ Type: STT_FUNC
362+ Section: .text
363+ Value: 0x00000000004001A0
364+ Size: 0x10
365+ Binding: STB_GLOBAL
366+ - Name: global_obj
367+ Type: STT_OBJECT
368+ Section: .data
369+ Value: 0x0000000000601004
370+ Size: 0x4
371+ Binding: STB_GLOBAL
372+ ...
373+ )" );
374+ ASSERT_THAT_EXPECTED (ExpectedFile, llvm::Succeeded ());
375+ auto module_sp = std::make_shared<Module>(ExpectedFile->moduleSpec ());
376+ auto *symtab = module_sp->GetSymtab ();
377+ ASSERT_NE (nullptr , symtab);
378+ EXPECT_EQ (nullptr , module_sp->FindFirstSymbolWithNameAndType (
379+ ConstString (" $d" ), eSymbolTypeAny));
380+ EXPECT_EQ (nullptr , module_sp->FindFirstSymbolWithNameAndType (
381+ ConstString (" $x" ), eSymbolTypeAny));
382+ EXPECT_EQ (nullptr , module_sp->FindFirstSymbolWithNameAndType (
383+ ConstString (" .Lfoo" ), eSymbolTypeAny));
384+ // assert that other symbols are present
385+ const Symbol *global_func = module_sp->FindFirstSymbolWithNameAndType (
386+ ConstString (" global_func" ), eSymbolTypeAny);
387+ ASSERT_NE (nullptr , global_func);
388+ const Symbol *global_obj = module_sp->FindFirstSymbolWithNameAndType (
389+ ConstString (" global_obj" ), eSymbolTypeAny);
390+ ASSERT_NE (nullptr , global_obj);
391+ }
0 commit comments