This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] Refactor code to include initialize method
ClosedPublic

Authored by jakehehrlich on Sep 18 2017, 4:38 PM.

Details

Summary

This change refactors some of the code to allow for some code deduplication in later diffs as well as just to make adding a new section type more self contained to the class itself. The idea for this was first mentioned by James in D 37915 and will be used in that change as recommended.

This change follows changes for dynamic sections but precedes support for dynamic relocations.

Diff Detail

Repository
rL LLVM

Event Timeline

jakehehrlich created this revision.Sep 18 2017, 4:38 PM
jhenderson edited edge metadata.Sep 19 2017, 1:44 AM

Just to point out, there's no diff context here! Aside from that, the overall change here looks good. I'm slightly surprised to see the SectionTable being copied everywhere, as I'd expect there to only be one, but I guess it doesn't matter since it's just a wrapper around a reference to an array of pointers.

tools/llvm-objcopy/Object.h
36

See my comment in D36560 regarding the argument names here.

Just to point out, there's no diff context here! Aside from that, the overall change here looks good. I'm slightly surprised to see the SectionTable being copied everywhere, as I'd expect there to only be one, but I guess it doesn't matter since it's just a wrapper around a reference to an array of pointers.

My intent was for it to be a lightly copyable type like ArrayRef is. Maybe I could call it "SectionTableRef" to clarify this? That way it follows the way StringRef and ArrayRef are used.

Just to point out, there's no diff context here! Aside from that, the overall change here looks good. I'm slightly surprised to see the SectionTable being copied everywhere, as I'd expect there to only be one, but I guess it doesn't matter since it's just a wrapper around a reference to an array of pointers.

My intent was for it to be a lightly copyable type like ArrayRef is. Maybe I could call it "SectionTableRef" to clarify this? That way it follows the way StringRef and ArrayRef are used.

I think this might be wise. It will ensure that people realise that it doesn't own the underlying sections, and that copying it is safe.

Changed SectionTable to SectionTableRef to clarify intended usage.

Looks fine to me. Just a couple of variable names that need dealing with and then I think this can go in.

tools/llvm-objcopy/Object.cpp
405–406

I think you can probably just call "TSec", "Sec".

tools/llvm-objcopy/Object.h
60

Not sure "Obj" is the right argument name here! See also all the overrides.

jakehehrlich added inline comments.Sep 22 2017, 1:04 PM
tools/llvm-objcopy/Object.h
60

Yep. That was leftover with my playing around with how this should work. I believe I originally tried passing the whole object

Changed a few things as requested by James

This revision is now accepted and ready to land.Sep 25 2017, 5:37 AM
This revision was automatically updated to reflect the committed changes.