rmodtool: Allow rmodules with 0 relocations

Currently, rmodules with 0 relocations are not allowed. Fix this by skipping
addition of .rmodules section on 0 relocs.

Change-Id: I7a39cf409a5f2bc808967d2b5334a15891c4748e
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: http://review.coreboot.org/6774
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@google.com>
Tested-by: build bot (Jenkins)
This commit is contained in:
Furquan Shaikh 2014-08-26 14:59:36 -07:00
parent 2af76f4bdc
commit b237c10899
1 changed files with 9 additions and 8 deletions

View File

@ -259,10 +259,8 @@ static int collect_relocations(struct rmod_context *ctx)
nrelocs = ctx->nrelocs; nrelocs = ctx->nrelocs;
INFO("%d relocations to be emitted.\n", nrelocs); INFO("%d relocations to be emitted.\n", nrelocs);
if (!nrelocs) { if (!nrelocs)
ERROR("No valid relocations in file.\n"); return 0;
return -1;
}
/* Reset the counter for indexing into the array. */ /* Reset the counter for indexing into the array. */
ctx->nrelocs = 0; ctx->nrelocs = 0;
@ -536,10 +534,13 @@ write_elf(const struct rmod_context *ctx, const struct buffer *in,
goto out; goto out;
addr += ctx->phdr->p_filesz; addr += ctx->phdr->p_filesz;
ret = add_section(ew, &relocs, ".relocs", addr, buffer_size(&relocs)); if (ctx->nrelocs) {
if (ret < 0) ret = add_section(ew, &relocs, ".relocs", addr,
goto out; buffer_size(&relocs));
addr += buffer_size(&relocs); if (ret < 0)
goto out;
addr += buffer_size(&relocs);
}
if (total_size != addr) { if (total_size != addr) {
ret = add_section(ew, NULL, ".empty", addr, total_size - addr); ret = add_section(ew, NULL, ".empty", addr, total_size - addr);