[2/2] Hexagon: implement machine flag check

Message ID 0d011ba233face7165e519af8aca1bbd46f9d61b.1711055228.git.quic_mathbern@quicinc.com
State Superseded
Headers
Series Add initial support for Hexagon |

Commit Message

Matheus Tavares Bernardino March 21, 2024, 9:09 p.m. UTC
  This fixes the "invalid machine flag" error from eu-elflint when passing
hexagon binaries.

Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
---
 backends/hexagon_init.c   | 1 +
 backends/hexagon_symbol.c | 8 ++++++++
 2 files changed, 9 insertions(+)
  

Patch

diff --git a/backends/hexagon_init.c b/backends/hexagon_init.c
index 9c8c6d8d..1cd27513 100644
--- a/backends/hexagon_init.c
+++ b/backends/hexagon_init.c
@@ -45,6 +45,7 @@  hexagon_init (Elf *elf __attribute__ ((unused)),
 {
   hexagon_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
+  HOOK (eh, machine_flag_check);
 
   return eh;
 }
diff --git a/backends/hexagon_symbol.c b/backends/hexagon_symbol.c
index b341243e..1e681e9f 100644
--- a/backends/hexagon_symbol.c
+++ b/backends/hexagon_symbol.c
@@ -56,3 +56,11 @@  hexagon_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type,
       return ELF_T_NUM;
     }
 }
+
+bool
+hexagon_machine_flag_check (GElf_Word flags)
+{
+  GElf_Word arch_variant = flags &~ EF_HEXAGON_MACH;
+  /* 0x8000 covers the "tiny core" arch variants. */
+  return arch_variant == 0 || arch_variant == 0x8000;
+}