This is an archive of the discontinued LLVM Phabricator instance.

[AIX] support read global symbol of big archive
ClosedPublic

Authored by DiggerLin on May 3 2022, 10:33 AM.

Diff Detail

Event Timeline

DiggerLin created this revision.May 3 2022, 10:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 3 2022, 10:33 AM
DiggerLin requested review of this revision.May 3 2022, 10:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 3 2022, 10:33 AM
jhenderson added inline comments.May 5 2022, 5:00 AM
llvm/lib/Object/Archive.cpp
1111–1112

Once you start using braces for an if/else sequence, use them consistently throughout that sequence.

1191
1194–1196

You need to check that the offset falls within the file, and that the file is big enough to hold the header and table or you risk reading invalid memory.

1201
1205

Could you factor out 8 * (SymNum + 1) into a separate variable, please, rather than repeat it?

DiggerLin marked 4 inline comments as done.May 5 2022, 1:40 PM
DiggerLin updated this revision to Diff 427431.EditedMay 5 2022, 1:43 PM

address James's comment and a new global symbol table malformed test case , thanks

jhenderson added inline comments.May 5 2022, 11:00 PM
llvm/lib/Object/Archive.cpp
1191

Not addressed?

1200

I would probably include the offset value in this message, along with a couple of grammar tweaks: "global symbol table with offset 0x1234 is past the end of the file"

1216

I'd do "out of file" -> "goes past the end of the file". It might be useful to have the offset and size in this error (e.g. "global symbol table at offset 0x1234 and size 0x4321 goes past the end of the file"). This will help developers spot clues as to why they're getting the error (e.g. the Size field is bad).

1221

