[PATCH] D65214: [obj2yaml] - Report a error when unable to resolve a sh_link reference properly.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 24 08:33:25 PDT 2019
grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Because of a bug we did not report a error in the case
shown in the test. With this patch we do.
https://reviews.llvm.org/D65214
Files:
test/tools/obj2yaml/elf-shlink.yaml
tools/obj2yaml/elf2yaml.cpp
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<StringError>(
+ "unable to resolve sh_link reference in section '" + S.Name +
+ "': " + toString(LinkSection.takeError()),
+ inconvertibleErrorCode());
+
NameOrErr = getUniquedSectionName(*LinkSection);
if (!NameOrErr)
return NameOrErr.takeError();
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65214.211517.patch
Type: text/x-patch
Size: 1442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190724/d559e642/attachment.bin>
More information about the llvm-commits
mailing list