strip --strip-unneeded?

H . J . Lu hjl@lucon.org
Fri May 12 15:39:00 GMT 2000


On Fri, May 12, 2000 at 04:00:09PM -0600, llewelly@dbritsch.dsl.xmission.com wrote:
> 
> Actually, it appears that I misunderstood what was going on.
>   I had had some problems with stripped executables that contained
>   exception throwing code. I had noticed that strip removed the
>   '__EXCEPTION_TABLE__' and '__FRAME_BEGIN__' symbols, so I
>   (incorrectly) assumed that was the cause of the problems.
> 
> It seems that the function containing the 'throw' is
>   disappearing. 
> 
> I have a test case that (I think) shows a bug in strip, but it is not
>   the bug I thought it was.
> 
> Here it is:  
>         
> {~/cc_exer}cat foo_vanish.h
> void foo(int j);
> 
> extern int l;
> {~/cc_exer}cat foo_vanish.cc
> 
> #include"foo_vanish.h"
> 
> int l=1;
> 
> void bar(int j)
>   {
>     throw j;
>   }
> 
> void foo(int j)
>   {
>     bar(j);
>   }
> 
> {~/cc_exer}cat foo_vanish_main.cc 
> 
> #include"foo_vanish.h"
> 
> int main()
>   {
>     int k=1;
>     try
>     {
>       foo(k);
>     }
>     catch(int i)
>     {
>       return l;
>     }
>     return l;
>   }
> {~/cc_exer}g++ -g -Wall -c foo_vanish.cc 
> {~/cc_exer}nm --demangle foo_vanish.o 
> 00000089 t Letext
> 00000000 ? __EXCEPTION_TABLE__
> 00000000 ? __FRAME_BEGIN__
>          U __cp_push_exception
>          U __eh_alloc
>          U int type_info function
>          U __throw
> 00000000 T bar(int)
> 0000006c T foo(int)
> 00000000 D l
>          U terminate(void)
> {~/cc_exer}strip --strip-unneeded foo_vanish.o
> {~/cc_exer}nm --demangle foo_vanish.o 
>          U __cp_push_exception
>          U __eh_alloc
>          U int type_info function
>          U __throw
> 00000000 T bar(int)
>          U terminate(void)
> {~/cc_exer}g++ -g -Wall foo_vanish_main.cc foo_vanish.o
> /tmp/cciCkDOS.o: In function `main':
> /home/llewelly/cc_exer/foo_vanish_main.cc:9: undefined reference to `foo(int)'
> /home/llewelly/cc_exer/foo_vanish_main.cc:15: undefined reference to `l'
> /home/llewelly/cc_exer/foo_vanish_main.cc:13: undefined reference to `l'
> collect2: ld returned 1 exit status

It is unclear to me what "strip --strip-unneeded" should do on .o
files. To me, it should keep global symbols as well as symbols which
need relocation processing. Global symbols defined in the .o file may
be needed for relocation processing for other files. Currently
"strip --strip-unneeded" will remove global symbols which aren't
involved in relocation.

Ian, any ideas?

Thanks.

H.J.


More information about the Binutils mailing list