public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [objcopy] relocation sections
@ 2007-12-07 16:05 robertsong
  2007-12-21 16:31 ` Nick Clifton
  0 siblings, 1 reply; 3+ messages in thread
From: robertsong @ 2007-12-07 16:05 UTC (permalink / raw)
  To: binutils

Hello, everyone.
I want to use objcopy to remove the useless sections from the object
file in order the shrink the library. But I can not realize it.
Now I am using libpng for example.
I add -ffunction-sections and -fdata-sections to CFLAGS of the Makefile
as to put every function into its own function.
But when I ran:
$objcopy -R .text.png_read_info pngread.o 
BFD: stXXXXYNYHix: symbol `png_read_info' required but not present
objcopy: stXXXXYNYHix: No symbols
$objcopy -N png_read_info pngread.o
BFD: stXXXX8m8Nnh: symbol `png_read_info' required but not present
objcopy: stXXXX8m8Nnh: No symbols

the comment of the error in bdf/elf.c is as bellow:
/* This case can occur when using --strip-symbol on a symbol
   which is used in a relocation entry.  */
So when I used --strip-all to remove all the symbols and relcation
informations of the object file.
This time the useless sections can be deleted.
But I don't want to remove all the symbols info, and I have no idea what
to do. 
Any suggestions will be appreciated.
Thank you very much.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [objcopy] relocation sections
  2007-12-07 16:05 [objcopy] relocation sections robertsong
@ 2007-12-21 16:31 ` Nick Clifton
  2008-01-01 10:46   ` robertsong
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Clifton @ 2007-12-21 16:31 UTC (permalink / raw)
  To: robertsong; +Cc: binutils

Hi Robert,

> I want to use objcopy to remove the useless sections from the object
> file in order the shrink the library.

Why ?  Or more specifically, how can you know that they are useless ?  Since 
you are creating a library rather than an executable, you cannot know which 
sections in which object files in the library will be needed by whatever 
application links against this library.

> Now I am using libpng for example.
> I add -ffunction-sections and -fdata-sections to CFLAGS of the Makefile
> as to put every function into its own function.
> But when I ran:
> $objcopy -R .text.png_read_info pngread.o 
> BFD: stXXXXYNYHix: symbol `png_read_info' required but not present
> objcopy: stXXXXYNYHix: No symbols
> $objcopy -N png_read_info pngread.o
> BFD: stXXXX8m8Nnh: symbol `png_read_info' required but not present
> objcopy: stXXXX8m8Nnh: No symbols
> 
> the comment of the error in bdf/elf.c is as bellow:
> /* This case can occur when using --strip-symbol on a symbol
>    which is used in a relocation entry.  */
> So when I used --strip-all to remove all the symbols and relcation
> informations of the object file.
> This time the useless sections can be deleted.
> But I don't want to remove all the symbols info, and I have no idea what
> to do. 

Simple - do not try to remove these sections from the object files.  Instead 
let the linker do it for you when you are creating your executable.  Just add 
the --gc-sections option to the linker command line and it will take care of 
eliminating any unused sections from the resultant binary.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [objcopy] relocation sections
  2007-12-21 16:31 ` Nick Clifton
@ 2008-01-01 10:46   ` robertsong
  0 siblings, 0 replies; 3+ messages in thread
From: robertsong @ 2008-01-01 10:46 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

nick, thanks for your reply.

2007/12/22, Nick Clifton <nickc@redhat.com>:
> Hi Robert,
>
> > I want to use objcopy to remove the useless sections from the object
> > file in order the shrink the library.
>
> Why ?  Or more specifically, how can you know that they are useless ?  Since
> you are creating a library rather than an executable, you cannot know which
> sections in which object files in the library will be needed by whatever
> application links against this library.
>

Well, I will search for all the applications in the target filesystem
and I want to remove the sections that are not used by these
applications. In this way, the size of the library can also be shrunk
as well as the applications.
Now libpng package has an application named as pngtest, and I used it
to take the test.

> > Now I am using libpng for example.
> > I add -ffunction-sections and -fdata-sections to CFLAGS of the Makefile
> > as to put every function into its own function.
> > But when I ran:
> > $objcopy -R .text.png_read_info pngread.o
> > BFD: stXXXXYNYHix: symbol `png_read_info' required but not present
> > objcopy: stXXXXYNYHix: No symbols
> > $objcopy -N png_read_info pngread.o
> > BFD: stXXXX8m8Nnh: symbol `png_read_info' required but not present
> > objcopy: stXXXX8m8Nnh: No symbols
> >
> > the comment of the error in bdf/elf.c is as bellow:
> > /* This case can occur when using --strip-symbol on a symbol
> >    which is used in a relocation entry.  */
> > So when I used --strip-all to remove all the symbols and relcation
> > informations of the object file.
> > This time the useless sections can be deleted.
> > But I don't want to remove all the symbols info, and I have no idea what
> > to do.
>
> Simple - do not try to remove these sections from the object files.  Instead
> let the linker do it for you when you are creating your executable.  Just add
> the --gc-sections option to the linker command line and it will take care of
> eliminating any unused sections from the resultant binary.
>

yes, I also added the --gc-sections option, but now I want to shrink
the library too.
Now I found out the error was generated when the symbol was used in
another relocation sections, and if I remove the relative section
firstly, and it will be OK.


Cheers
robert

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-01-01 10:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-07 16:05 [objcopy] relocation sections robertsong
2007-12-21 16:31 ` Nick Clifton
2008-01-01 10:46   ` robertsong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).