This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Howto change flags of a section?
- From: Thierry Bidault <thierry dot bidault at st dot com>
- To: "binutils at sources dot redhat dot com" <binutils at sources dot redhat dot com>
- Date: Thu, 24 Oct 2002 12:23:10 +0200
- Subject: Howto change flags of a section?
Hello from France,
I'm using bfd 2.9.1
and I'm wrtting a binutil that adds the flag SEC_EXCLUDE to a given
section.
I have used bfd_set_section_flags for it, but the flags of this section
are not changed (for instance with objdump I can't see them).
Do you have any idea where this comes from?
Thank you very much for your help.
This is the code I wrote:
static void
set_section_flags (bfd *ibfd, sec_ptr isection, PTR obfdarg)
{
if (strcmp(isection->name, ".mysection") == 0) {
flagword flags;
flags = bfd_get_section_flags (ibfd, isection);
/* Add SEC_EXCLUDE flag to .profile_info section to tell the linker
to erase this section when creating a final binary*/
flags |= SEC_EXCLUDE;
if (!bfd_set_section_flags (ibfd, isection, flags))
{
fprintf(stderr,"set flags ERROR\n");
}
fprintf(stdout,"new flags for %s:0x%x\n", isection->name,
isection->flags);
}
}
int
main (int argc, char *argv[])
{
char *file = NULL;
int f;
bfd *abfd;
file = argv[1];
f = open (file, O_RDWR, 0);
if (f < 0)
{
bfd_set_error (bfd_error_system_call);
bfd_fatal (file);
}
abfd = bfd_fdopenr (file, (const char *) NULL, f);
if (abfd == NULL)
bfd_fatal (file);
if (!bfd_check_format (abfd, bfd_object))
{
fprintf (stderr, "Not a bfd_object %s ! \n", file);
exit (-1);
}
bfd_map_over_sections (abfd, set_section_flags, (void *) NULL);
if (!bfd_close (abfd))
bfd_fatal (file);
return 0;
}
--
Thierry Bidault