cbfstool: add ELF symbol, relocation, and string table support

In order to convert rmodules back into ELF files one needs
to add in the relocations so they can be converted back to
rmodules. Because of that requirement symbol tables need
to be present because the relocations reference the symbols.
Additionally, symbol tables reference a string table for the
symbol names. Provide the necessary support for adding all
of those things to an ELF writer.

TEST=Extracted rmodule from a cbfs and compared with the
     source ELF file. Confirmed relocations and code sizes
     are correct.

Change-Id: I07e87a30b3371ddedabcfc682046e3db8c956ff2
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/12221
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
This commit is contained in:
Aaron Durbin
2015-10-28 11:26:40 -05:00
parent 8e982eabfa
commit cedcb882c1
2 changed files with 431 additions and 13 deletions

View File

@ -109,6 +109,17 @@ void elf_writer_destroy(struct elf_writer *ew);
int elf_writer_add_section(struct elf_writer *ew, const Elf64_Shdr *shdr,
struct buffer *contents, const char *name);
/* Add an absolute symbol to the ELF file returning < 0 on error, index of
* symbol otherwise. */
int elf_writer_add_symbol(struct elf_writer *ew, const char *name,
const char *section_name,
Elf64_Addr value, Elf64_Word size,
int binding, int type);
/* Add an absolute relocation referencing the provided symbol name. Returns < 0
* on error, 0 on success. */
int elf_writer_add_rel(struct elf_writer *ew, const char *sym, Elf64_Addr addr);
/*
* Serialize the ELF file to the output buffer. Return < 0 on error,
* 0 on success.