This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj] Add --memtag
ClosedPublic

Authored by hctim on Feb 9 2023, 5:14 PM.

Details

Summary

This adds functionality to readelf/readobj to specifically handle
MTE-related bits, like the AARCH64_MEMTAG_* dynamic entries, and a
decoder for the Android-specific ELF note.

Diff Detail

Event Timeline

hctim created this revision.Feb 9 2023, 5:14 PM
Herald added a project: Restricted Project. · View Herald Transcript
hctim requested review of this revision.Feb 9 2023, 5:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 9 2023, 5:14 PM
fmayer added inline comments.Feb 9 2023, 5:27 PM
llvm/tools/llvm-readobj/ELFDumper.cpp
5952

AFAICT this doesn't actually print anything, so this is a bit awkward. But maybe that's easier than manually iterating? At least worth a comment IMO.

hctim updated this revision to Diff 496298.Feb 9 2023, 5:41 PM

Add test that --memtag doesn't print non-MTE dynamic entries.

hctim updated this revision to Diff 496536.Feb 10 2023, 10:05 AM
hctim marked an inline comment as done.

Add a comment describing the use of printNotesHelper.

MaskRay added inline comments.Feb 10 2023, 5:39 PM
llvm/test/tools/llvm-readobj/ELF/AArch64/note-android-memtag.test
0

Add a test when no memtag tag is present in an object file.

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

If the user specifies --memtag, Memtag Dynamic Entries: should be unconditionally printed, even if empty.

5241
5930

delete this blank line

7308

unconditionally print "Memtag Dynamic Entries:"

7311

delete braces

llvm/tools/llvm-readobj/Opts.td
58

Does the help message include notes? I only see modes and global descriptors.

Add --memtag to llvm-readelf/llvm-readobj.

[llvm-readobj] Add --memtag

hctim retitled this revision from Add --memtag to llvm-readelf/llvm-readobj. to [llvm-readobj] Add --memtag.Feb 13 2023, 9:16 AM
hctim updated this revision to Diff 497018.Feb 13 2023, 9:17 AM
hctim marked 7 inline comments as done.

Address Ray's comments.

jhenderson added inline comments.Feb 15 2023, 2:22 AM
llvm/test/tools/llvm-readobj/ELF/AArch64/memtag-missing.test
5 ↗(On Diff #497018)
7 ↗(On Diff #497018)

Should this be a CHECK-NEXT?

13 ↗(On Diff #497018)

There's no point in the duplicate CHECK-NOT. What are you trying to test with these lines?

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

Any reason this can't be an ArrayRef<std::pair<std::string, std::string>> or similar?

It may also be more self-documenting to use a two-field class instead of std::pair<std::string, std::string>, as you can then give the fields specific names.

2274

This should be using Twine for the string concatenation.

2284

Ditto.

2287

Ditto. Also, the style for inline comments that are labelling a parameter is /*LowerCase=*/true. I believe the trailing = causes clang-format to format it like this.

5241

Especially if you adopt my suggestion about adding a struct/class for the fields, you shouldn't use auto here in the loop (see Coding Standards about use of auto - it's not clear what the type is from the context).

5930
  1. Do you need the this->?
  2. Don't use auto here - it's unclear what the type of Entry is.
5938–5939

As above, do you need to use this->?

5952

Seems to me like printNotesHelper might need renaming or restructuring.

7311

As above re. auto.

hctim updated this revision to Diff 497772.Feb 15 2023, 12:29 PM
hctim marked 12 inline comments as done.

Update with jhenderson@'s comments: used arrayref in place of vector, some minor reformatting and renaming.

hctim added inline comments.Feb 15 2023, 3:39 PM
llvm/test/tools/llvm-readobj/ELF/AArch64/memtag-missing.test
13 ↗(On Diff #497018)

Removed the duplicate. We're trying to assert (unlike in memtag.test) that readelf/readobj --memtag indiscriminately prints "Memtag Dynamic Entries", but doesn't print a missing Android ELF note.

llvm/test/tools/llvm-readobj/ELF/AArch64/note-android-memtag.test
0

done, in a separate file (memtag-missing.test)

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

I've changed it to ArrayRef in the callees, but I'm don't think adding a struct for a pair of strings would drastically improve readability here.

5241

I've updated all the range-based loops to use const auto& DynamicEntryKV (note the new KV suffix).

I agree with you (and the style guide) on "avoid auto for non-obvious type deductions", but IMHO using auto for a key-value iteration is idiomatic, as it's used for all std::map<string, string> iteration.

5952

renamed to processNotesHelper.

7311

(renamed to DynamicEntryKV, as elsewhere)

@fmayer / @jhenderson / @MaskRay , would you folks mind taking a second pass? thanks.

MaskRay added inline comments.Feb 17 2023, 2:05 PM
llvm/test/tools/llvm-readobj/ELF/AArch64/memtag-missing.test
1 ↗(On Diff #497772)

This file can be folded into memtag.test by using yaml2obj --docnum.

Being a separate test, CHECK-NOT: Memtag Android Note below can easily go stale without being noticed.

5 ↗(On Diff #497772)

I think you can just enumerate all lines since the output is very short.

Add CHECK-NOT: {{.}} in the end to assert that there is no additional output.

6 ↗(On Diff #497772)
llvm/tools/llvm-readobj/ELFDumper.cpp
301

ArrayRef is usually passed by value

586

ArrayRef is usually passed by value

693

ArrayRef is usually passed by value

5899

These need a e_machine == EM_AARCH64 check. These values are in the processor-specific dynamic tag range.

5904

Drop .c_str(). getDynamicTagAsString returns is a std::string.

MaskRay added inline comments.Feb 17 2023, 2:07 PM
llvm/docs/CommandGuide/llvm-readelf.rst
122

various dynamic entries => various memtag-specific dynamic entries ?

You need to update llvm-readobj.rst as well with the new option (we have separate documents for the two of them because there are several options that aren't shared).

llvm/test/tools/llvm-readobj/ELF/AArch64/memtag-missing.test
13 ↗(On Diff #497018)

Is ordering important here? CHECK-NOT will just show that this pattern won't appear since the last positive match, so if the unexpected output appears before the "Memtag Dynamic Entries" bit, it'll not catch it. If ordering isn't relevant here, you may wish to use FileCheck's "--implicit-check-not=Memtag Android Note".

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

If memory serves me correctly, Twine has a constructor that effectively can do the std::to_string, so you should use that. Same goes for below.

5241

I guess in my mind, it wasn't obvious that this was a key-value situation, but the renaming helps, thanks.

5891

Nit: has this been clang-formatted? If so, I'm marginally surprised that the format is []() {} not [](){}.

I noticed that there were a couple of llvm-readobj test failures in the pre-merge checks. Are either of them related to your change possibly?

hctim updated this revision to Diff 501328.Feb 28 2023, 4:07 PM
hctim marked 13 inline comments as done.

Address MaskRay and jhenderson's comments.

Let's see how the pre-merge bots go with this instance. Honestly, I've had so many times where the pre-merge bots show garbage results that I don't trust them any more :).

MaskRay accepted this revision.Feb 28 2023, 4:20 PM
This revision is now accepted and ready to land.Feb 28 2023, 4:20 PM
This revision was landed with ongoing or failed builds.Mar 1 2023, 11:00 AM
This revision was automatically updated to reflect the committed changes.