]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
backends: add checks for _GLOBAL_OFFSET_TABLE_ on loongarch
authorYouling Tang <tangyouling@loongson.cn>
Sat, 1 Apr 2023 03:18:53 +0000 (11:18 +0800)
committerMark Wielaard <mark@klomp.org>
Thu, 6 Apr 2023 22:47:01 +0000 (00:47 +0200)
Add handling of _GLOBAL_OFFSET_TABLE_.

Before applying the patch:
$ ./src/elflint --gnu-ld ./src/elflint
section [35] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol value 0x68548
does not match .got.plt section address 0x68238

After applying the patch:
$ ./src/elflint --gnu-ld ./src/elflint
No errors

Signed-off-by: Liwei Ge <geliwei@openanolis.org>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
backends/ChangeLog
backends/loongarch_init.c
backends/loongarch_symbol.c

index 9eee3036a3e8e9d33e0959d3305c73a8f4f39d7f..7bde291999ae84d9d90e78b0a614d0859deb7943 100644 (file)
@@ -1,3 +1,8 @@
+2023-04-01  Youling Tang <tangyouling@loongson.cn>
+
+       * loongarch_init.c (loongarch_init): Hook check_special_symbol.
+       * loongarch_symbol.c (loongarch_check_special_symbol): New function.
+
 2023-04-01  Youling Tang  <tangyouling@loongson.cn>
 
        * loongarch_reloc.def: Add RELOC_TYPE B16 to RELAX.
index 59d8cc3dab3236a2153ef89eb1cde3100af3f4b4..b641b07fa062a014b9eabc772373ad4affdf5b28 100644 (file)
@@ -46,6 +46,7 @@ loongarch_init (Elf *elf __attribute__ ((unused)),
   loongarch_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
   HOOK (eh, machine_flag_check);
+  HOOK (eh, check_special_symbol);
 
   return eh;
 }
index 43306ab8b2d6c59d7521c0f7ee8f71ddb7acec79..5ce55badc569283ab16eabaa7ea6b8656bdf1689 100644 (file)
@@ -79,3 +79,38 @@ loongarch_machine_flag_check (GElf_Word flags)
   return ((flags &~ (EF_LARCH_ABI_MODIFIER_MASK
                     | EF_LARCH_OBJABI_V1)) == 0);
 }
+
+/* Check whether given symbol's st_value and st_size are OK despite failing
+   normal checks.  */
+bool
+loongarch_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;
+}