Removing sections from an ELF file

Peter Barada pbarada at mail.wm.sps.mot.com
Fri May 10 15:40:32 UTC 2002


>Has anyone seen a tool that will remove or strip a section from an ELF
>file?  I use a couple of data sections to represent battery backed ram, and
>I deal with initializing those sections in my own code.  I haven't been
>able to convince the linker to omit the sections, and I can't tell the
>downloader to ignore 'em...so, I'd like to remove them.  Any ideas?

In ld documentation, look up 'NOLOAD'.  It specifies that the section
is not to be loaded.  Here's an example which tells the linker to mark
the .bss section with NOLOAD:

  .bss (NOLOAD) : {                           
    *(.sbss)                                  
    *(.bss)                                   
    *(COMMON)                                 
  } > ram                                     

You could 'objdump -h' the resultant elf file to see the attributes on
each of the sections.

If your loader doesn't understand the NOLOAD attribute, you could also
use 'objcopy --remove-section=SECTIONNAME' to physically rip those
sections out of the linked elf file. 

-- 
Peter Barada                                   Peter.Barada at motorola.com
Wizard                                         781-852-2768 (direct)
WaveMark Solutions(wholly owned by Motorola)   781-270-0193 (fax)



More information about the users mailing list