This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Creating .note sections


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>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]