[PATCH] D46896: [llvm-objcopy] Add --strip-unneeded option

Jake Ehrlich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 17 11:48:01 PDT 2018


jakehehrlich added a comment.

I'll be back to respond further. I'm pressed for time today.b



================
Comment at: tools/llvm-objcopy/Object.h:347
   uint8_t Visibility;
+  bool InReloc;
 
----------------
paulsemel wrote:
> jakehehrlich wrote:
> > paulsemel wrote:
> > > jakehehrlich wrote:
> > > > I'm not sure this is sufficient, or if it is it has to be set at the right time. For example say a symbol is referenced by a relocation in .rel.data and then .rel.data is removed. It could be that that symbol is either still referenced by another relocation in another section or it could not be. No local operation would tell you the answer either.
> > > > 
> > > > I think there are two possibilities.
> > > > 1) Maintain a count that can be incremented/decremented as relocations are added/removed
> > > > 2) Do a pass at the end to determine which symbols should be kept/not kept. You can either set this bool in that pass or add symbols to a set like container. see: http://llvm.org/docs/ProgrammersManual.html#set-like-containers-std-set-smallset-setvector-etc
> > > Arf.. I totally forgot the "what if the reloc section is removed" part Thanks about it !
> > > I think I will go for the counter, as I first wanted to be as light as possible for this option (and I don't see anything that might cause problems with the counter).
> > I was thinking about this and I was wondering if this isn't something that should be more general. Like it there are other ways symbols might be needed other than relocations. This should be a generic reference count. But we already have shared_ptr and weak_ptr to tell us how this should work! 
> > 
> > Can we think of a way to reuse that infrastructure? For instance those types already have use_count methods so that can be used to determine weather a symbol is needed or not. Alternatively it would make sense to create a similar sort of abstraction that managed the reference counting for us.
> Hm.. ok do you already have something in mind ?
> The fact is that not only relocation can reference symbols, so we need to be able to distinguish between blocking references and normal references if you know what I mean. 
Right which seems to be like a shared_ptr vs weak_ptr difference. I thought a tiny bit more about it and we don't want to connect collection to this. So I think I'd actually prefer an abstraction that has an explicit "clone" method that wraps pointers without calling delete on them. It seems like most ways of doing this I can think of require an extra layer of indirection. If you want we do explicit reference counting and I'll try and come up with something better later. Basically I think manual reference counting is error prone and I'd like to avoid it.


Repository:
  rL LLVM

https://reviews.llvm.org/D46896





More information about the llvm-commits mailing list