summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2021-11-16 14:23:30 -0500
committerTom Rini <[email protected]>2021-11-16 14:23:30 -0500
commit3144ba23bf4649f699078259fdf2e5cb4eab8f53 (patch)
treef19391a1e5401b638c072cb654b5f32858f17a67 /tools
parent2ffa0e87df3a7595f71d05782924ee83146d9fe7 (diff)
parent4b32531be236bbd9ca60f26447511f79e214f79e (diff)
Merge branch '2021-11-15-assorted-fixes'
- Rename "tqc" to "tq" and related updates - Assorted minor ARM updates, build updates and documentation updates
Diffstat (limited to 'tools')
-rw-r--r--tools/relocate-rela.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c
index 6a524014b73..f0bc548617a 100644
--- a/tools/relocate-rela.c
+++ b/tools/relocate-rela.c
@@ -63,7 +63,7 @@ int main(int argc, char **argv)
{
FILE *f;
int i, num;
- uint64_t rela_start, rela_end, text_base;
+ uint64_t rela_start, rela_end, text_base, file_size;
if (argc != 5) {
fprintf(stderr, "Statically apply ELF rela relocations\n");
@@ -87,8 +87,7 @@ int main(int argc, char **argv)
return 3;
}
- if (rela_start > rela_end || rela_start < text_base ||
- (rela_end - rela_start) % sizeof(Elf64_Rela)) {
+ if (rela_start > rela_end || rela_start < text_base) {
fprintf(stderr, "%s: bad rela bounds\n", argv[0]);
return 3;
}
@@ -96,6 +95,21 @@ int main(int argc, char **argv)
rela_start -= text_base;
rela_end -= text_base;
+ fseek(f, 0, SEEK_END);
+ file_size = ftell(f);
+ rewind(f);
+
+ if (rela_end > file_size) {
+ // Most likely compiler inserted some section that didn't get
+ // objcopy-ed into the final binary
+ rela_end = file_size;
+ }
+
+ if ((rela_end - rela_start) % sizeof(Elf64_Rela)) {
+ fprintf(stderr, "%s: rela size isn't a multiple of Elf64_Rela\n", argv[0]);
+ return 3;
+ }
+
num = (rela_end - rela_start) / sizeof(Elf64_Rela);
for (i = 0; i < num; i++) {