This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v4 06/17] RISC-V: Startup and Dynamic Loading Code
- From: Palmer Dabbelt <palmer at dabbelt dot com>
- To: joseph at codesourcery dot com
- Cc: libc-alpha at sourceware dot org, patches at groups dot riscv dot org
- Date: Mon, 22 Jan 2018 15:01:46 -0800 (PST)
- Subject: Re: [PATCH v4 06/17] RISC-V: Startup and Dynamic Loading Code
- Authentication-results: sourceware.org; auth=none
On Mon, 15 Jan 2018 08:54:55 PST (-0800), joseph@codesourcery.com wrote:
On Sat, 13 Jan 2018, Palmer Dabbelt wrote:
diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
+/* Return nonzero iff ELF header is compatible with the running host. */
+static inline int __attribute_used__
+elf_machine_matches_host (const ElfW (Ehdr) *ehdr)
+{
+ return ehdr->e_machine == EM_RISCV;
+}
I don't think this is sufficient. You should also check that the
floating-point ABI matches so you don't load shared libraries for the
wrong ABI. (See e.g. MIPS for a more complicated elf_machine_matches_host
example.) If in future you have RV64I ILP32, you'll also need to check
that only the right ILP32 libraries for the current instruction set are
loaded (not RV32I into an RV64I ILP32 process or vice versa). (Generic
code in dl-load.c deals with only loading whichever is appropriate of
32-bit or 64-bit ELF.)
Ah, OK -- when I was going through something else I was wondering how that got
enforced, I guess the answer is that it wasn't. I think something like this
should do it
diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
index 7d4fcee79662..21e401dbf2fb 100644
--- a/sysdeps/riscv/dl-machine.h
+++ b/sysdeps/riscv/dl-machine.h
@@ -57,7 +57,20 @@
static inline int __attribute_used__
elf_machine_matches_host (const ElfW (Ehdr) *ehdr)
{
- return ehdr->e_machine == EM_RISCV;
+ /* We can only run RISC-V binaries. */
+ if (ehdr->e_machine != EM_RISCV)
+ return 1;
+
+#ifdef __ricsv_float_abi_double
+ /* Hard-float libraries */
+ if ((ehdr->e_flags & EF_RISCV_FLOAT_ABI) == EF_RISCV_FLOAT_ABI_DOUBLE)
+ return 1;
+#else
+ if ((ehdr->e_flags & EF_RISCV_FLOAT_ABI) == EF_RISCV_FLOAT_ABI_SOFT)
+ return 1;
+#endif
+
+ return 0;
}
/* Return the link-time address of _DYNAMIC. */
I'll include something like that in our v5.