]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
backends: add checks for _GLOBAL_OFFSET_TABLE_ and __global_pointer$ on riscv
authorAndreas Schwab <schwab@suse.de>
Tue, 15 May 2018 11:47:02 +0000 (13:47 +0200)
committerMark Wielaard <mark@klomp.org>
Tue, 15 May 2018 14:46:18 +0000 (16:46 +0200)
Signed-off-by: Andreas Schwab <schwab@suse.de>
backends/ChangeLog
backends/riscv_init.c
backends/riscv_symbol.c

index 63bb7e444eea6be8dab47c8afaf7ec2447cfb7a1..0dde0ff3f5ccc55334c220d9997f87dbb024af3e 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-15  Andreas Schwab  <schwab@suse.de>
+
+       * riscv_init.c (riscv_init): Hook check_special_symbol.
+       * riscv_symbol.c (riscv_check_special_symbol): New function.
+
 2018-04-19  Andreas Schwab  <schwab@suse.de>
 
        * Makefile.am (modules): Add riscv.
index 761d9c2e18fd27cfd08f5401de82654cd472ff36..80be86d3c5ef1b572e945ae66cd64fcdb1a88647 100644 (file)
@@ -51,6 +51,7 @@ riscv_init (Elf *elf __attribute__ ((unused)),
   eh->name = "RISC-V";
   riscv_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
+  HOOK (eh, check_special_symbol);
   HOOK (eh, machine_flag_check);
 
   return MODVERSION;
index 628e0572aea6151b892cb5b3656b47ad10e34228..dce8e3586b0015b18c97f1c76f2e008d42e76d62 100644 (file)
@@ -60,3 +60,35 @@ riscv_machine_flag_check (GElf_Word flags)
   return ((flags &~ (EF_RISCV_RVC
                     | EF_RISCV_FLOAT_ABI)) == 0);
 }
+
+/* Check whether given symbol's st_value and st_size are OK despite failing
+   normal checks.  */
+bool
+riscv_check_special_symbol (Elf *elf, GElf_Ehdr *ehdr, const GElf_Sym *sym,
+                           const char *name, const GElf_Shdr *destshdr)
+{
+  if (name == NULL)
+    return false;
+
+  const char *sname = elf_strptr (elf, ehdr->e_shstrndx, destshdr->sh_name);
+  if (sname == NULL)
+    return false;
+
+  /* _GLOBAL_OFFSET_TABLE_ points to the start of the .got section, but it
+     is preceded by the .got.plt section in the output .got section.  */
+  if (strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
+    return (strcmp (sname, ".got") == 0
+           && sym->st_value >= destshdr->sh_addr
+           && sym->st_value < destshdr->sh_addr + destshdr->sh_size);
+
+  /* __global_pointer$ points to the .sdata section with an offset of
+     0x800.  It might however fall in the .got section, in which case we
+     cannot check the offset.  The size always should be zero.  */
+  if (strcmp (name, "__global_pointer$") == 0)
+    return (((strcmp (sname, ".sdata") == 0
+             && sym->st_value == destshdr->sh_addr + 0x800)
+            || strcmp (sname, ".got") == 0)
+           && sym->st_size == 0);
+
+  return false;
+}