This is an archive of the discontinued LLVM Phabricator instance.

llvm-objcopy: Remove unused field. NFCI.
ClosedPublic

Authored by pcc on Mar 7 2019, 9:54 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc created this revision.Mar 7 2019, 9:54 PM
MaskRay accepted this revision.Mar 8 2019, 12:56 AM
This revision is now accepted and ready to land.Mar 8 2019, 12:56 AM

Could you hold off on doing this for a bit? As @jakehehrlich mentioned by email, this was being used to write segment data not owned by sections, I think, and I could do with that behaviour. I'm just investigating why it got removed at the moment, and may come forward with patch in the next few days to make use of it again. I may decide not to bother, in which case I'll give an LGTM.

jhenderson requested changes to this revision.Mar 8 2019, 3:20 AM

Right, I did lots of digging and discovered that this was added originally for binary output support, in rL310127. The usage was removed when binary output support was changed to be driven by segments in r318324. It was never used for regular ELF output, but I think it should be.

I've discussed with a colleague and we definitely need the behaviour of preserving unlabelled space within program headers. As such, we will need the data. I or one of my colleagues will be looking at implementing this in the next few days, so please don't commit this.

This revision now requires changes to proceed.Mar 8 2019, 3:20 AM
pcc added a comment.Mar 8 2019, 12:26 PM

An alternative to storing this field in Segment would be to store a reference to the file contents as a field in Object. That would allow you to access the segment contents using the OriginalOffset and Size fields, and also seems like it might allow you to remove the various Contents fields from the Section hierarchy. So maybe we should remove this field in case that approach turns out to work out better?

jhenderson accepted this revision.Mar 11 2019, 2:07 AM

Yes, you're probably right. I've been thinking about this a bit since making my last comment, and just having the segment data doesn't necessarily seem all that useful, because we're actually only interested in the data not covered by sections. Go ahead and land this. I can always revert bits of it if the new implementation needs it.

This revision is now accepted and ready to land.Mar 11 2019, 2:07 AM

So this change and the issue that James hit made me think about a few short comings in llvm-objcopy that I think should be addressed.

  1. Consider the issue of data in a PT_LOAD that isn't covered by a section. We should maintain that IMO.
  2. Consider the issue of added trap instructions that LLD adds. Right now we're not preserving that and thus stripping decreases the security of binaries produced by LLD
  3. --strip-sections really should strip all sections, not just the allocated ones

I think soon we'll have to start copying from segments, when a section doesn't cover the region.

This revision was automatically updated to reflect the committed changes.