LoongArch: implemented a basic machine flag check

Message ID 20230320144502.3807720-1-asheplyakov@basealt.ru
State Committed
Headers
Series LoongArch: implemented a basic machine flag check |

Commit Message

Alexey Sheplyakov March 20, 2023, 2:45 p.m. UTC
  With this patch I can use eu-elflint to verify LoongArch ELF
binaries. Previously eu-elflint was complaining about invalid
machine flags:

$ ./src/elflint --gnu-ld ./src/elflint
invalid machine flags: 0x43
$ echo $?
1

Signed-off-by: Alexey Sheplyakov <asheplyakov@basealt.ru>
---
 backends/loongarch_init.c   | 1 +
 backends/loongarch_symbol.c | 7 +++++++
 2 files changed, 8 insertions(+)
  

Comments

Mark Wielaard March 20, 2023, 10:35 p.m. UTC | #1
Hi Alexey,

On Mon, Mar 20, 2023 at 06:45:02PM +0400, Alexey Sheplyakov wrote:
> With this patch I can use eu-elflint to verify LoongArch ELF
> binaries. Previously eu-elflint was complaining about invalid
> machine flags:
> 
> $ ./src/elflint --gnu-ld ./src/elflint
> invalid machine flags: 0x43
> $ echo $?
> 1

Thanks. I quickly peeked at the LoongArch ELF ABI specification and
this is precisely what needs to be checked.

Added a ChangeLog entry to the commit message, a reference to the
bug you filed and pushed.

Cheers,

Mark
  

Patch

diff --git a/backends/loongarch_init.c b/backends/loongarch_init.c
index a8ed9e81..59d8cc3d 100644
--- a/backends/loongarch_init.c
+++ b/backends/loongarch_init.c
@@ -45,6 +45,7 @@  loongarch_init (Elf *elf __attribute__ ((unused)),
 {
   loongarch_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
+  HOOK (eh, machine_flag_check);
 
   return eh;
 }
diff --git a/backends/loongarch_symbol.c b/backends/loongarch_symbol.c
index 8ba66a09..43306ab8 100644
--- a/backends/loongarch_symbol.c
+++ b/backends/loongarch_symbol.c
@@ -72,3 +72,10 @@  loongarch_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type,
       return ELF_T_NUM;
     }
 }
+
+bool
+loongarch_machine_flag_check (GElf_Word flags)
+{
+  return ((flags &~ (EF_LARCH_ABI_MODIFIER_MASK
+		     | EF_LARCH_OBJABI_V1)) == 0);
+}