Index: test/tools/obj2yaml/elf-shlink.yaml =================================================================== --- /dev/null +++ test/tools/obj2yaml/elf-shlink.yaml @@ -0,0 +1,19 @@ +## Check obj2yaml reports a proper error when unable to resolve +## a sh_link reference in a regular section. +## (We had a bug: the error was silently ignored). + +# RUN: yaml2obj %s -o %t.o +# RUN: not obj2yaml %t.o 2>&1 | FileCheck %s -DFILE=%t.o + +## CHECK: Error reading file: [[FILE]]: unable to resolve sh_link reference in section '.test': invalid section index: 42 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .test + Type: SHT_PROGBITS + Link: 42 Index: tools/obj2yaml/elf2yaml.cpp =================================================================== --- tools/obj2yaml/elf2yaml.cpp +++ tools/obj2yaml/elf2yaml.cpp @@ -376,8 +376,12 @@ if (Shdr->sh_link != ELF::SHN_UNDEF) { auto LinkSection = Obj.getSection(Shdr->sh_link); - if (LinkSection.takeError()) - return LinkSection.takeError(); + if (!LinkSection) + return make_error( + "unable to resolve sh_link reference in section '" + S.Name + + "': " + toString(LinkSection.takeError()), + inconvertibleErrorCode()); + NameOrErr = getUniquedSectionName(*LinkSection); if (!NameOrErr) return NameOrErr.takeError();