summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2019-08-05 10:13:06 -0700
committerH. Peter Anvin <hpa@zytor.com>2019-08-05 10:13:06 -0700
commita0d15be8e1a3b8126770d19f7cdf925ca0837782 (patch)
tree950e5ad76584e8b92a319a67747fa16b8f8c8815
parentb65e72a256c23fefaaff8d760c72c826a115b32d (diff)
downloadsamples-a0d15be8e1a3b8126770d19f7cdf925ca0837782.tar.gz
samples-a0d15be8e1a3b8126770d19f7cdf925ca0837782.tar.xz
samples-a0d15be8e1a3b8126770d19f7cdf925ca0837782.zip
elf2exe: sort relocations
The linker probably already did, but just in case, sort the relocations, for predictability and possibly for loader optimization/simplification. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--elf2exe/elf2exe.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/elf2exe/elf2exe.c b/elf2exe/elf2exe.c
index efa37c9..856e748 100644
--- a/elf2exe/elf2exe.c
+++ b/elf2exe/elf2exe.c
@@ -195,6 +195,14 @@ static void free_relocs(struct exe_relocs *er)
}
}
+static int compare_le32(const void *ap, const void *bp)
+{
+ uint32_t a = getle(*(const uint32_t *)ap);
+ uint32_t b = getle(*(const uint32_t *)bp);
+
+ return (a > b) - (a < b);
+}
+
static int make_relocs(const struct fileinfo *in, const struct dyninfo *di,
struct exe_relocs *er)
{
@@ -270,6 +278,12 @@ static int make_relocs(const struct fileinfo *in, const struct dyninfo *di,
break;
}
}
+
+ for (j = 0; er[j].r_type != R_386_NONE; j++) {
+ /* In case the linker didn't, sort the relocations */
+ qsort(er[j].exerelocs, er[j].nrelocs, sizeof(uint32_t),
+ compare_le32);
+ }
return 0;
err: