[PATCH] D46819: [llvm-objcopy] Add --keep-symbol (-K) option

Jake Ehrlich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 15 17:29:38 PDT 2018


jakehehrlich added a comment.

In https://reviews.llvm.org/D46819#1100415, @alexshap wrote:

> yeah, the behavior of --keep-symbol is more complicated than what's going on here.
>  In particular,
>
>   main.c
>   
>   __attribute__((section(".data.foo"))) int xx= 1;
>   int yy() { return 239; }
>   
>
> objcopy --keep-symbol xx --remove-section .data.foo main.o main2.o
>
> objcopy: main1.o: symbol `xx' required but not present
>  objcopy:main1.o: No symbols
>  [alexshap at devvm ~/local] echo $?
> 1
>
> so probably the exit code should not be 0, error reporting can be better, though, than what binutils objcopy has to offer.
>
> @paulsemel , can you send fix (looks like it's not that involved to fix it) ? otherwise i can send a patch for review myself . cc: @jakehehrlich


I'm not sure how concerned I am about this but I've got some thoughts I suppose. The issue here is that GNU objcopy implicitly keeps a section if a symbol is explicitly kept that is defined in that section. Right now we don't keep such sections. I'm fine with the added error for --remove-section and --keep-symbol conflicts because those are explicit but I don't think we should error out for all such cases and I don't want to put any extra effort into erroring out in that case. In more complicated mixtures of symbol keeping and section removals we should probably err on the side of caution by not removing sections (which appears to be what GNU objcopy does as well). This is probably a slightly non-trivial feature to implement. The reasoning is that in some big build success is more important than reducing size. A warning should be issued at best in that case and I'd only consider an error valid in the case of an explicit-keep explicit-remove conflict. In past discussions of this form it was decided that we shouldn't worry about that sort of error. In general an explict-keep should override *everything*.

So my recommendation would be to implement keeping of sections for kept symbols defined in those sections but not to worry about the error case. In fact I'm not even sure I'd be ok with an error in that case.


Repository:
  rL LLVM

https://reviews.llvm.org/D46819





More information about the llvm-commits mailing list