summaryrefslogtreecommitdiff
path: root/src/elfops
diff options
context:
space:
mode:
authornorly <ny-git@enpas.org>2013-05-27 04:57:46 +0100
committernorly <ny-git@enpas.org>2013-05-27 05:13:37 +0100
commit147edc30e5afb3fa0b17727fde972a0c1a9b275f (patch)
tree062d4667190e4921dca1b354033bfd99938480b7 /src/elfops
parent6a9a293ebbe91ff82defbfabc30f6c23ec270a54 (diff)
Abstract model more - break 'make check'
Sections are now sorted by file offset and sh_link dependencies between them as well as PHDR-SHDR dependencies are deduced as much as possible. The downside is that while the output should still work just fine, 'make check' fails to establish binary equivalence of input and output if the section table is reordered. Thankfully, in normal GCC binaries it is already ordered so we don't have to worry about this. Unfortunately the ELF spec is very lax in this regard so we have to draw a line ourselves.
Diffstat (limited to 'src/elfops')
-rw-r--r--src/elfops/check.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/elfops/check.c b/src/elfops/check.c
index 8aaa7b5..daf6542 100644
--- a/src/elfops/check.c
+++ b/src/elfops/check.c
@@ -160,6 +160,22 @@ int elfu_eCheck(Elf *e)
goto ERROR;
}
}
+
+ /* Section addr/offset should match parent PHDR.
+ * Find parent PHDR: */
+ for (j = 0; j < numPhdr; j++) {
+ if (PHDR_CONTAINS_SCN_IN_MEMORY(&phdrs[j], &shdrs[i])) {
+ if (!PHDR_CONTAINS_SCN_IN_FILE(&phdrs[j], &shdrs[i])) {
+ ELFU_WARN("elfu_eCheck: Memory/file offsets/sizes are not congruent for SHDR %d, PHDR %d.\n", i, j);
+ goto ERROR;
+ }
+ }
+ }
+
+ /* sh_link members should not point to sections out of range. */
+ if (shdrs[i].sh_link >= numShdr) {
+ ELFU_WARN("elfu_eCheck: Bogus sh_link in SHDR %d.\n", i);
+ }
}
}