]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Check alignment of section base address
authorPetr Machata <pmachata@redhat.com>
Fri, 3 Jul 2009 15:59:47 +0000 (17:59 +0200)
committerPetr Machata <pmachata@redhat.com>
Fri, 3 Jul 2009 15:59:47 +0000 (17:59 +0200)
src/dwarflint.c

index 9576349990a9707b41e7b962475ac35aec015822..06ab869ba93e9c9a220abd485fc6641dcafb9fb9 100644 (file)
@@ -1064,6 +1064,12 @@ where_reset_3 (struct where *wh, uint64_t addr)
 
 #define WHERE_SECDATA(DATA, PARENT) (WHERE (data_get_sec (DATA)->id, PARENT))
 
+static bool
+address_aligned (uint64_t addr, uint64_t align)
+{
+  return align < 2 || (addr % align == 0);
+}
+
 static void
 process_file (Dwarf *dwarf, const char *fname, bool only_one)
 {
@@ -1169,6 +1175,11 @@ process_file (Dwarf *dwarf, const char *fname, bool only_one)
       if (scnname == NULL)
        goto invalid_elf;
 
+      if (!address_aligned (shdr->sh_addr, shdr->sh_addralign))
+       wr_error (NULL, "Base address of section %s, %#" PRIx64
+                 ", should have an alignment of %" PRId64 ".\n",
+                 scnname, shdr->sh_addr, shdr->sh_addralign);
+
       struct secinfo *secentry = find_secentry (scnname);
       struct section_data *secdata = secentry != NULL ? secentry->dataptr : NULL;
       cursec->scn = scn;