This is an archive of the discontinued LLVM Phabricator instance.

Use DataExtractor to decode SLEB128 in android_relas.
ClosedPublic

Authored by rahmanl on Jan 21 2021, 11:34 AM.

Details

Summary

A simple refactoring patch which let us use DataExtractor::getSLEB128 rather than using a lambda function.

Diff Detail

Event Timeline

rahmanl created this revision.Jan 21 2021, 11:34 AM
rahmanl updated this revision to Diff 318271.Jan 21 2021, 11:43 AM

Remove some of the error handling code.

rahmanl updated this revision to Diff 318273.Jan 21 2021, 11:46 AM

Make the error handling code consistent with the old code.

rahmanl published this revision for review.Jan 21 2021, 11:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 21 2021, 11:47 AM
Harbormaster completed remote builds in B86137: Diff 318273.
probinson added inline comments.
llvm/lib/Object/ELF.cpp
11

Can you remove the LEB128.h include?

In principle, looks fine, but two pre-merge bots are complaining about an unhandled Error somewhere.

rahmanl updated this revision to Diff 318554.Jan 22 2021, 9:27 AM

Add an extra error check to solve the buildbot failure.

rahmanl marked an inline comment as done.Jan 22 2021, 9:29 AM

Thanks @jhenderson. I added one more check after uint64_t NumRelocsInGroup = Data.getSLEB128(Cur); to solve the issue.

So, if the previous build bot failure was due to an unhandled Error, that means that this error path doesn't have any testing. Basically, there needs to be a test for each individual getSLEB128 call, in case the section happens to be corrupted at that specific point (e.g. a truncated SLEB or one that goes outside the uint64_t range). Given that this is in the Object library, it would also probably make most sense for those tests to be gtest unit tests rather than lit stuff.

If I'm following things correctly, I don't think you've made the testing situation any worse, so if you'd prefer to defer that to a separate change, that's fine by me.

llvm/lib/Object/ELF.cpp
381

Add a comment saying what the 4 here represents, i.e. something like DataExtractor::Cursor Cur(/*Offset=*/4);

A minor nit from me, the rest looks fine.

llvm/lib/Object/ELF.cpp
429

Looks like you can remove these 2 lines and do the following?

for (uint64_t I = 0; Cur && I != NumRelocsInGroup; ++I) {

It is a bit shorter, anyways the Cur is checked right below.

rahmanl marked 2 inline comments as done.Jan 25 2021, 3:47 PM

So, if the previous build bot failure was due to an unhandled Error, that means that this error path doesn't have any testing. Basically, there needs to be a test for each individual getSLEB128 call, in case the section happens to be corrupted at that specific point (e.g. a truncated SLEB or one that goes outside the uint64_t range). Given that this is in the Object library, it would also probably make most sense for those tests to be gtest unit tests rather than lit stuff.

I agree that the testing is not extensive. However, I think as long as we make sure the Cursor error is eventually taken (by takeError), there won't be any unhandled error problem. The previous diff posed the problem that the following return from the function (at line 396) could potentially left the Cursor error unhandled.

if (NumRelocsInGroup > NumRelocs)
   return createError("relocation group unexpectedly large");

I am trying to say that we only need to guard the function returns (which is already done). So I don't have a strong opinion on making the tests any better.

If I'm following things correctly, I don't think you've made the testing situation any worse, so if you'd prefer to defer that to a separate change, that's fine by me.

llvm/lib/Object/ELF.cpp
429

Great suggestion. Thanks.

rahmanl updated this revision to Diff 319149.Jan 25 2021, 3:48 PM
rahmanl marked an inline comment as done.

Address two reviewer comments.

@jhenderson Is this ready to land?

jhenderson accepted this revision.Jan 27 2021, 2:24 AM

@jhenderson Is this ready to land?

Sorry, I got caught up with things yesterday and didn't get to all the review requests I had to field.

I guess the test case I'm thinking of is showing that the malformed group reloc count value means we don't get the "relocation group unexpectedly large" error. I don't feel strongly enough about this though to push for more testing if you don't want to add it.

This revision is now accepted and ready to land.Jan 27 2021, 2:24 AM

@jhenderson Is this ready to land?

Sorry, I got caught up with things yesterday and didn't get to all the review requests I had to field.

I guess the test case I'm thinking of is showing that the malformed group reloc count value means we don't get the "relocation group unexpectedly large" error. I don't feel strongly enough about this though to push for more testing if you don't want to add it.

Thanks for the response. I see your point now. But the "relocation group unexpectedly large" error has been tested by asm5.s in the same test file above. So I think we should be good to land.

I am surprised this patch hasn't been automatically updated to show the committed status after I pushed it (https://github.com/llvm/llvm-project/commit/3ca502a7d60787abe14db1fa541950ff79c7585b). Maybe I should've used arc land instead of git push?

I am surprised this patch hasn't been automatically updated to show the committed status after I pushed it (https://github.com/llvm/llvm-project/commit/3ca502a7d60787abe14db1fa541950ff79c7585b). Maybe I should've used arc land instead of git push?

Probably because you've used "Differential Revision". The latter word should be "revision"

I am surprised this patch hasn't been automatically updated to show the committed status after I pushed it (https://github.com/llvm/llvm-project/commit/3ca502a7d60787abe14db1fa541950ff79c7585b). Maybe I should've used arc land instead of git push?

Probably because you've used "Differential Revision". The latter word should be "revision"

No, it definitely should be Revision (upper-case). I always use git push, and my last commit worked fine - see rGb37a349ff2442e73ceafeee982afb430359e08b1. Your format looks the same as mine, so either Phabricator had a fit and just failed to link the two up this time, or something else is the matter. @mehdi_amini, any ideas?

Oh, don't forget to manually close and add the related commit yourself.

I am surprised this patch hasn't been automatically updated to show the committed status after I pushed it (https://github.com/llvm/llvm-project/commit/3ca502a7d60787abe14db1fa541950ff79c7585b). Maybe I should've used arc land instead of git push?

Probably because you've used "Differential Revision". The latter word should be "revision"

No, it definitely should be Revision (upper-case).

Seems there is no difference what to use then. I believe I always used lower-case. E.g rG029644ee510792120f1c0daf32989b401d4ce871.

I am surprised this patch hasn't been automatically updated to show the committed status after I pushed it (https://github.com/llvm/llvm-project/commit/3ca502a7d60787abe14db1fa541950ff79c7585b). Maybe I should've used arc land instead of git push?

Probably because you've used "Differential Revision". The latter word should be "revision"

No, it definitely should be Revision (upper-case).

Seems there is no difference what to use then. I believe I always used lower-case. E.g rG029644ee510792120f1c0daf32989b401d4ce871.

Thanks @grimar and @jhenderson.
I think the 'differential revision' line was added automatically when I pushed.