From 935a0041acbc94ca38691b9a755a8ea94cfe0d89 Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Tue, 26 Aug 2014 14:57:23 -0700 Subject: [PATCH] UPSTREAM: rmodtool: correct final memory size calculation Apparently when I originally wrote this I confused myself to no end. The code/data of an rmodule has a set memory size which is associated with the .payload section. The relocation entries may increase the overall footprint of the memory size if the rmodule has no bss but a lot of relocations. Therefore, just compare relocation entries size plus the file size of the .payload section with the memory size of the paylod section. The .empty section is added only when we have not met the final target size. BUG=chrome-os-partner:31615 BRANCH=None TEST=Compiles successfully and the elf.rmod created is verified using readelf and objdump Change-Id: I67d8c1267b2216786019eadc02f48b6502026602 Author: Aaron Durbin Signed-off-by: Furquan Shaikh Reviewed-on: https://chromium-review.googlesource.com/214324 Tested-by: Furquan Shaikh Reviewed-by: Aaron Durbin Commit-Queue: Aaron Durbin --- util/cbfstool/rmodule.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/cbfstool/rmodule.c b/util/cbfstool/rmodule.c index b0096f24cb..e4329d4693 100644 --- a/util/cbfstool/rmodule.c +++ b/util/cbfstool/rmodule.c @@ -548,11 +548,11 @@ write_elf(const struct rmod_context *ctx, const struct buffer *in, * is considered a part of the program. */ total_size += buffer_size(&rmod_header); - total_size += ctx->phdr->p_memsz; - if (buffer_size(&relocs) + ctx->phdr->p_filesz > total_size) { - total_size -= ctx->phdr->p_memsz; + if (buffer_size(&relocs) + ctx->phdr->p_filesz > ctx->phdr->p_memsz) { total_size += buffer_size(&relocs); total_size += ctx->phdr->p_filesz; + } else { + total_size += ctx->phdr->p_memsz; } ret = add_section(ew, &rmod_header, ".header", addr,