[RFC,1/2] RISC-V: Move TSO check to elf_machine_matches_host()

Message ID 20231127145603.2339644-2-christoph.muellner@vrull.eu
State New
Series RISC-V: Add dynamic TSO support |


Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Testing passed

Commit Message

Christoph Müllner Nov. 27, 2023, 2:56 p.m. UTC
  From: Christoph Müllner <christoph.muellner@vrull.eu>

The current implementation does not support ELF files which  have the
EF_RISCV_TSO ELF flag set.  This is implemented in process_elf64_file(),
with the assumption that no TSO-capable hosts exists.

In order to weaken this restriction, let's move the TSO flag check
into elf_machine_matches_host(), where compatibility with the host
can be checked.

This patch serves as a preparation for further changes and does
not intend to implement any functional changes.

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
 sysdeps/riscv/dl-machine.h                 | 4 ++++
 sysdeps/unix/sysv/linux/riscv/readelflib.c | 5 ++---
 2 files changed, 6 insertions(+), 3 deletions(-)


diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
index c0c9bd93ad..ce537731dd 100644
--- a/sysdeps/riscv/dl-machine.h
+++ b/sysdeps/riscv/dl-machine.h
@@ -72,6 +72,10 @@  elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
     return 0;
+  /* Execution of TSO binaries is not supported at this time.  */
+  if (ehdr->e_flags & EF_RISCV_TSO)
+    return 0;
   return 1;
diff --git a/sysdeps/unix/sysv/linux/riscv/readelflib.c b/sysdeps/unix/sysv/linux/riscv/readelflib.c
index 788eba8305..e2bd4d7727 100644
--- a/sysdeps/unix/sysv/linux/riscv/readelflib.c
+++ b/sysdeps/unix/sysv/linux/riscv/readelflib.c
@@ -30,10 +30,9 @@  int process_elf64_file (const char *file_name, const char *lib,
      extension, we can still support libraries compiled without that extension
      so we just ignore this flag.
    - EF_RISCV_RVE: glibc (and Linux) don't support RV32E based systems.
-   - EF_RISCV_TSO: The TSO extension isn't supported, as doing so would require
-     some mechanism to ensure that the TSO extension is enabled which doesn't
+   - EF_RISCV_TSO: Accepted with restrictions (see elf_machine_matches_host).
      currently exist.  */
 /* Returns 0 if everything is ok, != 0 in case of error.  */