This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readelf] Allow single-letter flags to be merged.
ClosedPublic

Authored by rupprecht on Jan 11 2019, 6:22 PM.

Details

Summary

This patch adds support for merged arguments (e.g. -SW == -S -W) for llvm-readelf.

No changes are intended for llvm-readobj. There are a few short flags (-sd, -sr, -st, -dt) that would conflict with grouped single letter flags, and having only some grouped flags might be confusing. So, allow merged flags for readelf compatibility, but force separate args for llvm-readobj. From what I can tell, these two-letter flags are only used with llvm-readobj, not llvm-readelf.

This fixes PR40064.

Diff Detail

Repository
rL LLVM

Event Timeline

rupprecht created this revision.Jan 11 2019, 6:22 PM

One question: what happens if you do enable grouping, and there's an ambiguous alias?

test/tools/llvm-readobj/merged.test
5 ↗(On Diff #181410)

Use FileCheck --input-file instead of cat.

10 ↗(On Diff #181410)

What's with the |& ?

13–16 ↗(On Diff #181410)

These should probably be in the corresponding tests for the appropriate dumps. I don't think we need them here.

tools/llvm-readobj/llvm-readobj.cpp
633 ↗(On Diff #181410)

I think this comment needs tweaking. As things stand, the args is ambiguous (i.e. is it referring to "-sd" or "-s" and "-d". I think you can replace "these args" with "single-letter args".

654 ↗(On Diff #181410)

Could we come up with some way of enforcing this list to be extended by any new single letter aliases that are added? I don't know if it's possible, but one option might be to set grouping on by default, and disable it for llvm-readobj.

rupprecht marked 7 inline comments as done.
  • Move two-letter aliases tests to separate tests
  • Automatically merge any single-letter args

One question: what happens if you do enable grouping, and there's an ambiguous alias?

I believe there's a silent failure... I think it prefers the longer alias (i.e. registering s, r, and sr, will cause "-sr" to be interpreted as sr, not s and r).

test/tools/llvm-readobj/merged.test
10 ↗(On Diff #181410)

It redirects stderr (i.e. the "unknown command line arg" we're checking) in a pipeline: https://www.gnu.org/software/bash/manual/bash.html#Pipelines

But 2>&1 works just as well and is more widely used (I can't find |& in any llvm tests, so lit probably doesn't support it), so I'll just use that.

tools/llvm-readobj/llvm-readobj.cpp
654 ↗(On Diff #181410)

Yes, there is an API for that! Updated.

jhenderson added inline comments.Jan 15 2019, 2:22 AM
test/tools/llvm-readobj/dyn-symbols.test
3–4 ↗(On Diff #181617)

aliases -> alias, names -> name

7 ↗(On Diff #181617)

Would diff make more sense here, since these are text files?

38 ↗(On Diff #181617)

Here and below, could you check that there are no extraneous characters at the end of the name, by putting a {{$}} at the end, please? This would match other names for which this is a prefix. You might need to capture the string offset as a result.

test/tools/llvm-readobj/merged.test
10 ↗(On Diff #181410)

Ah, I didn't know about that. Cool, but yes, use 2>&1 instead!

tools/llvm-readobj/llvm-readobj.cpp
633 ↗(On Diff #181617)

missing "args" after the latest change, i.e. "single-letter" to "single-letter args"

rupprecht updated this revision to Diff 181779.Jan 15 2019, 7:22 AM
rupprecht marked 4 inline comments as done.
  • Use diff instead of cmp
  • Check for full symbol names
  • Fix typos
rupprecht marked an inline comment as done.Jan 15 2019, 7:23 AM
rupprecht added inline comments.
test/tools/llvm-readobj/dyn-symbols.test
38 ↗(On Diff #181617)

The actual output here is _ITM_deregisterTMCloneTable (28), so I used {{ }} instead, as {{$}} fails due to the trailing (28). I verified that truncating the name (e.g. _ITM_deregisterTMCloneTabl{{ }}) causes the test to fail.

This revision is now accepted and ready to land.Jan 15 2019, 7:44 AM
This revision was automatically updated to reflect the committed changes.