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.

BUG=chrome-os-partner:31615
BRANCH=None
TEST=Compiles succesfully with 0 relocations

Change-Id: I7a39cf409a5f2bc808967d2b5334a15891c4748e
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://chromium-review.googlesource.com/214325
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Tested-by: Furquan Shaikh <furquan@chromium.org>
Commit-Queue: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
Furquan Shaikh 2014-08-26 14:59:36 -07:00 committed by chrome-internal-fetch
commit f2abd28c53

View file

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