This is an archive of the discontinued LLVM Phabricator instance.

[Object] Create MutableELFObject Class for Doing Mutations on ELFObjectFiles [Part 4]
AcceptedPublic

Authored by abrachet on Aug 10 2019, 11:09 PM.

Details

Summary

Added addSection and addSymbol methods

Diff Detail

Event Timeline

abrachet created this revision.Aug 10 2019, 11:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2019, 11:09 PM

I think some other interesting test cases are a) adding more than one symbol/section, b) adding and then removing a symbol/section, c) removing stuff and then adding stuff, showing that the iteration still works correctly.

llvm/include/llvm/Object/MutableELFObject.h
171

My instinct is that this should be a void return type.

346

I think this should just be a void return type.

351

I think this should just be a void return type.

403–408

This seems like an unrelated change?

llvm/unittests/Object/MutableELFObjectTest.cpp
545–547

Comment why there's 4 sections already.

566–568

Comment why there's already a symbol here.

570

It's not a header. Symbols are just that - symbols (unlike sections which have a header and actual contents). So this should just be called "Sym" or something like that.

abrachet updated this revision to Diff 215331.Aug 14 2019, 11:44 PM

Addressed review comments

abrachet marked 5 inline comments as done.Aug 14 2019, 11:49 PM
abrachet added inline comments.
llvm/include/llvm/Object/MutableELFObject.h
171

Hmm, I'm not sure about this and the other comments. I think it is more convenient this way, but also I wonder when you would add something and then immediately change something. The cost of this return is very small though I would say.

I don't have a strong opinion either way.

jhenderson added inline comments.Aug 15 2019, 8:23 AM
llvm/include/llvm/Object/MutableELFObject.h
171

My thinking is that add is akin to vector's push_back method, which doesn't return anything.

llvm/unittests/Object/MutableELFObjectTest.cpp
545

"yaml2obj creates the .symtab ..."

567

"... creates the index 0 symbol even when ..."

613

for (size_t I = 0; I < 10000; ++I) would seem more natural.

I'd also reduce it to 1000 or 100 for speed.

624

AddRemoveSymbol

659

AddRemoveSection

688–705

Could you add some new lines in this block between the groups of setup followed by checks, to make it easier to see where the interesting tests actually are, please.

abrachet updated this revision to Diff 215521.Aug 15 2019, 6:54 PM

Addressed review comments

abrachet marked 10 inline comments as done.Aug 15 2019, 6:54 PM
abrachet updated this revision to Diff 215536.Aug 15 2019, 8:26 PM

Fixed failing test for std::distance call.

jhenderson accepted this revision.Aug 19 2019, 1:53 AM

LGTM, though @rupprecht should confirm too.

This revision is now accepted and ready to land.Aug 19 2019, 1:53 AM
MaskRay added inline comments.
llvm/include/llvm/Object/MutableELFObject.h
346

void addSymbol(MutableELFSymbol<ELFT> Sym)

If you don't have a lvalue overload, taking an rvalue is usually inferior to pass-by-value because you'll not able to call addSymbol with a lvalue.

349

void addSection(MutableELFSection<ELFT> Sym)

I think the method is self-explanatory. No need for a comment.

MaskRay added inline comments.Aug 19 2019, 10:54 PM
llvm/include/llvm/Object/MutableELFObject.h
42

Omit Other, but why do you need the defaulted move ctor?

173

Swap the two statements to omit - 1.

abrachet updated this revision to Diff 216324.Aug 20 2019, 8:24 PM

Addressed comments. Made unit tests better.

abrachet marked 4 inline comments as done.Aug 20 2019, 8:25 PM
jhenderson accepted this revision.Aug 21 2019, 2:00 AM

Latest changes LGTM.

rupprecht accepted this revision.Aug 21 2019, 11:32 AM