This is a shorter name (plus the "S" in "Offsets" shouldn't be capitalized).

llvm/test/tools/llvm-ar/malform-global-symbol-table-bigarchive.test
1 ↗(On Diff #427431)

You can do this test without needing additional big archive binaries. Instead, use python to truncate an existing big archive by an appropriate number of bytes.

3 ↗(On Diff #427431)

Nit: too many blank lines.

4–5 ↗(On Diff #427431)
DiggerLin marked 4 inline comments as done.May 10 2022, 10:28 AM
DiggerLin added inline comments.
llvm/lib/Object/Archive.cpp
1221

thanks

DiggerLin marked an inline comment as done.

address Jame's comment. thanks for the comments

jhenderson added inline comments.May 12 2022, 12:52 AM
llvm/lib/Object/Archive.cpp
1191

STILL not addressed...

1203–1204

These will print in decimal, but offsets are usually printed in hex. Use utohexstr instead (you may need to explicitly add a 0x prefix too, but I don't know). Also "is" -> "goes" in the message, because the thing in question may start within range, but not finish. "is" implies that ot starts past the end of the file.

1220–1223

Same comments as above.

1221

Not addressed?

MaskRay added inline comments.May 12 2022, 12:58 AM
llvm/test/tools/llvm-ar/malform-global-symbol-table-bigarchive.test
9 ↗(On Diff #428429)

It may be useful to do rm -rf %t && cd %t at the top once you are using tricky lit feature like %/t.a... Then you can use regular filenames without the %t prefix.

DiggerLin updated this revision to Diff 428967.May 12 2022, 9:35 AM
DiggerLin marked 6 inline comments as done.

address comment

jhenderson added inline comments.May 13 2022, 1:09 AM
llvm/test/tools/llvm-ar/malform-global-symbol-table-bigarchive.test
16 ↗(On Diff #428967)

@MaskRay, I'm in two minds about this, so would like another opinion: would you prefer to have sizes in hex or decimal? On the one hand, decimal is more "natural" when speaking of sizes typically. On the other hand, it's much easier to do maths if the two things are in the same base, so my instinct would be to say that the sizes need to be hex too.

DiggerLin updated this revision to Diff 437526.Jun 16 2022, 6:47 AM
DiggerLin marked 2 inline comments as done.
DiggerLin added inline comments.Jun 16 2022, 6:55 AM
llvm/lib/Object/Archive.cpp
1191

thanks.

1203–1204

thanks

1221

thanks

llvm/test/tools/llvm-ar/malform-global-symbol-table-bigarchive.test
16 ↗(On Diff #428967)

I can change to using both hex and decimal.
truncated or malformed archive (global symbol table header at offset 0x20e and size 114(0x72) goes past the end of file)
@jhenderson

9 ↗(On Diff #428429)

thanks

jhenderson added inline comments.Jun 21 2022, 12:23 AM
llvm/lib/Object/Archive.cpp
1204–1205

I don't think we need the size to be printed in both hex and decimal. I think just hex is sufficient, having thought about it.

1224–1225

I don't think we need the size to be printed in both hex and decimal. I think just hex is sufficient, having thought about it.

llvm/test/tools/llvm-ar/malform-global-symbol-table-bigarchive.test
16 ↗(On Diff #428967)

As noted above, I think we should just have the size in one or other format, and I think I'd pick hex.

DiggerLin updated this revision to Diff 438708.Jun 21 2022, 8:07 AM
DiggerLin marked 3 inline comments as done.

I feel like this code is missing testing for the non-error cases. In particular, I'd expect to see some sort of test that shows that the archive symbol table can be read successfully. I think you can do that using llvm-nm --print-armap. I'd be surprised if there aren't already equivalent test cases for other formats that do this, so you may be able to copy/modify those to cover big archives too.

llvm/lib/Object/Archive.cpp
1189–1192

Test case?

1214–1217

Test case?

I feel like this code is missing testing for the non-error cases. In particular, I'd expect to see some sort of test that shows that the archive symbol table can be read successfully. I think you can do that using llvm-nm --print-armap. I'd be surprised if there aren't already equivalent test cases for other formats that do this, so you may be able to copy/modify those to cover big archives too.

There is already has "llvm-nm --print-armap" in the llvm/test/tools/llvm-ar/delete.test , the test case is disable in AIX OS, it enable in AIX in the patch by deleting the "# XFAIL: system-aix"

I feel like this code is missing testing for the non-error cases. In particular, I'd expect to see some sort of test that shows that the archive symbol table can be read successfully. I think you can do that using llvm-nm --print-armap. I'd be surprised if there aren't already equivalent test cases for other formats that do this, so you may be able to copy/modify those to cover big archives too.

There is already has "llvm-nm --print-armap" in the llvm/test/tools/llvm-ar/delete.test , the test case is disable in AIX OS, it enable in AIX in the patch by deleting the "# XFAIL: system-aix"

delete.test is a test that shows that llvm-ar can delete symbols when its members are deleted. It's hardly comprehensive coverage of the archive symbol table code. However, there are many other symbol table tests both in the Object and tools/llvm-ar test directories. It's not clear to me why the changes you've made didn't cause a test to start passing/failing when it wasn't before, at least on AIX OS. You need to investigate, and ensure there is coverage of the new code you've added in a test dedicated to symbol table reading etc.

llvm/test/tools/llvm-ar/malform-global-symbol-table-bigarchive.test
1 ↗(On Diff #438708)

Test-case name should be "malformed-..." (not "malform-...")

DiggerLin added a comment.EditedJun 28 2022, 8:56 AM

delete.test is a test that shows that llvm-ar can delete symbols when its members are deleted. It's hardly comprehensive coverage of the archive symbol table code. However, there are many other symbol table tests both in the Object and tools/llvm-ar test directories. It's not clear to me why the changes you've made didn't cause a test to start passing/failing when it wasn't before, at least on AIX OS. You need to investigate, and ensure there is coverage of the new code you've added in a test dedicated to symbol table reading etc.

   
When we added "XFAIL" into a lot test cases in the patch https://reviews.llvm.org/D122746 "[AIX][XCOFF] print unsupported message for llvm-ar big archive write operation" , after implement the https://reviews.llvm.org/D123949 [AIX] "support write operation of big archive",  The "XFAIL" of some of the XFAIL test cases in https://reviews.llvm.org/D122746 are removed in patch D123949.  but there are still has some test cases still has "XFAIL" , after  investigated those test cases, I created several patches for the XFAIL test cases to remove remaining the "XFAIL" from test cases.

including:

D124017 [AIX] fixed llvm-ar can not read empty big archive correctly.
D124940 [AIX] llvm-link support big archive.
D124865.  [AIX] support read global symbol of big archive

There is source code as https://github.com/llvm/llvm-project/blob/main/llvm/tools/llvm-ar/llvm-ar.cpp#L916

Kind = !NewMembersP->empty() ? NewMembersP->front().detectKindFromObject()
                                   : object::Archive::getDefaultKindForHost();

in most of the test cases which has "llvm-nm --print-armap" , when create archive with new object file, the first file is no XCOFF object file. So they do not generate big archive in AIX OS. Only the llvm/test/tools/llvm-ar/delete.test , it has (first new member is not object file, the archive format will be decided by host OS)

/# RUN: llvm-ar rc %t.a %t1.txt %t-delete.o %t-keep.o %t2.txt

so it will generate the big archive based on the host. it effected by the patch.

DiggerLin marked 3 inline comments as done.Jun 28 2022, 1:32 PM
DiggerLin added inline comments.
llvm/lib/Object/Archive.cpp
1189–1192

I do not think we can add a test case for the malformed in the test case.
since we do not support yaml2obj for big archive, we can not generate malformed big archive. there is https://github.com/llvm/llvm-project/blob/main/llvm/test/tools/llvm-objdump/malformed-archives.test#L182
as in patch https://reviews.llvm.org/D111889#change-i2aT5QfHJFnJ

1214–1217

as above

DiggerLin updated this revision to Diff 440749.Jun 28 2022, 1:34 PM
DiggerLin marked 2 inline comments as done.

address James' comment

Thanks for the explanation on the topic of symbol table testing. It makes sense to me. I've added one inline suggestion for how to test the malformed inputs cases. I think it should be fairly straightforward, but let me know if it doesn't work - it's not the end of the world if we can't test it, but I think we should be able to. As a related aside, I think there is some support for an archive file format in yaml2obj, but I don't know how comprehensive it is. It might be worth investigating to see how simple it would be to extend it for big archives.

llvm/lib/Object/Archive.cpp
1189–1192

One option might be to use python to binary edit an archive created by llvm-ar. You could probably assume that the offset of the field is stable, so can just do something like:

  1. use llvm-ar to create archive.a
  2. read archive.a into byte array
  3. modify byte at offset x
  4. write byte array to disk as new file (bad.a)
  5. run llvm-ar on bad.a
1214–1217

Same response.

DiggerLin marked 2 inline comments as done.Jul 7 2022, 9:13 AM
DiggerLin added inline comments.
llvm/lib/Object/Archive.cpp
1189–1192

My suggestion is that we do not have a test case for the these code in the patch. @jhenderson

I will create a new patch to add test case for all malformedError test including the test case in https://reviews.llvm.org/D111889. the [AIX] Support of Big archive (read) ,if you suggestion work. and I think I need to write a python script and run the script.

1214–1217

as above

DiggerLin marked 2 inline comments as done.Jul 7 2022, 10:15 AM
jhenderson accepted this revision.Jul 11 2022, 1:16 AM

LGTM, with one request.

llvm/lib/Object/Archive.cpp
1189–1192

Thanks. That sounds reasonable. Please add a "TODO: add test case." comment to the bits of code that are missing test cases before landing this patch.

This revision is now accepted and ready to land.Jul 11 2022, 1:16 AM
MaskRay accepted this revision.Jul 11 2022, 10:37 PM

[AIX] support read global symbol of big archive

"Support reading global symbols in a big archive"

llvm/lib/Object/Archive.cpp
1220–1223

Hex offsets are common. If you choose hex for size, that seems fine (I'd do it, too).

llvm/test/tools/llvm-ar/malformed-global-symbol-table-bigarchive.test
13

Delete the otherwise empty #

This revision was landed with ongoing or failed builds.Jul 18 2022, 7:44 AM
This revision was automatically updated to reflect the committed changes.