Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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? |
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) |
llvm/lib/Object/Archive.cpp | ||
---|---|---|
1221 | thanks |
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? |
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. |
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. |
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. |
9 ↗ | (On Diff #428429) | thanks |
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. |
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? |
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-...") |
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.
llvm/lib/Object/Archive.cpp | ||
---|---|---|
1189–1192 | I do not think we can add a test case for the malformed in the test case. | |
1214–1217 | as above |
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:
| |
1214–1217 | Same response. |
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 |
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. |
[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 # |
Once you start using braces for an if/else sequence, use them consistently throughout that sequence.