* [PATCH] backends: add checks for _GLOBAL_OFFSET_TABLE_ and __global_pointer$ on riscv
@ 2018-05-15 11:47 Andreas Schwab
2018-05-15 14:49 ` Mark Wielaard
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Schwab @ 2018-05-15 11:47 UTC (permalink / raw)
To: elfutils-devel
Signed-off-by: Andreas Schwab <schwab@suse.de>
---
backends/ChangeLog | 5 +++++
backends/riscv_init.c | 1 +
backends/riscv_symbol.c | 32 ++++++++++++++++++++++++++++++++
3 files changed, 38 insertions(+)
diff --git a/backends/ChangeLog b/backends/ChangeLog
index 63bb7e444e..0dde0ff3f5 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -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.
diff --git a/backends/riscv_init.c b/backends/riscv_init.c
index 0203eac8b8..4234cded2b 100644
--- a/backends/riscv_init.c
+++ b/backends/riscv_init.c
@@ -52,6 +52,7 @@ riscv_init (Elf *elf __attribute__ ((unused)),
riscv_init_reloc (eh);
HOOK (eh, register_info);
HOOK (eh, reloc_simple_type);
+ HOOK (eh, check_special_symbol);
HOOK (eh, machine_flag_check);
return MODVERSION;
diff --git a/backends/riscv_symbol.c b/backends/riscv_symbol.c
index 628e0572ae..dce8e3586b 100644
--- a/backends/riscv_symbol.c
+++ b/backends/riscv_symbol.c
@@ -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;
+}
--
2.17.0
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] backends: add checks for _GLOBAL_OFFSET_TABLE_ and __global_pointer$ on riscv
2018-05-15 11:47 [PATCH] backends: add checks for _GLOBAL_OFFSET_TABLE_ and __global_pointer$ on riscv Andreas Schwab
@ 2018-05-15 14:49 ` Mark Wielaard
2018-05-15 14:56 ` Andreas Schwab
0 siblings, 1 reply; 3+ messages in thread
From: Mark Wielaard @ 2018-05-15 14:49 UTC (permalink / raw)
To: Andreas Schwab, elfutils-devel
On Tue, 2018-05-15 at 13:47 +0200, Andreas Schwab wrote:
> +
> + * riscv_init.c (riscv_init): Hook check_special_symbol.
> + * riscv_symbol.c (riscv_check_special_symbol): New function.
Looks good. Pushed.
I assume this solves some of the self-tests in make check on riscv.
Is there an ELF abi document for riscv that describes these special
symbols?
Thanks,
Mark
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] backends: add checks for _GLOBAL_OFFSET_TABLE_ and __global_pointer$ on riscv
2018-05-15 14:49 ` Mark Wielaard
@ 2018-05-15 14:56 ` Andreas Schwab
0 siblings, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 2018-05-15 14:56 UTC (permalink / raw)
To: Mark Wielaard; +Cc: elfutils-devel
On Mai 15 2018, Mark Wielaard <mark@klomp.org> wrote:
> Is there an ELF abi document for riscv that describes these special
> symbols?
There is
<https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md>,
but it doesn't mention the symbols. I have extracted that out of the
binutils sources.
Andreas.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-05-15 14:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-15 11:47 [PATCH] backends: add checks for _GLOBAL_OFFSET_TABLE_ and __global_pointer$ on riscv Andreas Schwab
2018-05-15 14:49 ` Mark Wielaard
2018-05-15 14:56 ` Andreas Schwab
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).