Creating .note sections
Ceri Storey
cez@necrofish.org.uk
Wed Apr 23 12:31:00 GMT 2003
On Sun, Apr 20, 2003 at 10:30:10PM +0100, Ceri Storey wrote:
> How do people reccomend I go about programmaticly adding a .note section
> to an already-existing (ELF format) binary *and* have it's type set to
Well, i've figured out that the backed will set any sections who's name
begins with ".note" to type PT_NOTE, so that's sorted. Unfourtunately,
the code segfaults _bfd_elf_strtab_emit () after I call bfd_close ().
The code I'm using to add the section is as follows:
sec = bfd_make_section(thebfd, buf);
if (sec == NULL) {
bfd_perror("make section");
exit(1);
}
printf("set section size: %#016llx\n", (unsigned long long)sectsz);
if (!bfd_set_section_size(thebfd, sec, sectsz)) {
bfd_perror("set section size");
exit(1);
}
sec->output_section = sec;
sec->output_offset = 0;
if (!bfd_set_section_flags(thebfd, sec,
SEC_HAS_CONTENTS | SEC_READONLY | SEC_IN_MEMORY)) {
bfd_perror("set section flags");
exit(1);
}
if (!bfd_set_section_contents(thebfd, sec, sigsect, 0, sectsz)) {
bfd_perror("set section contents");
exit(1);
}
}
--
Ceri Storey <cez@necrofish.org.uk>
More information about the Binutils
mailing list