]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
s390: elflint should check if _GLOBAL_OFFSET_TABLE_ points to .got. elfutils-0.176
authorMark Wielaard <mark@klomp.org>
Fri, 15 Feb 2019 13:39:57 +0000 (14:39 +0100)
committerMark Wielaard <mark@klomp.org>
Fri, 15 Feb 2019 13:39:57 +0000 (14:39 +0100)
The _GLOBAL_OFFSET_TABLE_ symbol might point to the DT_PLTGOT,
which is in the .got section, even if the symbol itself is
associated with the .got.plt section.

See https://sourceware.org/ml/binutils/2018-07/msg00200.html

Signed-off-by: Mark Wielaard <mark@klomp.org>
backends/ChangeLog
backends/s390_init.c
backends/s390_symbol.c

index 58a1b775b3b43cc6ae1abc4d993ccd4ed8f4afc4..0c61a0b33d1cf117fe821965060f22ca808b74eb 100644 (file)
@@ -1,3 +1,8 @@
+2019-02-15  Mark Wielaard  <mark@klomp.org>
+
+       * s390_init.c (s390_init): Hook check_special_symbol.
+       * s390_symbol.c (s390_check_sepcial_symbol): New function.
+
 2018-12-27  Jim Wilson  <jimw@sifive.com>
 
        * Makefile.am (riscv_SRCS): Add riscv64_corenote.c.
index ba8df45d6d24819fced0e31a9d9843c91915b161..0004aeeac6ae6219ed9ff9b05ff7e4f95dfed6d2 100644 (file)
@@ -54,6 +54,7 @@ s390_init (Elf *elf __attribute__ ((unused)),
   eh->name = "IBM S/390";
   s390_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
+  HOOK (eh, check_special_symbol);
   HOOK (eh, register_info);
   HOOK (eh, return_value_location);
   if (eh->class == ELFCLASS64)
index f91e13735e9ccd66919589fb1f1b0a402060b338..9e80ecaa377b86d87c3381ac5b7890691aacc299 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <elf.h>
 #include <stddef.h>
+#include <string.h>
 
 #define BACKEND                s390_
 #include "libebl_CPU.h"
@@ -55,3 +56,40 @@ s390_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type,
       return ELF_T_NUM;
     }
 }
+
+/* The _GLOBAL_OFFSET_TABLE_ symbol might point to the DT_PLTGOT,
+   which is in the .got section, even if the symbol itself is
+   associated with the is a .got.plt section.
+   https://sourceware.org/ml/binutils/2018-07/msg00200.html  */
+bool
+s390_check_special_symbol (Elf *elf, const GElf_Sym *sym,
+                              const char *name, const GElf_Shdr *destshdr)
+{
+  if (name != NULL
+      && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
+    {
+      size_t shstrndx;
+      if (elf_getshdrstrndx (elf, &shstrndx) != 0)
+       return false;
+      const char *sname = elf_strptr (elf, shstrndx, destshdr->sh_name);
+      if (sname != NULL
+         && (strcmp (sname, ".got") == 0 || strcmp (sname, ".got.plt") == 0))
+       {
+         Elf_Scn *scn = NULL;
+         while ((scn = elf_nextscn (elf, scn)) != NULL)
+           {
+             GElf_Shdr shdr_mem;
+             GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
+             if (shdr != NULL)
+               {
+                 sname = elf_strptr (elf, shstrndx, shdr->sh_name);
+                 if (sname != NULL && strcmp (sname, ".got") == 0)
+                   return (sym->st_value >= shdr->sh_addr
+                           && sym->st_value < shdr->sh_addr + shdr->sh_size);
+               }
+           }
+       }
+    }
+
+  return false;
+}