This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Fix GCC8 warnings about "fall through", NFCI
ClosedPublic

Authored by Hahnfeld on Mar 1 2019, 10:29 AM.

Details

Summary

Add break statements in Object/ELF.cpp since the code should consider the
generic tags for Hexagon, MIPS, and PPC. Add a test (copied from llvm-readobj)
to show that this works correctly (earlier versions of this patch would have
asserted).

The warnings in X86ELFObjectWriter.cpp are actually false-positives since
the nested switch() handles all possible values and returns in all cases.
Make this explicit by adding llvm_unreachable's.

Diff Detail

Repository
rL LLVM

Event Timeline

Hahnfeld created this revision.Mar 1 2019, 10:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2019, 10:29 AM
ruiu added a subscriber: ruiu.Mar 1 2019, 4:11 PM
ruiu added inline comments.
llvm/lib/Object/ELF.cpp
441 ↗(On Diff #188939)

Looks like in LLVM something like "Invalid dynamic tag type" is more common error message to pass to llvm_unreachable.

llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
116 ↗(On Diff #188939)

Ditto -- I'd pass "Invalid relocation type".

ruiu accepted this revision.Mar 1 2019, 4:13 PM

LGTM with these changes.

This revision is now accepted and ready to land.Mar 1 2019, 4:13 PM
MaskRay added a comment.EditedMar 1 2019, 11:53 PM

getDynamicTagAsString is used by llvm-objdump and it'd be better if llvm-objdump can parse some malformed binaries (with bad .dynsym). If the tag is unknown, falling back to the default label (return "<unknown:>0x"...) may make more sense.

getDynamicTagAsString is used by llvm-objdump and it'd be better if llvm-objdump can parse some malformed binaries (with bad .dynsym). If the tag is unknown, falling back to the default label (return "<unknown:>0x"...) may make more sense.

I think we could just add a break and handle that case in the generic switch below. But I think you're right, the current patch would break for Hexagon, MIPS and PPC64. I tested with assertions enabled, but maybe there is no test case exercising this code path?

getDynamicTagAsString is used by llvm-objdump and it'd be better if llvm-objdump can parse some malformed binaries (with bad .dynsym). If the tag is unknown, falling back to the default label (return "<unknown:>0x"...) may make more sense.

I think we could just add a break and handle that case in the generic switch below. But I think you're right, the current patch would break for Hexagon, MIPS and PPC64. I tested with assertions enabled, but maybe there is no test case exercising this code path?

Yes. For this patch using break; should be good enough. There may not be tests for such corrupted binaries.

Hahnfeld updated this revision to Diff 189049.Mar 2 2019, 7:53 AM
Hahnfeld marked 2 inline comments as done.
Hahnfeld edited the summary of this revision. (Show Details)

Replace llvm_unreachables in Object/ELF.cpp by break statements and add test to exercise this code path.

Hahnfeld requested review of this revision.Mar 2 2019, 7:54 AM

I think we could just add a break and handle that case in the generic switch below. But I think you're right, the current patch would break for Hexagon, MIPS and PPC64. I tested with assertions enabled, but maybe there is no test case exercising this code path?

Yes. For this patch using break; should be good enough. There may not be tests for such corrupted binaries.

I've added one which would have asserted in the previous version of this patch.

MaskRay added inline comments.Mar 2 2019, 8:36 PM
llvm/test/tools/llvm-objdump/elf-dynamic-section-machine-specific.test
1 ↗(On Diff #189049)

This file duplicates test/tools/llvm-readobj/elf-dynamic-tags-machine-specific.test

Does FileCheck %S/../llvm-readobj/xxxxx.test work?

Hahnfeld marked an inline comment as done.Mar 3 2019, 4:43 AM
Hahnfeld added inline comments.
llvm/test/tools/llvm-objdump/elf-dynamic-section-machine-specific.test
1 ↗(On Diff #189049)

Yes, but from what I've seen in reviews so far it's generally not a good idea to reuse tests for two separate tools. And it wouldn't work anyway because the format is different.

What we could do though is moving the ELF description to some INPUTS/ and use it in both tests. That would leave the checks separate, but de-duplicate the yaml content. Let me know if you think that's worth it.

MaskRay added inline comments.Mar 3 2019, 6:17 AM
llvm/test/tools/llvm-objdump/elf-dynamic-section-machine-specific.test
1 ↗(On Diff #189049)

Sorry my previous comment was a bit off. The check lines are separate from the rest of the input file. So it should be possible to use llvm-objdump <some operations> %S/../llvm-readobj/xxx.test | FileCheck %s

Hahnfeld updated this revision to Diff 189081.Mar 3 2019, 7:10 AM

Move common ELF description to Inputs/.

Hahnfeld marked 3 inline comments as done.Mar 3 2019, 7:11 AM
Hahnfeld added inline comments.
llvm/test/tools/llvm-objdump/elf-dynamic-section-machine-specific.test
1 ↗(On Diff #189049)

I've put it into %S/../llvm-readobj/Inputs/ which should make the intent clear that the file is used by multiple tests.

Hahnfeld marked an inline comment as done.Mar 12 2019, 2:57 AM

Gentle ping

MaskRay added inline comments.Mar 12 2019, 4:08 AM
llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
116 ↗(On Diff #188939)

Is this done?

Hahnfeld marked 2 inline comments as done.Mar 12 2019, 4:14 AM
Hahnfeld added inline comments.
llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
116 ↗(On Diff #188939)

I've updated the message to say "unexpected relocation type!" which is used elsewhere in this file. That should be visible in the latest diff.

Hahnfeld marked an inline comment as done.Mar 12 2019, 4:14 AM
MaskRay accepted this revision.Mar 12 2019, 4:16 AM
This revision is now accepted and ready to land.Mar 12 2019, 4:16 AM
This revision was automatically updated to reflect the committed changes.