This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj] - Don't call `unwrapOrErr` in `findSectionByName`.
ClosedPublic

Authored by grimar on Jul 27 2020, 6:27 AM.

Details

Summary

We have a findSectionByName helper that tries to find a section
by it name. It is used in a few places, but never tested.

I'd like to reuse this helper for a different place.
For this, I've changed it to return Expected<> and now it
doesn't use unwrapOrErr anymore too.

Diff Detail

Event Timeline

grimar created this revision.Jul 27 2020, 6:27 AM
Herald added a project: Restricted Project. · View Herald Transcript

It seems to me like findSectionByName should still be able to find a section even if an earlier section had an invalid name. Imagine the following two cases:

object1
+- sec1 (invalid sh_name)
+- sec2 (won't be findable)

object2
+- sec1 (can be found)
+- sec2 (invalid sh_name)

The only difference in these two cases is the section order. The actual section to be found can still be found in both cases, if the invalid name were to just be ignored (probably warned about in the first case).

Maybe that indicates the right thing to do here is just print the warning in findSectionByName instead of this change. What do you think?

llvm/test/tools/llvm-readobj/ELF/mips-abiflags.test
352–353

Setting the name of the SHT_NULL section made it look to me like the null section was significant in some way. Perhaps this could just be an arbitrary SHT_PROGBITS section instead. Same goes for the other tests.

llvm/test/tools/llvm-readobj/ELF/mips-options-sec.test
3–50

All the changes in mips-reginfo.test amd here look good to me, but perhaps you should split the comment and comment-marker additions into a separate NFC commit. Happy for that to be done without review.

llvm/tools/llvm-readobj/ELFDumper.cpp
1293

Maybe "unable to locate the" would be a better string here? That way, you don't have error repeated in the error message, and we won't have a situation in the future where the word "error" appears in a warning.

grimar updated this revision to Diff 281493.Jul 29 2020, 3:13 AM
grimar marked an inline comment as done.
  • Addressed review comments.
  • Update findSectionByName as suggested (now it tries to find a section by name even if unable to read other section names properly).
grimar added inline comments.Jul 29 2020, 3:15 AM
llvm/tools/llvm-readobj/ELFDumper.cpp
1293

Done.

jhenderson added inline comments.Jul 30 2020, 1:22 AM
llvm/test/tools/llvm-readobj/ELF/mips-abiflags.test
384–386

I think these additional "section not found" errors/warnings are confusing the issue of what's important in the test. I'd add the respective missing sections, so that the errors aren't emitted.

Alternatively, I'm not 100% convinced we should have this kind of warning/error at all, since the earlier warning(s) might be sufficient to say there are problems reading the section names. I might be incined to just fallback to the "not found" behaviour in that case, though like I say, I could be persuaded otherwise.

Same goes for all the other test cases.

grimar updated this revision to Diff 281851.Jul 30 2020, 2:37 AM
  • Addressed review comments.
llvm/test/tools/llvm-readobj/ELF/mips-abiflags.test
384–386

Alternatively, I'm not 100% convinced we should have this kind of warning/error at all, since the earlier warning(s) might be sufficient to say there are problems reading the section names. I might be incined to just fallback to the "not found" behaviour

OK. This is simpler and works for me. I've changed the behavior to this one.

jhenderson added inline comments.Jul 30 2020, 2:47 AM
llvm/test/tools/llvm-readobj/ELF/mips-options-sec.test
43

.MIPS.options?

llvm/test/tools/llvm-readobj/ELF/mips-reginfo.test
23

Somewhat tangential, and definitely not part of this patch but "has a wrong size" sounds wrong to me (although I can't explain why). If you get a moment, changing it to "has an incorrect size" would be nice.

jhenderson accepted this revision.Jul 30 2020, 2:48 AM

LGTM, with nit fixed.

This revision is now accepted and ready to land.Jul 30 2020, 2:48 AM
grimar added inline comments.Jul 30 2020, 2:59 AM
llvm/test/tools/llvm-readobj/ELF/mips-reginfo.test
23

I have a plan to cleanup ELFDumper<ELFT>::printMipsReginfo() + refine the corresponding test file similar to as what D84854 did for printMipsOptions(). I'll change the message there.

D84854 , btw, prints:

warning: '[[FILE]]': the .MIPS.options section has a wrong size (0x1)

I guess I'll change it to "the .MIPS.options section has an incorrect size (0x1)" then too.