From 147edc30e5afb3fa0b17727fde972a0c1a9b275f Mon Sep 17 00:00:00 2001 From: norly Date: Mon, 27 May 2013 04:57:46 +0100 Subject: 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. --- src/elfops/check.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/elfops') 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); + } } } -- cgit v1.2.3