Index: test/tools/obj2yaml/abs-common-symbols.yaml =================================================================== --- /dev/null +++ test/tools/obj2yaml/abs-common-symbols.yaml @@ -0,0 +1,54 @@ +# RUN: yaml2obj %s > %t +# RUN: obj2yaml %t | FileCheck %s + +# CHECK: Symbols: +# CHECK-NEXT: Global: +# CHECK-NEXT: - Name: absolute1 +# CHECK-NEXT: Index: SHN_ABS +# CHECK-NEXT: Value: 0x0000000000001234 +# CHECK-NEXT: - Name: absolute2 +# CHECK-NEXT: Index: SHN_ABS +# CHECK-NEXT: Value: 0x0000000000004321 +# CHECK-NEXT: - Name: common1 +# CHECK-NEXT: Index: SHN_COMMON +# CHECK-NEXT: - Name: common2 +# CHECK-NEXT: Index: SHN_COMMON +# CHECK-NEXT: - Name: valid_index +# CHECK-NEXT: Section: .text +# CHECK-NEXT: - Name: processor_specific_index1 +# CHECK-NEXT: Index: SHN_HEXAGON_SCOMMON_1 +# CHECK-NEXT: - Name: processor_specific_index2 +# CHECK-NEXT: Index: SHN_HEXAGON_SCOMMON_1 + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_HEXAGON +Sections: + - Name: .text + Type: SHT_PROGBITS +Symbols: + Global: + - Name: absolute1 + Index: SHN_ABS + Value: 0x1234 + - Name: absolute2 + Index: 0xfff1 + Value: 0x4321 + - Name: common1 + Index: SHN_COMMON + - Name: common2 + Index: 0xfff2 + - Name: valid_index + Index: 0x1 + - Name: processor_specific_index1 + Index: 0xff01 + - Name: processor_specific_index2 + Index: SHN_HEXAGON_SCOMMON_1 + +## shn_xindex.o contains a symbol with st_shndx == SHN_XINDEX. +## We do not support it at this moment. +# RUN: not obj2yaml %S/Inputs/shn_xindex.o 2>&1 | FileCheck %s --check-prefix=ERR +# ERR: Error reading file: {{.*}}shn_xindex.o: Feature not yet implemented. Index: tools/obj2yaml/elf2yaml.cpp =================================================================== --- tools/obj2yaml/elf2yaml.cpp +++ tools/obj2yaml/elf2yaml.cpp @@ -276,6 +276,13 @@ return errorToErrorCode(SymbolNameOrErr.takeError()); S.Name = SymbolNameOrErr.get(); + if (Sym->st_shndx >= ELF::SHN_LORESERVE) { + if (Sym->st_shndx == ELF::SHN_XINDEX) + return obj2yaml_error::not_implemented; + S.Index = (ELFYAML::ELF_SHN)Sym->st_shndx; + return obj2yaml_error::success; + } + auto ShdrOrErr = Obj.getSection(Sym, SymTab, ShndxTable); if (!ShdrOrErr) return errorToErrorCode(ShdrOrErr.takeError());