This is an archive of the discontinued LLVM Phabricator instance.

[MC][ELF] Add section flags to diagnostic
Needs ReviewPublic

Authored by bcain on Apr 10 2020, 4:04 PM.

Details

Summary

Make the assembler diagnostic emit quoted section names and refer to
the expected flag bits by input character flag.

Diff Detail

Event Timeline

bcain created this revision.Apr 10 2020, 4:04 PM
Herald added a project: Restricted Project. · View Herald Transcript
MaskRay added inline comments.Apr 10 2020, 5:09 PM
llvm/lib/MC/MCParser/ELFAsmParser.cpp
663

There are actually a lot more section flags, e.g. SHF_MERGE ('M') SHF_LINK_ORDER ('o') SHF_EXCLUDE ('e'). This patch will leave an empty string for an unknown flag.

667

A backquote (binutils uses it sometimes) is actually uncommon in LLVM diagnostics. Both unquoted and '-quoted section names are common.

bcain marked 2 inline comments as done.Apr 10 2020, 5:32 PM
bcain added inline comments.
llvm/lib/MC/MCParser/ELFAsmParser.cpp
663

Ok, I'll fix it by making it exhaustive.

667

IMO quoting it one way or another makes more sense than not. I can use single-quotes if that's more conventional.

bcain updated this revision to Diff 257192.Apr 13 2020, 9:58 PM

Added a getSectionFlagString() function.
Changed section name delimiters in diagnostic to single-quotes

bcain updated this revision to Diff 257196.Apr 13 2020, 10:01 PM
bcain marked an inline comment as done.

fix indentation in getSectionFlagString per git-clang-format

bcain marked an inline comment as done.Apr 13 2020, 10:02 PM
bcain added inline comments.
llvm/test/MC/ELF/section-flags-changed.s
6

When I ran this test, it failed. I'm not quite clear on why FileCheck doesn't match here, I'm sure I'm missing something simple.

I'll continue to investigate why this test fails.

bcain updated this revision to Diff 258222.Apr 16 2020, 7:16 PM

Fixed the expressions in getSectionFlagString() - strings instead of chars, the nulls were the wrong choice.

Test passes now.

MaskRay added inline comments.Apr 20 2020, 9:09 PM
llvm/lib/MC/MCParser/ELFAsmParser.cpp
290

It is incorrect to mix OS/processor specific flags here. Hard coding generic flags and their strings are also error-prone. I left this as a TODO because it is not very easy to reuse lib/MC/MCSectionELF.cpp#L53 code. I'll check more carefully how to reuse.

bcain marked an inline comment as done.Apr 21 2020, 7:46 AM
bcain added inline comments.
llvm/lib/MC/MCParser/ELFAsmParser.cpp
290

it is not very easy to reuse lib/MC/MCSectionELF.cpp#L53 code. I'll check more carefully how to reuse.

What If I just abstracted the portion of code in PrintSwitchToSection() relating to the flags to a method that takes unsigned Flags and returns the text as a string? That could be used here in ELFAsmParser but also in PrintSwitchToSection()?