This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Creating .note sections
- From: Ceri Storey <cez at necrofish dot org dot uk>
- To: binutils at sources dot redhat dot com
- Date: Wed, 23 Apr 2003 13:31:05 +0100
- Subject: Re: Creating .note sections
- References: <20030420213010.GC29154@hilbert.house>
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 at necrofish dot org dot uk>