This is an archive of the discontinued LLVM Phabricator instance.

[obj2yaml][XCOFF] Dump sections
ClosedPublic

Authored by Esme on Mar 4 2021, 8:01 PM.

Details

Summary

This patch implements parsing sections for obj2yaml on AIX.

Diff Detail

Event Timeline

Esme created this revision.Mar 4 2021, 8:01 PM
Esme requested review of this revision.Mar 4 2021, 8:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2021, 8:01 PM
Esme added a reviewer: Restricted Project.Mar 4 2021, 8:02 PM
Esme added a comment.Mar 18 2021, 12:04 AM

Gently ping.

qiucf added a subscriber: qiucf.Mar 22 2021, 1:43 AM
qiucf added inline comments.
llvm/include/llvm/ObjectYAML/XCOFFYAML.h
59 ↗(On Diff #328365)

Better to add brief comment like length or symbol table index, depending on symbol type.? Like D68650.

llvm/test/tools/obj2yaml/XCOFF/aix.yaml
6–7

As I see this test is not auto-generated? So can we reduce the indents to make the diff minimal?

llvm/tools/obj2yaml/xcoff2yaml.cpp
35

Why not change return type to Error?

150

Put break inside brace.

Esme updated this revision to Diff 332865.Mar 23 2021, 10:17 PM
Esme added a reviewer: qiucf.

You'll need someone with XCOFF experience to review this too. Generally looks fine from my brief look though.

llvm/test/tools/obj2yaml/XCOFF/aix.yaml
0–1

It would be nice if we could replace the canned binary input with a YAML input and then use yaml2obj to produce the YAML for consumption by obj2yaml at some point in the future. That'll allow us proper flexibility to test all code paths.

7

Nit: add extra spaces to make things line up nicely.

Should this be a CHECK-NEXT though? If so, delete the blank line above it.

llvm/tools/obj2yaml/xcoff2yaml.cpp
41–43
58

Perhaps report this as a regular error using createStringError()? No need for report_fatal_error when we have an easy way to report the Error after all.

59–60

No need for the else here.

79

This and the similar relocation check below - do you actually need it? If a user had an invalid object, where the section type was different to what it should be (e.g. a bug in an object producer), this check would prevent using obj2yaml, yet in my mind, the YAML could easily represent this state.

Esme updated this revision to Diff 348722.May 30 2021, 7:58 PM
  1. Address comment.
  2. Rebase on D85774 and D95505.
llvm/test/tools/obj2yaml/XCOFF/aix.yaml
0–1

Yes, I agree with that. However, the yaml2obj is not yet fully implemented and some fields this test need like the symbol auxiliary entries are not yet supported in yaml2obj. I will replace the canned binary input with a YAML input in the future.

jhenderson added inline comments.Jun 7 2021, 1:43 AM
llvm/test/tools/obj2yaml/XCOFF/aix.yaml
0–1

Is there a particular need for obj2yaml support ahead of yaml2obj support for these things? I'm just wondering whether it would be better to wait.

Esme added inline comments.Jun 8 2021, 8:27 PM
llvm/test/tools/obj2yaml/XCOFF/aix.yaml
0–1

There is no particular reason for obj2yaml support to be ahead of yaml2obj, except that if I can use obj2yaml to convert compiled object files to readable yaml files, it will help me to implement yaml2obj.

jhenderson added inline comments.Jun 9 2021, 12:25 AM
llvm/test/tools/obj2yaml/XCOFF/aix.yaml
0–1

The problem is that there's currently quite a lot of noise (e.g. the excessive section content) in this test that isn't all that useful. There are also a number of cases that aren't properly covered by this test input (e.g. sections with no relocations, empty sections etc), and you may find it difficult to cover all of them using a canned binary. Better to wait until you've got sufficient yaml2obj support for the basic structure, and then develop the two in tandem (i.e. add a feature to yaml2obj and at the same time, mirror it in obj2yaml).

There's of course nothing stopping you having this patch applied locally to help you in your yaml2obj development.

llvm/tools/obj2yaml/xcoff2yaml.cpp
83

Here and throughout, you need testing for your error cases, i.e. what obj2yaml does when this error is triggered.

139

Do you have testing for the case where this is false?

144–146

I'm not convinced this belongs at all. Why do you do this check only for debug builds?

158

Here and elsewhere - this is the more normal TODO syntax in LLVM.

Esme updated this revision to Diff 371247.Sep 7 2021, 8:29 PM
Esme retitled this revision from [obj2yaml] Implement parsing sections and auxiliary entries of XCOFF. to [obj2yaml][XCOFF] Dump sections.
Esme edited the summary of this revision. (Show Details)
  1. Only dump sections.
  2. Replace the binary input with the yaml input.

You still need testing for your error cases, i.e. showing that obj2yaml produces a suitable error (or possibly follows some fallback path) when it encounters invalid content.

llvm/test/tools/obj2yaml/XCOFF/aix.yaml
11–20

Here and below, we usually remove excessive spacing, so that the values neatly line up, as close as possible to the tags. See the suggested edit for an example of what I mean.

llvm/tools/obj2yaml/xcoff2yaml.cpp
58

Probably, this should just be errc::not_implemented (or something along those lines) - the file type is valid, we just haven't added support yet.

Is there much difference between 64 and 32-bit sections though, or could you just remove this error entirely and do the right thing?

Esme updated this revision to Diff 371779.Sep 9 2021, 9:52 PM

Address comment.

  1. Add 64-bit support and test.
  2. Test error paths.
jhenderson added inline comments.Sep 10 2021, 1:29 AM
llvm/test/tools/obj2yaml/XCOFF/aix.yaml
136–141

Strictly, this should be like the inline edit (and same immediately below), but I'm not too fussed by that.

llvm/test/tools/obj2yaml/XCOFF/invalid.yaml
1 ↗(On Diff #371779)

You should consider splitting this test into separate files, e.g. invalid-section and invalid-symbol, as I suspect it will grow as obj2yaml support for XCOFF improves.

13–20 ↗(On Diff #371779)
28 ↗(On Diff #371779)

Not for this patch, but it would be nice if we could get the actual useful error message, rather than the error code converted to an error message. That would ensure the message actually provides useful context (here the question could be raised "which section index? Where was it and what was its value?"

llvm/tools/obj2yaml/xcoff2yaml.cpp
93–94

This error path appears to be untested?

Esme updated this revision to Diff 372165.Sep 12 2021, 10:21 PM

Address comment

This revision is now accepted and ready to land.Sep 13 2021, 1:30 AM
This revision was landed with ongoing or failed builds.Sep 14 2021, 10:17 PM
This revision was automatically updated to reflect the committed changes.