This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils 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: Adding a NOTE section after a copy ..


You cannot add an SHF_ALLOC section to an already-final (non-ET_REL) ELF
file without doing a lot more work.  If you want a non-allocated section
created with the compiler, you have to play some games with asm () to get
the section flags right.  For adding a simple string or binary blob, it is
easier to write or generate assembly source where you write exactly the
section directive you want (.section .note.foo, "", @note).

If you use ELF_F_LAYOUT (which you must unless you recompute the phdrs
too), then you have to set sh_offset manually in your new section.

Indeed you do not have to adjust e_shnum; that is automatic in elf_update
after you have used elf_newscn.  Of course, you do need to add your
section's name to .shstrtab.

You may find it easier to write a script using objcopy --add-section
(binutils) rather than writing your own tool with libelf.


Thanks,
Roland

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