public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] kvx: fix 32-bit build and validation
@ 2023-08-22 16:01 Paul Iannetta
  2023-08-23  0:27 ` Alan Modra
  2023-08-23  3:16 ` Alan Modra
  0 siblings, 2 replies; 19+ messages in thread
From: Paul Iannetta @ 2023-08-22 16:01 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 147 bytes --]

Hi,

This patch should fix most issues on 32-bit hosts, both the build and
the validation should work cleanly.

Can I merge it into master?
Paul



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-kvx-fix-32-bit-build-and-validation.patch --]
[-- Type: text/x-diff, Size: 13376 bytes --]

From 6900d3245c59cc4b4da026328e74beae66a05b9d Mon Sep 17 00:00:00 2001
From: Paul Iannetta <piannetta@kalrayinc.com>
Date: Thu, 17 Aug 2023 16:08:29 +0200
Subject: [PATCH] kvx: fix 32-bit build and validation

gas/ChangeLog:

2023-08-22  Paul Iannetta  <piannetta@kalrayinc.com>

	* config/tc-kvx.h (struct token_s): Use int64_t and uint64_t
	  instead of long long and unsigned long long.
	* config/tc-kvx.c (kvx_set_cpu): Use ELFOSABI_GNU for the
	  kvx-linux target.
	(struct token_list):
	* config/kvx-parse.c (promote_token): Likewise.
	(print_token_list): Likewise.
	(get_token_class): Likewise and fix immediate selection on
	32-bit hosts.

bfd/ChangeLog:

2023-08-22  Paul Iannetta  <piannetta@kalrayinc.com>

	* Makefile.am: Move elf32-kvx.lo from BFD32_BACKENDS to
	  BFD64_BACKENDS.  Remove elfxx-kvx.lo from BFD32_BACKENDS.
	  Remove elfxx-kvx.c from BFD32_BACKENDS_CFILES.
	* Makefile.in: Regenerate.
	* config.bfd: Adjust targ_defvec and targ_selvecs and gate them
	  behing BFD64.
	* configure.ac: Add target_size=64 to kvx_elf64_*vec.
	* configure: Regenerate.
	* elfnn-kvx.c (elfNN_kvx_stub_name): Cast rel->r_addend to
	  uint64_t.
	(elfNN_kvx_relocate_section): Likewise.

ld/ChangeLog:

2023-08-22  Paul Iannetta  <piannetta@kalrayinc.com>

	* Makefile.am: Move eelf32kvx.c from ALL_EMULATION_SOURCES to
	  ALL_64_EMULATION_SOURCES.
	* Makefile.in: Regenerate.
	* configure.tgt: Split long line.
---
 bfd/Makefile.am        |  4 +---
 bfd/Makefile.in        |  4 +---
 bfd/config.bfd         |  9 ++++-----
 bfd/configure          |  4 ++--
 bfd/configure.ac       |  4 ++--
 bfd/elfnn-kvx.c        | 10 +++++-----
 gas/config/kvx-parse.c | 26 +++++++++++++-------------
 gas/config/tc-kvx.c    |  3 +++
 gas/config/tc-kvx.h    | 10 +++++-----
 ld/Makefile.am         |  2 +-
 ld/Makefile.in         |  2 +-
 ld/configure.tgt       |  3 ++-
 12 files changed, 40 insertions(+), 41 deletions(-)

diff --git a/bfd/Makefile.am b/bfd/Makefile.am
index 8b0761db582..378c13198d6 100644
--- a/bfd/Makefile.am
+++ b/bfd/Makefile.am
@@ -318,7 +318,6 @@ BFD32_BACKENDS = \
 	elf32-i386.lo \
 	elf32-ip2k.lo \
 	elf32-iq2000.lo \
-	elf32-kvx.lo \
 	elf32-lm32.lo \
 	elf32-m32c.lo \
 	elf32-m32r.lo \
@@ -359,7 +358,6 @@ BFD32_BACKENDS = \
 	elf32-z80.lo \
 	elf32.lo \
 	elflink.lo \
-	elfxx-kvx.lo \
 	elfxx-sparc.lo \
 	elfxx-tilegx.lo \
 	elfxx-x86.lo \
@@ -495,7 +493,6 @@ BFD32_BACKENDS_CFILES = \
 	elf32-z80.c \
 	elf32.c \
 	elflink.c \
-	elfxx-kvx.c \
 	elfxx-sparc.c \
 	elfxx-tilegx.c \
 	elfxx-x86.c \
@@ -549,6 +546,7 @@ BFD64_BACKENDS = \
 	coff64-rs6000.lo \
 	elf32-aarch64.lo \
 	elf32-ia64.lo \
+	elf32-kvx.lo \
 	elf32-loongarch.lo \
 	elf32-mips.lo \
 	elf32-riscv.lo \
diff --git a/bfd/Makefile.in b/bfd/Makefile.in
index cca093e1fef..bb530271fca 100644
--- a/bfd/Makefile.in
+++ b/bfd/Makefile.in
@@ -774,7 +774,6 @@ BFD32_BACKENDS = \
 	elf32-i386.lo \
 	elf32-ip2k.lo \
 	elf32-iq2000.lo \
-	elf32-kvx.lo \
 	elf32-lm32.lo \
 	elf32-m32c.lo \
 	elf32-m32r.lo \
@@ -815,7 +814,6 @@ BFD32_BACKENDS = \
 	elf32-z80.lo \
 	elf32.lo \
 	elflink.lo \
-	elfxx-kvx.lo \
 	elfxx-sparc.lo \
 	elfxx-tilegx.lo \
 	elfxx-x86.lo \
@@ -951,7 +949,6 @@ BFD32_BACKENDS_CFILES = \
 	elf32-z80.c \
 	elf32.c \
 	elflink.c \
-	elfxx-kvx.c \
 	elfxx-sparc.c \
 	elfxx-tilegx.c \
 	elfxx-x86.c \
@@ -1006,6 +1003,7 @@ BFD64_BACKENDS = \
 	coff64-rs6000.lo \
 	elf32-aarch64.lo \
 	elf32-ia64.lo \
+	elf32-kvx.lo \
 	elf32-loongarch.lo \
 	elf32-mips.lo \
 	elf32-riscv.lo \
diff --git a/bfd/config.bfd b/bfd/config.bfd
index 30927bdbe23..2a4622219ba 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -804,14 +804,13 @@ case "${targ}" in
     targ_selvecs=kvx_elf32_vec
     want64=true
     ;;
-#endif
 
   kvx-*-*)
-    targ_defvec=kvx_elf32_vec
-#ifdef BFD64
-    targ64_selvecs=kvx_elf64_vec
-#endif
+    targ_defvec=kvx_elf64_vec
+    targ_selvecs="kvx_elf64_vec kvx_elf32_vec"
+    want64=true
     ;;
+#endif
 
   lm32-*-elf | lm32-*-rtems*)
     targ_defvec=lm32_elf32_vec
diff --git a/bfd/configure b/bfd/configure
index 489531c0a7f..d43754c4787 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -13960,8 +13960,8 @@ do
     ip2k_elf32_vec)		 tb="$tb elf32-ip2k.lo elf32.lo $elf" ;;
     iq2000_elf32_vec)		 tb="$tb elf32-iq2000.lo elf32.lo $elf" ;;
     kvx_elf32_vec)		 tb="$tb elf32-kvx.lo elfxx-kvx.lo elf32.lo $elf $ipa" ;;
-    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
-    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
+    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
+    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
     lm32_elf32_vec)		 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
     lm32_elf32_fdpic_vec)	 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
     loongarch_elf32_vec)	 tb="$tb elf32-loongarch.lo elfxx-loongarch.lo elf32.lo elf-ifunc.lo $elf" ;;
diff --git a/bfd/configure.ac b/bfd/configure.ac
index 0d1cd814af6..3fdd12fe22d 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -496,8 +496,8 @@ do
     ip2k_elf32_vec)		 tb="$tb elf32-ip2k.lo elf32.lo $elf" ;;
     iq2000_elf32_vec)		 tb="$tb elf32-iq2000.lo elf32.lo $elf" ;;
     kvx_elf32_vec)		 tb="$tb elf32-kvx.lo elfxx-kvx.lo elf32.lo $elf $ipa" ;;
-    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
-    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
+    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
+    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
     lm32_elf32_vec)		 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
     lm32_elf32_fdpic_vec)	 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
     loongarch_elf32_vec)	 tb="$tb elf32-loongarch.lo elfxx-loongarch.lo elf32.lo elf-ifunc.lo $elf" ;;
diff --git a/bfd/elfnn-kvx.c b/bfd/elfnn-kvx.c
index 77ff2483a28..a0a528ef9d2 100644
--- a/bfd/elfnn-kvx.c
+++ b/bfd/elfnn-kvx.c
@@ -740,7 +740,7 @@ elfNN_kvx_stub_name (const asection *input_section,
 	snprintf (stub_name, len, "%08x_%s+%" PRIx64 "x",
 		  (unsigned int) input_section->id,
 		  hash->root.root.root.string,
-		  rel->r_addend);
+		  (uint64_t) rel->r_addend);
     }
   else
     {
@@ -751,7 +751,7 @@ elfNN_kvx_stub_name (const asection *input_section,
 		  (unsigned int) input_section->id,
 		  (unsigned int) sym_sec->id,
 		  (unsigned int) ELFNN_R_SYM (rel->r_info),
-		  rel->r_addend);
+		  (uint64_t) rel->r_addend);
     }
 
   return stub_name;
@@ -2588,11 +2588,11 @@ elfNN_kvx_relocate_section (bfd *output_bfd,
 	  (*_bfd_error_handler)
 	    ((sym_type == STT_TLS
               /* xgettext:c-format */
-              ? _("%pB(%pA+%#lx): %s used with TLS symbol %s")
+              ? _("%pB(%pA+%#" PRIx64 "): %s used with TLS symbol %s")
               /* xgettext:c-format */
-              : _("%pB(%pA+%#lx): %s used with non-TLS symbol %s")),
+              : _("%pB(%pA+%#" PRIx64 "): %s used with non-TLS symbol %s")),
 	     input_bfd,
-	     input_section, (long) rel->r_offset, howto->name, name);
+	     input_section, (uint64_t) rel->r_offset, howto->name, name);
 	}
 
       /* Original aarch64 has relaxation handling for TLS here. */
diff --git a/gas/config/kvx-parse.c b/gas/config/kvx-parse.c
index ec3f912c476..c386d3eb66d 100644
--- a/gas/config/kvx-parse.c
+++ b/gas/config/kvx-parse.c
@@ -396,10 +396,10 @@ print_token (struct token_s token, char *buf, int bufsz)
     buf[i] = 0;
 }
 
-static long long
+static int64_t
 promote_token (struct token_s tok)
 {
-  long long cur_class = tok.class_id & -tok.class_id;
+  int64_t cur_class = tok.class_id & -tok.class_id;
   switch (tok.category)
     {
       case CAT_REGISTER:
@@ -414,8 +414,8 @@ promote_token (struct token_s tok)
 	  input_line_pointer = tok.insn + tok.begin;
 	  expression (&exp);
 	  input_line_pointer = ilp_save;
-	  long long new_class_id = tok.class_id;
-	  long long old_class_id = tok.class_id;
+	  int64_t new_class_id = tok.class_id;
+	  int64_t old_class_id = tok.class_id;
 	  while ((new_class_id = env.promote_immediate (old_class_id)) != old_class_id
 	      && ((exp.X_op == O_symbol && !has_relocation_of_size (str_hash_find (env.reloc_hash, TOKEN_NAME (new_class_id))))
 		|| (exp.X_op == 64 && !kvx_get_pseudo_func2 (exp.X_op_symbol, str_hash_find (env.reloc_hash, TOKEN_NAME (new_class_id))))))
@@ -443,7 +443,7 @@ is_insn (const struct token_s *token, struct token_class *classes)
   return res;
 }
 
-static long long
+static int64_t
 get_token_class (struct token_s *token, struct token_classes *classes, int insn_p, int modifier_p)
 {
   int cur = 0;
@@ -511,12 +511,12 @@ get_token_class (struct token_s *token, struct token_classes *classes, int insn_
 
   if (class == classes->imm_classes)
     {
-      unsigned long long uval = token_val_p
+      uint64_t uval = token_val_p
 	? token->val
 	: strtoull (tok + (tok[0] == '-') + (tok[0] == '+'), NULL, 0);
-      long long val = uval;
-      long long pval = val < 0 ? -val : val;
-      int neg_power2_p = val < 0 && !(pval & (pval - 1));
+      uint64_t sign_bit = ((~0ULL >> 1) ^ ~0ULL);
+      int64_t pval = sign_bit & uval ? 1 + (~0ULL >> 1) - (~sign_bit & uval) : (~sign_bit & uval);
+      int neg_power2_p = (sign_bit & uval) && !(pval & (pval - 1));
       unsigned int len = 8 * sizeof (pval) - __builtin_clzll (pval);
       for (; class[cur].class_id != -1
 	  && ((unsigned int) (class[cur].sz < 0 ? - class[cur].sz - !neg_power2_p : class[cur].sz) < len
@@ -652,11 +652,11 @@ print_token_list (struct token_list *lst)
   struct token_list *cur = lst;
   while (cur)
     {
-      printf_debug (1, "%s (%d : %s : %d) / ",
+      printf_debug (0, "%s (%lld : %s : %d) / ",
 	      cur->tok, cur->val, TOKEN_NAME (cur->class_id), cur->loc);
       cur = cur->next;
     }
-  printf_debug (1, "\n");
+  printf_debug (0, "\n");
 }
 
 void
@@ -804,7 +804,7 @@ retry:;
     parse_with_restarts (tok, cur_rule[i].jump_target, rules, errs);
   /* While parsing fails but there is hope since the current token can be
      promoted.  */
-  while (!fst_part && tok.class_id != (long long) promote_token (tok))
+  while (!fst_part && tok.class_id != (int64_t) promote_token (tok))
     {
       free_token_list (fst_part);
       tok.class_id = promote_token (tok);
@@ -854,7 +854,7 @@ retry:;
 
   printf_debug (1, "snd_part: Trying to match: %s\n", TOKEN_NAME (CLASS_ID (tok)));
   struct token_list *snd_part = parse_with_restarts (tok, cur_rule[i].stack_it, rules, errs);
-  while (!snd_part && tok.class_id != (long long) promote_token (tok))
+  while (!snd_part && tok.class_id != (int64_t) promote_token (tok))
     {
       tok.class_id = promote_token (tok);
       printf_debug (1, ">> Restart with %s?\n", TOKEN_NAME (CLASS_ID (tok)));
diff --git a/gas/config/tc-kvx.c b/gas/config/tc-kvx.c
index 3cf6b27976d..00aec6c858e 100644
--- a/gas/config/tc-kvx.c
+++ b/gas/config/tc-kvx.c
@@ -1419,6 +1419,9 @@ kvx_set_cpu (void)
   if (env.params.core == -1)
       env.params.core = kvx_core_info->elf_core;
 
+  if (!strcmp (TARGET_OS, "linux-gnu"))
+      env.params.osabi = ELFOSABI_GNU;
+
   int kvx_bfd_mach;
   print_insn = kvx_print_insn;
 
diff --git a/gas/config/tc-kvx.h b/gas/config/tc-kvx.h
index 11787bf0532..f8587540ca5 100644
--- a/gas/config/tc-kvx.h
+++ b/gas/config/tc-kvx.h
@@ -43,15 +43,15 @@ struct token_s {
   char *insn;
   int begin, end;
   int category;
-  long long class_id;
-  unsigned long long val;
+  int64_t class_id;
+  uint64_t val;
 };
 
 struct token_list
 {
   char *tok;
-  unsigned long long val;
-  long long class_id;
+  uint64_t val;
+  int64_t class_id;
   int category;
   int loc;
   struct token_list *next;
@@ -61,7 +61,7 @@ struct token_list
 
 struct token_class {
   const char ** class_values;
-  long long class_id;
+  int64_t class_id;
   int sz;
 };
 
diff --git a/ld/Makefile.am b/ld/Makefile.am
index 07fac968bb7..be456275748 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -237,7 +237,6 @@ ALL_EMULATION_SOURCES = \
 	eelf32ip2k.c \
 	eelf32iq10.c \
 	eelf32iq2000.c \
-	eelf32kvx.c \
 	eelf32lm32.c \
 	eelf32lm32fd.c \
 	eelf32lppc.c \
@@ -408,6 +407,7 @@ ALL_64_EMULATION_SOURCES = \
 	eelf32ebmipvxworks.c \
 	eelf32elmip.c \
 	eelf32elmipvxworks.c \
+	eelf32kvx.c \
 	eelf32l4300.c \
 	eelf32lmip.c \
 	eelf32loongarch.c \
diff --git a/ld/Makefile.in b/ld/Makefile.in
index a2aa54b69d8..c6a79774f38 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -738,7 +738,6 @@ ALL_EMULATION_SOURCES = \
 	eelf32ip2k.c \
 	eelf32iq10.c \
 	eelf32iq2000.c \
-	eelf32kvx.c \
 	eelf32lm32.c \
 	eelf32lm32fd.c \
 	eelf32lppc.c \
@@ -908,6 +907,7 @@ ALL_64_EMULATION_SOURCES = \
 	eelf32ebmipvxworks.c \
 	eelf32elmip.c \
 	eelf32elmipvxworks.c \
+	eelf32kvx.c \
 	eelf32l4300.c \
 	eelf32lmip.c \
 	eelf32loongarch.c \
diff --git a/ld/configure.tgt b/ld/configure.tgt
index f78ba07e5ca..ff0aaaae257 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -476,7 +476,8 @@ lm32-*-*)		targ_emul=elf32lm32
 kvx-*-linux*)		targ_emul=elf64kvx_linux
 			targ_extra_emuls="elf64kvx"
 			;;
-kvx-*-*)		targ_emul=elf64kvx; targ_extra_emuls="elf64kvx_linux elf32kvx"
+kvx-*-*)		targ_emul=elf64kvx;
+			targ_extra_emuls="elf64kvx_linux elf32kvx"
 			;;
 m32c-*-elf)
 			targ_emul=elf32m32c
-- 
2.35.1.500.gb896f729e2


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] kvx: fix 32-bit build and validation
  2023-08-22 16:01 [PATCH] kvx: fix 32-bit build and validation Paul Iannetta
@ 2023-08-23  0:27 ` Alan Modra
  2023-08-23  7:44   ` Paul Iannetta
  2023-08-23  3:16 ` Alan Modra
  1 sibling, 1 reply; 19+ messages in thread
From: Alan Modra @ 2023-08-23  0:27 UTC (permalink / raw)
  To: Paul Iannetta; +Cc: binutils

On Tue, Aug 22, 2023 at 06:01:42PM +0200, Paul Iannetta via Binutils wrote:
>    kvx-*-*)
> -    targ_defvec=kvx_elf32_vec
> -#ifdef BFD64
> -    targ64_selvecs=kvx_elf64_vec
> -#endif
> +    targ_defvec=kvx_elf64_vec
> +    targ_selvecs="kvx_elf64_vec kvx_elf32_vec"
> +    want64=true

It isn't necessary to put kvx_elf64_vec into targ_selvecs, but doesn't
hurt.  I mention this only because..

> -    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
> -    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
> +    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
> +    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;

..I don't see kvx_elf64_linux_vec defined anywhere.  Delete it?

>    if (class == classes->imm_classes)
>      {
> -      unsigned long long uval = token_val_p
> +      uint64_t uval = token_val_p
>  	? token->val
>  	: strtoull (tok + (tok[0] == '-') + (tok[0] == '+'), NULL, 0);
> -      long long val = uval;
> -      long long pval = val < 0 ? -val : val;
> -      int neg_power2_p = val < 0 && !(pval & (pval - 1));
> +      uint64_t sign_bit = ((~0ULL >> 1) ^ ~0ULL);
> +      int64_t pval = sign_bit & uval ? 1 + (~0ULL >> 1) - (~sign_bit & uval) : (~sign_bit & uval);
> +      int neg_power2_p = (sign_bit & uval) && !(pval & (pval - 1));
>        unsigned int len = 8 * sizeof (pval) - __builtin_clzll (pval);
>        for (; class[cur].class_id != -1
>  	  && ((unsigned int) (class[cur].sz < 0 ? - class[cur].sz - !neg_power2_p : class[cur].sz) < len

I'm about to commit a patch I wrote yesterday that fixes ubsan
warnings in the above, which will make this change unnecessary (except
of course you might like to make the variables {u,}int64_t).  The
expressions you're using for sign_bit and pval to avoid signed integer
overflow will no doubt work (unless unsigned long long is larger than
uint64_t!), but are more complicated than the following.

 int64_t val = uval;
 int64_t pval = val < 0 ? -uval : uval;
 int neg_power2_p = val < 0 && !(uval & (uval - 1));

> index 3cf6b27976d..00aec6c858e 100644
> --- a/gas/config/tc-kvx.c
> +++ b/gas/config/tc-kvx.c
> @@ -1419,6 +1419,9 @@ kvx_set_cpu (void)
>    if (env.params.core == -1)
>        env.params.core = kvx_core_info->elf_core;
>  
> +  if (!strcmp (TARGET_OS, "linux-gnu"))
> +      env.params.osabi = ELFOSABI_GNU;
> +
>    int kvx_bfd_mach;
>    print_insn = kvx_print_insn;
>  

Do you really need this?  Other targets automatically use ELFOSABI_GNU
when the ELF bfd code detects known ABI extensions.  See
has_gnu_osabi.  Hmm, likely you shouldn't be setting e_ident in
tc-kvx.c:kvx_end.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] kvx: fix 32-bit build and validation
  2023-08-22 16:01 [PATCH] kvx: fix 32-bit build and validation Paul Iannetta
  2023-08-23  0:27 ` Alan Modra
@ 2023-08-23  3:16 ` Alan Modra
  2023-08-23 13:39   ` Luis Machado
  1 sibling, 1 reply; 19+ messages in thread
From: Alan Modra @ 2023-08-23  3:16 UTC (permalink / raw)
  To: Paul Iannetta; +Cc: binutils

I've committed this part of your patch, with a small fix to targets.c
needed to get a successful 32-bit host --enable-targets=all build.

bfd/
	* Makefile.am: Move elf32-kvx.lo from BFD32_BACKENDS to
	BFD64_BACKENDS.  Remove elfxx-kvx.lo from BFD32_BACKENDS.
	Remove elfxx-kvx.c from BFD32_BACKENDS_CFILES.
	* Makefile.in: Regenerate.
	* config.bfd: Adjust targ_defvec and targ_selvecs and gate them
	behind BFD64.
	* configure.ac: Add target_size=64 to kvx_elf64_*vec.
	* configure: Regenerate.
	* elfnn-kvx.c (elfNN_kvx_stub_name): Cast rel->r_addend to
	uint64_t to match format string.
	(elfNN_kvx_relocate_section): Similarly for r_offset, and
	use PRIx64 in format string.
	* targets.c (_bfd_target_vector <kvx_elf32_vec>): Move inside
	#ifdef BFD64.
ld/
	* Makefile.am: Move eelf32kvx.c from ALL_EMULATION_SOURCES to
	ALL_64_EMULATION_SOURCES.
	* Makefile.in: Regenerate.

diff --git a/bfd/Makefile.am b/bfd/Makefile.am
index 8b0761db582..378c13198d6 100644
--- a/bfd/Makefile.am
+++ b/bfd/Makefile.am
@@ -318,7 +318,6 @@ BFD32_BACKENDS = \
 	elf32-i386.lo \
 	elf32-ip2k.lo \
 	elf32-iq2000.lo \
-	elf32-kvx.lo \
 	elf32-lm32.lo \
 	elf32-m32c.lo \
 	elf32-m32r.lo \
@@ -359,7 +358,6 @@ BFD32_BACKENDS = \
 	elf32-z80.lo \
 	elf32.lo \
 	elflink.lo \
-	elfxx-kvx.lo \
 	elfxx-sparc.lo \
 	elfxx-tilegx.lo \
 	elfxx-x86.lo \
@@ -495,7 +493,6 @@ BFD32_BACKENDS_CFILES = \
 	elf32-z80.c \
 	elf32.c \
 	elflink.c \
-	elfxx-kvx.c \
 	elfxx-sparc.c \
 	elfxx-tilegx.c \
 	elfxx-x86.c \
@@ -549,6 +546,7 @@ BFD64_BACKENDS = \
 	coff64-rs6000.lo \
 	elf32-aarch64.lo \
 	elf32-ia64.lo \
+	elf32-kvx.lo \
 	elf32-loongarch.lo \
 	elf32-mips.lo \
 	elf32-riscv.lo \
diff --git a/bfd/Makefile.in b/bfd/Makefile.in
index cca093e1fef..bb530271fca 100644
--- a/bfd/Makefile.in
+++ b/bfd/Makefile.in
@@ -774,7 +774,6 @@ BFD32_BACKENDS = \
 	elf32-i386.lo \
 	elf32-ip2k.lo \
 	elf32-iq2000.lo \
-	elf32-kvx.lo \
 	elf32-lm32.lo \
 	elf32-m32c.lo \
 	elf32-m32r.lo \
@@ -815,7 +814,6 @@ BFD32_BACKENDS = \
 	elf32-z80.lo \
 	elf32.lo \
 	elflink.lo \
-	elfxx-kvx.lo \
 	elfxx-sparc.lo \
 	elfxx-tilegx.lo \
 	elfxx-x86.lo \
@@ -951,7 +949,6 @@ BFD32_BACKENDS_CFILES = \
 	elf32-z80.c \
 	elf32.c \
 	elflink.c \
-	elfxx-kvx.c \
 	elfxx-sparc.c \
 	elfxx-tilegx.c \
 	elfxx-x86.c \
@@ -1006,6 +1003,7 @@ BFD64_BACKENDS = \
 	coff64-rs6000.lo \
 	elf32-aarch64.lo \
 	elf32-ia64.lo \
+	elf32-kvx.lo \
 	elf32-loongarch.lo \
 	elf32-mips.lo \
 	elf32-riscv.lo \
diff --git a/bfd/config.bfd b/bfd/config.bfd
index 30927bdbe23..2a4622219ba 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -804,14 +804,13 @@ case "${targ}" in
     targ_selvecs=kvx_elf32_vec
     want64=true
     ;;
-#endif
 
   kvx-*-*)
-    targ_defvec=kvx_elf32_vec
-#ifdef BFD64
-    targ64_selvecs=kvx_elf64_vec
-#endif
+    targ_defvec=kvx_elf64_vec
+    targ_selvecs="kvx_elf64_vec kvx_elf32_vec"
+    want64=true
     ;;
+#endif
 
   lm32-*-elf | lm32-*-rtems*)
     targ_defvec=lm32_elf32_vec
diff --git a/bfd/configure b/bfd/configure
index 489531c0a7f..d43754c4787 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -13960,8 +13960,8 @@ do
     ip2k_elf32_vec)		 tb="$tb elf32-ip2k.lo elf32.lo $elf" ;;
     iq2000_elf32_vec)		 tb="$tb elf32-iq2000.lo elf32.lo $elf" ;;
     kvx_elf32_vec)		 tb="$tb elf32-kvx.lo elfxx-kvx.lo elf32.lo $elf $ipa" ;;
-    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
-    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
+    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
+    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
     lm32_elf32_vec)		 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
     lm32_elf32_fdpic_vec)	 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
     loongarch_elf32_vec)	 tb="$tb elf32-loongarch.lo elfxx-loongarch.lo elf32.lo elf-ifunc.lo $elf" ;;
diff --git a/bfd/configure.ac b/bfd/configure.ac
index 0d1cd814af6..3fdd12fe22d 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -496,8 +496,8 @@ do
     ip2k_elf32_vec)		 tb="$tb elf32-ip2k.lo elf32.lo $elf" ;;
     iq2000_elf32_vec)		 tb="$tb elf32-iq2000.lo elf32.lo $elf" ;;
     kvx_elf32_vec)		 tb="$tb elf32-kvx.lo elfxx-kvx.lo elf32.lo $elf $ipa" ;;
-    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
-    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
+    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
+    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
     lm32_elf32_vec)		 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
     lm32_elf32_fdpic_vec)	 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
     loongarch_elf32_vec)	 tb="$tb elf32-loongarch.lo elfxx-loongarch.lo elf32.lo elf-ifunc.lo $elf" ;;
diff --git a/bfd/elfnn-kvx.c b/bfd/elfnn-kvx.c
index 467d91fea53..95580d19930 100644
--- a/bfd/elfnn-kvx.c
+++ b/bfd/elfnn-kvx.c
@@ -736,7 +736,7 @@ elfNN_kvx_stub_name (const asection *input_section,
 	snprintf (stub_name, len, "%08x_%s+%" PRIx64 "x",
 		  (unsigned int) input_section->id,
 		  hash->root.root.root.string,
-		  rel->r_addend);
+		  (uint64_t) rel->r_addend);
     }
   else
     {
@@ -747,7 +747,7 @@ elfNN_kvx_stub_name (const asection *input_section,
 		  (unsigned int) input_section->id,
 		  (unsigned int) sym_sec->id,
 		  (unsigned int) ELFNN_R_SYM (rel->r_info),
-		  rel->r_addend);
+		  (uint64_t) rel->r_addend);
     }
 
   return stub_name;
@@ -2568,11 +2568,11 @@ elfNN_kvx_relocate_section (bfd *output_bfd,
 	  (*_bfd_error_handler)
 	    ((sym_type == STT_TLS
 	      /* xgettext:c-format */
-	      ? _("%pB(%pA+%#lx): %s used with TLS symbol %s")
+	      ? _("%pB(%pA+%#" PRIx64 "): %s used with TLS symbol %s")
 	      /* xgettext:c-format */
-	      : _("%pB(%pA+%#lx): %s used with non-TLS symbol %s")),
+	      : _("%pB(%pA+%#" PRIx64 "): %s used with non-TLS symbol %s")),
 	     input_bfd,
-	     input_section, (long) rel->r_offset, howto->name, name);
+	     input_section, (uint64_t) rel->r_offset, howto->name, name);
 	}
 
       /* Original aarch64 has relaxation handling for TLS here. */
diff --git a/bfd/targets.c b/bfd/targets.c
index 210beddaf11..63b3abbd287 100644
--- a/bfd/targets.c
+++ b/bfd/targets.c
@@ -1130,9 +1130,8 @@ static const bfd_target * const _bfd_target_vector[] =
 	&ip2k_elf32_vec,
 	&iq2000_elf32_vec,
 
-	&kvx_elf32_vec,
-
 #ifdef BFD64
+	&kvx_elf32_vec,
 	&kvx_elf64_vec,
 #endif
 
diff --git a/ld/Makefile.am b/ld/Makefile.am
index 07fac968bb7..be456275748 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -237,7 +237,6 @@ ALL_EMULATION_SOURCES = \
 	eelf32ip2k.c \
 	eelf32iq10.c \
 	eelf32iq2000.c \
-	eelf32kvx.c \
 	eelf32lm32.c \
 	eelf32lm32fd.c \
 	eelf32lppc.c \
@@ -408,6 +407,7 @@ ALL_64_EMULATION_SOURCES = \
 	eelf32ebmipvxworks.c \
 	eelf32elmip.c \
 	eelf32elmipvxworks.c \
+	eelf32kvx.c \
 	eelf32l4300.c \
 	eelf32lmip.c \
 	eelf32loongarch.c \
diff --git a/ld/Makefile.in b/ld/Makefile.in
index a2aa54b69d8..c6a79774f38 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -738,7 +738,6 @@ ALL_EMULATION_SOURCES = \
 	eelf32ip2k.c \
 	eelf32iq10.c \
 	eelf32iq2000.c \
-	eelf32kvx.c \
 	eelf32lm32.c \
 	eelf32lm32fd.c \
 	eelf32lppc.c \
@@ -908,6 +907,7 @@ ALL_64_EMULATION_SOURCES = \
 	eelf32ebmipvxworks.c \
 	eelf32elmip.c \
 	eelf32elmipvxworks.c \
+	eelf32kvx.c \
 	eelf32l4300.c \
 	eelf32lmip.c \
 	eelf32loongarch.c \

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] kvx: fix 32-bit build and validation
  2023-08-23  0:27 ` Alan Modra
@ 2023-08-23  7:44   ` Paul Iannetta
  2023-08-23 12:14     ` Alan Modra
  0 siblings, 1 reply; 19+ messages in thread
From: Paul Iannetta @ 2023-08-23  7:44 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

Thank you very much for your comments!

On Wed, Aug 23, 2023 at 09:57:26AM +0930, Alan Modra wrote:
> On Tue, Aug 22, 2023 at 06:01:42PM +0200, Paul Iannetta via Binutils wrote:
> >    kvx-*-*)
> > -    targ_defvec=kvx_elf32_vec
> > -#ifdef BFD64
> > -    targ64_selvecs=kvx_elf64_vec
> > -#endif
> > +    targ_defvec=kvx_elf64_vec
> > +    targ_selvecs="kvx_elf64_vec kvx_elf32_vec"
> > +    want64=true
> 
> It isn't necessary to put kvx_elf64_vec into targ_selvecs, but doesn't
> hurt.  I mention this only because..

I'll remove it then.

> 
> > -    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
> > -    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
> > +    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
> > +    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
> 
> ..I don't see kvx_elf64_linux_vec defined anywhere.  Delete it?

Indeed, it somehow got missing from bfd/targets.c, it is mostly
similar to kvx_elf64_vec, and only exists to match what is done in the
linker with the emulation elf64kvx_linux.

> 
> >    if (class == classes->imm_classes)
> >      {
> > -      unsigned long long uval = token_val_p
> > +      uint64_t uval = token_val_p
> >  	? token->val
> >  	: strtoull (tok + (tok[0] == '-') + (tok[0] == '+'), NULL, 0);
> > -      long long val = uval;
> > -      long long pval = val < 0 ? -val : val;
> > -      int neg_power2_p = val < 0 && !(pval & (pval - 1));
> > +      uint64_t sign_bit = ((~0ULL >> 1) ^ ~0ULL);
> > +      int64_t pval = sign_bit & uval ? 1 + (~0ULL >> 1) - (~sign_bit & uval) : (~sign_bit & uval);
> > +      int neg_power2_p = (sign_bit & uval) && !(pval & (pval - 1));
> >        unsigned int len = 8 * sizeof (pval) - __builtin_clzll (pval);
> >        for (; class[cur].class_id != -1
> >  	  && ((unsigned int) (class[cur].sz < 0 ? - class[cur].sz - !neg_power2_p : class[cur].sz) < len
> 
> I'm about to commit a patch I wrote yesterday that fixes ubsan
> warnings in the above, which will make this change unnecessary (except
> of course you might like to make the variables {u,}int64_t).  The
> expressions you're using for sign_bit and pval to avoid signed integer
> overflow will no doubt work (unless unsigned long long is larger than
> uint64_t!), but are more complicated than the following.
> 
>  int64_t val = uval;
>  int64_t pval = val < 0 ? -uval : uval;
>  int neg_power2_p = val < 0 && !(uval & (uval - 1));

Thanks, I'll much prefer keeping something readable.

> 
> > index 3cf6b27976d..00aec6c858e 100644
> > --- a/gas/config/tc-kvx.c
> > +++ b/gas/config/tc-kvx.c
> > @@ -1419,6 +1419,9 @@ kvx_set_cpu (void)
> >    if (env.params.core == -1)
> >        env.params.core = kvx_core_info->elf_core;
> >  
> > +  if (!strcmp (TARGET_OS, "linux-gnu"))
> > +      env.params.osabi = ELFOSABI_GNU;
> > +
> >    int kvx_bfd_mach;
> >    print_insn = kvx_print_insn;
> >  
> 
> Do you really need this?  Other targets automatically use ELFOSABI_GNU
> when the ELF bfd code detects known ABI extensions.  See
> has_gnu_osabi.  Hmm, likely you shouldn't be setting e_ident in
> tc-kvx.c:kvx_end.

I thought I needed this because we may emit STB_GNU_UNIQUE symbols but
I was not aware of the fact that has_gnu_osabi updates itself
depending on the features used.  I'll fix that part accordingly.

Thanks,
Paul






^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] kvx: fix 32-bit build and validation
  2023-08-23  7:44   ` Paul Iannetta
@ 2023-08-23 12:14     ` Alan Modra
  2023-08-23 14:39       ` [PATCH 0/4] kvx: various fixes Paul Iannetta
  2023-08-23 14:40       ` [PATCH] kvx: fix 32-bit build and validation Paul Iannetta
  0 siblings, 2 replies; 19+ messages in thread
From: Alan Modra @ 2023-08-23 12:14 UTC (permalink / raw)
  To: Paul Iannetta; +Cc: binutils

On Wed, Aug 23, 2023 at 09:44:25AM +0200, Paul Iannetta wrote:
> On Wed, Aug 23, 2023 at 09:57:26AM +0930, Alan Modra wrote:
> > ..I don't see kvx_elf64_linux_vec defined anywhere.  Delete it?
> 
> Indeed, it somehow got missing from bfd/targets.c, it is mostly
> similar to kvx_elf64_vec, and only exists to match what is done in the
> linker with the emulation elf64kvx_linux.

Unless you really need it, don't add it.  If you have two target
vectors that match kvx objects then people will run into "file format
is ambiguous" errors when attempting to use any of objdump, objcopy,
nm etc. on a kvx object.  You won't see that if you've built binutils
with one of the kvx targets as the default, but will if you've built
say --target=x86_64-linux-gnu --enable-targets=all.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] kvx: fix 32-bit build and validation
  2023-08-23  3:16 ` Alan Modra
@ 2023-08-23 13:39   ` Luis Machado
  0 siblings, 0 replies; 19+ messages in thread
From: Luis Machado @ 2023-08-23 13:39 UTC (permalink / raw)
  To: Alan Modra, Paul Iannetta; +Cc: binutils

Thanks for pushing this Alan.

On 8/23/23 04:16, Alan Modra via Binutils wrote:
> I've committed this part of your patch, with a small fix to targets.c
> needed to get a successful 32-bit host --enable-targets=all build.
> 
> bfd/
> 	* Makefile.am: Move elf32-kvx.lo from BFD32_BACKENDS to
> 	BFD64_BACKENDS.  Remove elfxx-kvx.lo from BFD32_BACKENDS.
> 	Remove elfxx-kvx.c from BFD32_BACKENDS_CFILES.
> 	* Makefile.in: Regenerate.
> 	* config.bfd: Adjust targ_defvec and targ_selvecs and gate them
> 	behind BFD64.
> 	* configure.ac: Add target_size=64 to kvx_elf64_*vec.
> 	* configure: Regenerate.
> 	* elfnn-kvx.c (elfNN_kvx_stub_name): Cast rel->r_addend to
> 	uint64_t to match format string.
> 	(elfNN_kvx_relocate_section): Similarly for r_offset, and
> 	use PRIx64 in format string.
> 	* targets.c (_bfd_target_vector <kvx_elf32_vec>): Move inside
> 	#ifdef BFD64.
> ld/
> 	* Makefile.am: Move eelf32kvx.c from ALL_EMULATION_SOURCES to
> 	ALL_64_EMULATION_SOURCES.
> 	* Makefile.in: Regenerate.
> 
> diff --git a/bfd/Makefile.am b/bfd/Makefile.am
> index 8b0761db582..378c13198d6 100644
> --- a/bfd/Makefile.am
> +++ b/bfd/Makefile.am
> @@ -318,7 +318,6 @@ BFD32_BACKENDS = \
>  	elf32-i386.lo \
>  	elf32-ip2k.lo \
>  	elf32-iq2000.lo \
> -	elf32-kvx.lo \
>  	elf32-lm32.lo \
>  	elf32-m32c.lo \
>  	elf32-m32r.lo \
> @@ -359,7 +358,6 @@ BFD32_BACKENDS = \
>  	elf32-z80.lo \
>  	elf32.lo \
>  	elflink.lo \
> -	elfxx-kvx.lo \
>  	elfxx-sparc.lo \
>  	elfxx-tilegx.lo \
>  	elfxx-x86.lo \
> @@ -495,7 +493,6 @@ BFD32_BACKENDS_CFILES = \
>  	elf32-z80.c \
>  	elf32.c \
>  	elflink.c \
> -	elfxx-kvx.c \
>  	elfxx-sparc.c \
>  	elfxx-tilegx.c \
>  	elfxx-x86.c \
> @@ -549,6 +546,7 @@ BFD64_BACKENDS = \
>  	coff64-rs6000.lo \
>  	elf32-aarch64.lo \
>  	elf32-ia64.lo \
> +	elf32-kvx.lo \
>  	elf32-loongarch.lo \
>  	elf32-mips.lo \
>  	elf32-riscv.lo \
> diff --git a/bfd/Makefile.in b/bfd/Makefile.in
> index cca093e1fef..bb530271fca 100644
> --- a/bfd/Makefile.in
> +++ b/bfd/Makefile.in
> @@ -774,7 +774,6 @@ BFD32_BACKENDS = \
>  	elf32-i386.lo \
>  	elf32-ip2k.lo \
>  	elf32-iq2000.lo \
> -	elf32-kvx.lo \
>  	elf32-lm32.lo \
>  	elf32-m32c.lo \
>  	elf32-m32r.lo \
> @@ -815,7 +814,6 @@ BFD32_BACKENDS = \
>  	elf32-z80.lo \
>  	elf32.lo \
>  	elflink.lo \
> -	elfxx-kvx.lo \
>  	elfxx-sparc.lo \
>  	elfxx-tilegx.lo \
>  	elfxx-x86.lo \
> @@ -951,7 +949,6 @@ BFD32_BACKENDS_CFILES = \
>  	elf32-z80.c \
>  	elf32.c \
>  	elflink.c \
> -	elfxx-kvx.c \
>  	elfxx-sparc.c \
>  	elfxx-tilegx.c \
>  	elfxx-x86.c \
> @@ -1006,6 +1003,7 @@ BFD64_BACKENDS = \
>  	coff64-rs6000.lo \
>  	elf32-aarch64.lo \
>  	elf32-ia64.lo \
> +	elf32-kvx.lo \
>  	elf32-loongarch.lo \
>  	elf32-mips.lo \
>  	elf32-riscv.lo \
> diff --git a/bfd/config.bfd b/bfd/config.bfd
> index 30927bdbe23..2a4622219ba 100644
> --- a/bfd/config.bfd
> +++ b/bfd/config.bfd
> @@ -804,14 +804,13 @@ case "${targ}" in
>      targ_selvecs=kvx_elf32_vec
>      want64=true
>      ;;
> -#endif
>  
>    kvx-*-*)
> -    targ_defvec=kvx_elf32_vec
> -#ifdef BFD64
> -    targ64_selvecs=kvx_elf64_vec
> -#endif
> +    targ_defvec=kvx_elf64_vec
> +    targ_selvecs="kvx_elf64_vec kvx_elf32_vec"
> +    want64=true
>      ;;
> +#endif
>  
>    lm32-*-elf | lm32-*-rtems*)
>      targ_defvec=lm32_elf32_vec
> diff --git a/bfd/configure b/bfd/configure
> index 489531c0a7f..d43754c4787 100755
> --- a/bfd/configure
> +++ b/bfd/configure
> @@ -13960,8 +13960,8 @@ do
>      ip2k_elf32_vec)		 tb="$tb elf32-ip2k.lo elf32.lo $elf" ;;
>      iq2000_elf32_vec)		 tb="$tb elf32-iq2000.lo elf32.lo $elf" ;;
>      kvx_elf32_vec)		 tb="$tb elf32-kvx.lo elfxx-kvx.lo elf32.lo $elf $ipa" ;;
> -    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
> -    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
> +    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
> +    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
>      lm32_elf32_vec)		 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
>      lm32_elf32_fdpic_vec)	 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
>      loongarch_elf32_vec)	 tb="$tb elf32-loongarch.lo elfxx-loongarch.lo elf32.lo elf-ifunc.lo $elf" ;;
> diff --git a/bfd/configure.ac b/bfd/configure.ac
> index 0d1cd814af6..3fdd12fe22d 100644
> --- a/bfd/configure.ac
> +++ b/bfd/configure.ac
> @@ -496,8 +496,8 @@ do
>      ip2k_elf32_vec)		 tb="$tb elf32-ip2k.lo elf32.lo $elf" ;;
>      iq2000_elf32_vec)		 tb="$tb elf32-iq2000.lo elf32.lo $elf" ;;
>      kvx_elf32_vec)		 tb="$tb elf32-kvx.lo elfxx-kvx.lo elf32.lo $elf $ipa" ;;
> -    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
> -    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
> +    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
> +    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
>      lm32_elf32_vec)		 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
>      lm32_elf32_fdpic_vec)	 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
>      loongarch_elf32_vec)	 tb="$tb elf32-loongarch.lo elfxx-loongarch.lo elf32.lo elf-ifunc.lo $elf" ;;
> diff --git a/bfd/elfnn-kvx.c b/bfd/elfnn-kvx.c
> index 467d91fea53..95580d19930 100644
> --- a/bfd/elfnn-kvx.c
> +++ b/bfd/elfnn-kvx.c
> @@ -736,7 +736,7 @@ elfNN_kvx_stub_name (const asection *input_section,
>  	snprintf (stub_name, len, "%08x_%s+%" PRIx64 "x",
>  		  (unsigned int) input_section->id,
>  		  hash->root.root.root.string,
> -		  rel->r_addend);
> +		  (uint64_t) rel->r_addend);
>      }
>    else
>      {
> @@ -747,7 +747,7 @@ elfNN_kvx_stub_name (const asection *input_section,
>  		  (unsigned int) input_section->id,
>  		  (unsigned int) sym_sec->id,
>  		  (unsigned int) ELFNN_R_SYM (rel->r_info),
> -		  rel->r_addend);
> +		  (uint64_t) rel->r_addend);
>      }
>  
>    return stub_name;
> @@ -2568,11 +2568,11 @@ elfNN_kvx_relocate_section (bfd *output_bfd,
>  	  (*_bfd_error_handler)
>  	    ((sym_type == STT_TLS
>  	      /* xgettext:c-format */
> -	      ? _("%pB(%pA+%#lx): %s used with TLS symbol %s")
> +	      ? _("%pB(%pA+%#" PRIx64 "): %s used with TLS symbol %s")
>  	      /* xgettext:c-format */
> -	      : _("%pB(%pA+%#lx): %s used with non-TLS symbol %s")),
> +	      : _("%pB(%pA+%#" PRIx64 "): %s used with non-TLS symbol %s")),
>  	     input_bfd,
> -	     input_section, (long) rel->r_offset, howto->name, name);
> +	     input_section, (uint64_t) rel->r_offset, howto->name, name);
>  	}
>  
>        /* Original aarch64 has relaxation handling for TLS here. */
> diff --git a/bfd/targets.c b/bfd/targets.c
> index 210beddaf11..63b3abbd287 100644
> --- a/bfd/targets.c
> +++ b/bfd/targets.c
> @@ -1130,9 +1130,8 @@ static const bfd_target * const _bfd_target_vector[] =
>  	&ip2k_elf32_vec,
>  	&iq2000_elf32_vec,
>  
> -	&kvx_elf32_vec,
> -
>  #ifdef BFD64
> +	&kvx_elf32_vec,
>  	&kvx_elf64_vec,
>  #endif
>  
> diff --git a/ld/Makefile.am b/ld/Makefile.am
> index 07fac968bb7..be456275748 100644
> --- a/ld/Makefile.am
> +++ b/ld/Makefile.am
> @@ -237,7 +237,6 @@ ALL_EMULATION_SOURCES = \
>  	eelf32ip2k.c \
>  	eelf32iq10.c \
>  	eelf32iq2000.c \
> -	eelf32kvx.c \
>  	eelf32lm32.c \
>  	eelf32lm32fd.c \
>  	eelf32lppc.c \
> @@ -408,6 +407,7 @@ ALL_64_EMULATION_SOURCES = \
>  	eelf32ebmipvxworks.c \
>  	eelf32elmip.c \
>  	eelf32elmipvxworks.c \
> +	eelf32kvx.c \
>  	eelf32l4300.c \
>  	eelf32lmip.c \
>  	eelf32loongarch.c \
> diff --git a/ld/Makefile.in b/ld/Makefile.in
> index a2aa54b69d8..c6a79774f38 100644
> --- a/ld/Makefile.in
> +++ b/ld/Makefile.in
> @@ -738,7 +738,6 @@ ALL_EMULATION_SOURCES = \
>  	eelf32ip2k.c \
>  	eelf32iq10.c \
>  	eelf32iq2000.c \
> -	eelf32kvx.c \
>  	eelf32lm32.c \
>  	eelf32lm32fd.c \
>  	eelf32lppc.c \
> @@ -908,6 +907,7 @@ ALL_64_EMULATION_SOURCES = \
>  	eelf32ebmipvxworks.c \
>  	eelf32elmip.c \
>  	eelf32elmipvxworks.c \
> +	eelf32kvx.c \
>  	eelf32l4300.c \
>  	eelf32lmip.c \
>  	eelf32loongarch.c \
> 


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 0/4] kvx: various fixes
  2023-08-23 12:14     ` Alan Modra
@ 2023-08-23 14:39       ` Paul Iannetta
  2023-08-23 14:39         ` [PATCH 1/4] kvx: remove kvx_elf64_linux_vec Paul Iannetta
                           ` (4 more replies)
  2023-08-23 14:40       ` [PATCH] kvx: fix 32-bit build and validation Paul Iannetta
  1 sibling, 5 replies; 19+ messages in thread
From: Paul Iannetta @ 2023-08-23 14:39 UTC (permalink / raw)
  To: binutils; +Cc: Paul Iannetta

As discussed earlier, I removed kvx_elf64_linux_vec, fix the handling of unique
symbols by using has_gnu_osabi instead of overwriting e_ident, change (unsigned)
long long into {u,}int64 and at some place int by int32_t.

Thanks,
Paul





^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 1/4] kvx: remove kvx_elf64_linux_vec
  2023-08-23 14:39       ` [PATCH 0/4] kvx: various fixes Paul Iannetta
@ 2023-08-23 14:39         ` Paul Iannetta
  2023-08-23 14:39         ` [PATCH 2/4] kvx: fix handling of STB_GNU_UNIQUE symbols Paul Iannetta
                           ` (3 subsequent siblings)
  4 siblings, 0 replies; 19+ messages in thread
From: Paul Iannetta @ 2023-08-23 14:39 UTC (permalink / raw)
  To: binutils; +Cc: Paul Iannetta

bfd/ChangeLog:

2023-08-23  Paul Iannetta  <piannetta@kalrayinc.com>

	* targets.c (_bfd_target_vector): Remove add kvx_elf64_linux_vec.
	* configure.ac: Likewise.
	* configure: Regenerate.
---
 bfd/configure    | 1 -
 bfd/configure.ac | 1 -
 2 files changed, 2 deletions(-)

diff --git a/bfd/configure b/bfd/configure
index d43754c4787..f0a07ff675f 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -13961,7 +13961,6 @@ do
     iq2000_elf32_vec)		 tb="$tb elf32-iq2000.lo elf32.lo $elf" ;;
     kvx_elf32_vec)		 tb="$tb elf32-kvx.lo elfxx-kvx.lo elf32.lo $elf $ipa" ;;
     kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
-    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
     lm32_elf32_vec)		 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
     lm32_elf32_fdpic_vec)	 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
     loongarch_elf32_vec)	 tb="$tb elf32-loongarch.lo elfxx-loongarch.lo elf32.lo elf-ifunc.lo $elf" ;;
diff --git a/bfd/configure.ac b/bfd/configure.ac
index 3fdd12fe22d..d1e7e3a4bf3 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -497,7 +497,6 @@ do
     iq2000_elf32_vec)		 tb="$tb elf32-iq2000.lo elf32.lo $elf" ;;
     kvx_elf32_vec)		 tb="$tb elf32-kvx.lo elfxx-kvx.lo elf32.lo $elf $ipa" ;;
     kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
-    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
     lm32_elf32_vec)		 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
     lm32_elf32_fdpic_vec)	 tb="$tb elf32-lm32.lo elf32.lo $elf" ;;
     loongarch_elf32_vec)	 tb="$tb elf32-loongarch.lo elfxx-loongarch.lo elf32.lo elf-ifunc.lo $elf" ;;
-- 
2.35.1.500.gb896f729e2






^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 2/4] kvx: fix handling of STB_GNU_UNIQUE symbols
  2023-08-23 14:39       ` [PATCH 0/4] kvx: various fixes Paul Iannetta
  2023-08-23 14:39         ` [PATCH 1/4] kvx: remove kvx_elf64_linux_vec Paul Iannetta
@ 2023-08-23 14:39         ` Paul Iannetta
  2023-08-23 14:39         ` [PATCH 3/4] kvx: use {u,}int32_t and {u,}int64_t Paul Iannetta
                           ` (2 subsequent siblings)
  4 siblings, 0 replies; 19+ messages in thread
From: Paul Iannetta @ 2023-08-23 14:39 UTC (permalink / raw)
  To: binutils; +Cc: Paul Iannetta

When processing a STB_GNU_UNIQUE symbol we did not update has_gnu_osabi
correctly.

gas/ChangeLog:

2023-08-23  Paul Iannetta  <piannetta@kalrayinc.com>

	* config/tc-kvx.c (kvx_end): Do not write to e_ident.
	(kvx_type): Properly handle STB_GNU_UNIQUE symbols.
---
 gas/config/tc-kvx.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/gas/config/tc-kvx.c b/gas/config/tc-kvx.c
index c5c8312922f..be8bc7da923 100644
--- a/gas/config/tc-kvx.c
+++ b/gas/config/tc-kvx.c
@@ -2205,7 +2205,6 @@ void
 kvx_end (void)
 {
   int newflags;
-  Elf_Internal_Ehdr *i_ehdrp;
 
   if (!env.params.core_set)
     env.params.core = kvx_core_info->elf_core;
@@ -2218,10 +2217,6 @@ kvx_end (void)
 
   bfd_set_private_flags (stdoutput, newflags);
 
-  i_ehdrp = elf_elfheader (stdoutput);
-  i_ehdrp->e_ident[EI_ABIVERSION] = env.params.abi;
-  i_ehdrp->e_ident[EI_OSABI] = env.params.osabi;
-
   cleanup ();
 
   if (inside_bundle && insncnt != 0)
@@ -2277,7 +2272,10 @@ kvx_type (int start ATTRIBUTE_UNUSED)
     type = BSF_ELF_COMMON;
   else if (strcmp (typename, "gnu_unique_object") == 0
 	   || strcmp (typename, "STB_GNU_UNIQUE") == 0)
-    type = BSF_OBJECT | BSF_GNU_UNIQUE;
+    {
+      elf_tdata (stdoutput)->has_gnu_osabi |= elf_gnu_osabi_unique;
+      type = BSF_OBJECT | BSF_GNU_UNIQUE;
+    }
   else if (strcmp (typename, "notype") == 0
 	   || strcmp (typename, "STT_NOTYPE") == 0)
     ;
-- 
2.35.1.500.gb896f729e2






^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 3/4] kvx: use {u,}int32_t and {u,}int64_t
  2023-08-23 14:39       ` [PATCH 0/4] kvx: various fixes Paul Iannetta
  2023-08-23 14:39         ` [PATCH 1/4] kvx: remove kvx_elf64_linux_vec Paul Iannetta
  2023-08-23 14:39         ` [PATCH 2/4] kvx: fix handling of STB_GNU_UNIQUE symbols Paul Iannetta
@ 2023-08-23 14:39         ` Paul Iannetta
  2023-08-23 14:39         ` [PATCH 4/4] kvx: bfd/config.bfd & ld/configure.tgt Paul Iannetta
  2023-08-24  3:12         ` [PATCH 0/4] kvx: various fixes Alan Modra
  4 siblings, 0 replies; 19+ messages in thread
From: Paul Iannetta @ 2023-08-23 14:39 UTC (permalink / raw)
  To: binutils; +Cc: Paul Iannetta

gas/ChangeLog:

2023-08-23  Paul Iannetta  <piannetta@kalrayinc.com>

	* config/kvx-parse.c (promote_token): use {u,}int32_t and
	  {u,}int64_t.
	(get_token_class): Likewise.
	* config/tc-kvx.c (insert_operand): Likewise.
	* config/tc-kvx.h (struct token_s): Likewise.
	(struct token_list): Likewise.

opcodes/ChangeLog:

2023-08-23  Paul Iannetta  <piannetta@kalrayinc.com>

	* kvx-dis.c (struct decoded_insn): use {u,}int32_t and
	  {u,}int64_t.
	(decode_insn): Likewise.
	(print_insn_kvx): Likewise.
	(decode_prologue_epilogue_bundle): Likewise.
	* kvx-dis.h (struct kvx_prologue_epilogue_insn): Likewise.
---
 gas/config/kvx-parse.c | 20 ++++++++++----------
 gas/config/tc-kvx.c    |  8 ++++----
 gas/config/tc-kvx.h    | 10 +++++-----
 opcodes/kvx-dis.c      | 32 ++++++++++++++++----------------
 opcodes/kvx-dis.h      |  2 +-
 5 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/gas/config/kvx-parse.c b/gas/config/kvx-parse.c
index af207be285b..bb51c861625 100644
--- a/gas/config/kvx-parse.c
+++ b/gas/config/kvx-parse.c
@@ -396,10 +396,10 @@ print_token (struct token_s token, char *buf, int bufsz)
     buf[i] = 0;
 }
 
-static long long
+static int64_t
 promote_token (struct token_s tok)
 {
-  long long cur_class = tok.class_id & -tok.class_id;
+  int64_t cur_class = tok.class_id & -tok.class_id;
   switch (tok.category)
     {
       case CAT_REGISTER:
@@ -414,8 +414,8 @@ promote_token (struct token_s tok)
 	  input_line_pointer = tok.insn + tok.begin;
 	  expression (&exp);
 	  input_line_pointer = ilp_save;
-	  long long new_class_id = tok.class_id;
-	  long long old_class_id = tok.class_id;
+	  int64_t new_class_id = tok.class_id;
+	  int64_t old_class_id = tok.class_id;
 	  while (((new_class_id = env.promote_immediate (old_class_id))
 		  != old_class_id)
 		 && ((exp.X_op == O_symbol
@@ -451,7 +451,7 @@ is_insn (const struct token_s *token, struct token_class *classes)
   return res;
 }
 
-static long long
+static int64_t
 get_token_class (struct token_s *token, struct token_classes *classes, int insn_p, int modifier_p)
 {
   int cur = 0;
@@ -519,12 +519,12 @@ get_token_class (struct token_s *token, struct token_classes *classes, int insn_
 
   if (class == classes->imm_classes)
     {
-      unsigned long long uval
+      uint64_t uval
 	= (token_val_p
 	   ? token->val
 	   : strtoull (tok + (tok[0] == '-') + (tok[0] == '+'), NULL, 0));
-      long long val = uval;
-      long long pval = val < 0 ? -uval : uval;
+      int64_t val = uval;
+      int64_t pval = val < 0 ? -uval : uval;
       int neg_power2_p = val < 0 && !(uval & (uval - 1));
       unsigned len = pval ? 8 * sizeof (pval) - __builtin_clzll (pval) : 0;
       while (class[cur].class_id != -1
@@ -821,7 +821,7 @@ retry:;
     parse_with_restarts (tok, cur_rule[i].jump_target, rules, errs);
   /* While parsing fails but there is hope since the current token can be
      promoted.  */
-  while (!fst_part && tok.class_id != (long long) promote_token (tok))
+  while (!fst_part && tok.class_id != (int64_t) promote_token (tok))
     {
       free_token_list (fst_part);
       tok.class_id = promote_token (tok);
@@ -871,7 +871,7 @@ retry:;
 
   printf_debug (1, "snd_part: Trying to match: %s\n", TOKEN_NAME (CLASS_ID (tok)));
   struct token_list *snd_part = parse_with_restarts (tok, cur_rule[i].stack_it, rules, errs);
-  while (!snd_part && tok.class_id != (long long) promote_token (tok))
+  while (!snd_part && tok.class_id != (int64_t) promote_token (tok))
     {
       tok.class_id = promote_token (tok);
       printf_debug (1, ">> Restart with %s?\n", TOKEN_NAME (CLASS_ID (tok)));
diff --git a/gas/config/tc-kvx.c b/gas/config/tc-kvx.c
index be8bc7da923..c9cb8adbb3d 100644
--- a/gas/config/tc-kvx.c
+++ b/gas/config/tc-kvx.c
@@ -458,7 +458,7 @@ static int
 insert_operand (struct kvxinsn *insn, struct kvx_operand *opdef,
 		struct token_list *tok)
 {
-  unsigned long long op = 0;
+  uint64_t op = 0;
   struct kvx_bitfield *bfields = opdef->bfield;
   int bf_nb = opdef->bitfields;
   int immx_ready = 0;
@@ -570,7 +570,7 @@ insert_operand (struct kvxinsn *insn, struct kvx_operand *opdef,
 	      {
 		/* This is a immediate: either a regular immediate, or an
 		   immediate that was saved in a variable through `.equ'.  */
-		unsigned long long sval = (long long) tok->val;
+		uint64_t sval = (int64_t) tok->val;
 		op = opdef->flags & kvxSIGNED ? sval : tok->val;
 		op >>= opdef->shift;
 	      }
@@ -661,8 +661,8 @@ insert_operand (struct kvxinsn *insn, struct kvx_operand *opdef,
 
   for (int bf_idx = 0; bf_idx < bf_nb; bf_idx++)
     {
-      unsigned long long value =
-	((unsigned long long) op >> bfields[bf_idx].from_offset);
+      uint64_t value =
+	((uint64_t) op >> bfields[bf_idx].from_offset);
       int j = 0;
       int to_offset = bfields[bf_idx].to_offset;
       value &= (1LL << bfields[bf_idx].size) - 1;
diff --git a/gas/config/tc-kvx.h b/gas/config/tc-kvx.h
index efb57251541..4d29f015c09 100644
--- a/gas/config/tc-kvx.h
+++ b/gas/config/tc-kvx.h
@@ -46,15 +46,15 @@ struct token_s {
   char *insn;
   int begin, end;
   int category;
-  long long class_id;
-  unsigned long long val;
+  int64_t class_id;
+  uint64_t val;
 };
 
 struct token_list
 {
   char *tok;
-  unsigned long long val;
-  long long class_id;
+  uint64_t val;
+  int64_t class_id;
   int category;
   int loc;
   struct token_list *next;
@@ -64,7 +64,7 @@ struct token_list
 
 struct token_class {
   const char ** class_values;
-  long long class_id;
+  int64_t class_id;
   int sz;
 };
 
diff --git a/opcodes/kvx-dis.c b/opcodes/kvx-dis.c
index d7b86791c30..e63430a9e57 100644
--- a/opcodes/kvx-dis.c
+++ b/opcodes/kvx-dis.c
@@ -539,7 +539,7 @@ struct decoded_insn
       CAT_IMMEDIATE,
     } type;
     /* The value of the operands.  */
-    unsigned long long val;
+    uint64_t val;
     /* If it is an immediate, its sign.  */
     int sign;
     /* If it is an immediate, is it pc relative.  */
@@ -593,20 +593,20 @@ decode_insn (bfd_vma memaddr, insn_t * insn, struct decoded_insn *res)
 	      int flags = op->format[i]->flags;
 	      int shift = op->format[i]->shift;
 	      int bias = op->format[i]->bias;
-	      unsigned long long value = 0;
+	      uint64_t value = 0;
 
 	      for (int bf_idx = 0; bf_idx < bf_nb; bf_idx++)
 		{
 		  int insn_idx = (int) bf[bf_idx].to_offset / 32;
 		  int to_offset = bf[bf_idx].to_offset % 32;
-		  unsigned long long encoded_value =
+		  uint64_t encoded_value =
 		    insn->syllables[insn_idx] >> to_offset;
 		  encoded_value &= (1LL << bf[bf_idx].size) - 1;
 		  value |= encoded_value << bf[bf_idx].from_offset;
 		}
 	      if (flags & kvxSIGNED)
 		{
-		  unsigned long long signbit = 1LL << (width - 1);
+		  uint64_t signbit = 1LL << (width - 1);
 		  value = (value ^ signbit) - signbit;
 		}
 	      value = (value << shift) + bias;
@@ -1126,13 +1126,13 @@ print_insn_kvx (bfd_vma memaddr, struct disassemble_info *info)
 		  {
 		    if (dec.operands[i].width <= 32)
 		      {
-			(*info->fprintf_func) (info->stream, "%d (0x%x)",
-					       (int) dec.operands[i].val,
-					       (int) dec.operands[i].val);
+			(*info->fprintf_func) (info->stream, "%" PRId32 " (0x%" PRIx32 ")",
+					       (int32_t) dec.operands[i].val,
+					       (int32_t) dec.operands[i].val);
 		      }
 		    else
 		      {
-			(*info->fprintf_func) (info->stream, "%lld (0x%llx)",
+			(*info->fprintf_func) (info->stream, "%" PRId64 " (0x%" PRIx64 ")",
 					       dec.operands[i].val,
 					       dec.operands[i].val);
 		      }
@@ -1141,18 +1141,18 @@ print_insn_kvx (bfd_vma memaddr, struct disassemble_info *info)
 		  {
 		    if (dec.operands[i].width <= 32)
 		      {
-			(*info->fprintf_func) (info->stream, "%u (0x%x)",
-					       (unsigned int) dec.operands[i].
+			(*info->fprintf_func) (info->stream, "%" PRIu32 " (0x%" PRIx32 ")",
+					       (uint32_t) dec.operands[i].
 					       val,
-					       (unsigned int) dec.operands[i].
+					       (uint32_t) dec.operands[i].
 					       val);
 		      }
 		    else
 		      {
-			(*info->fprintf_func) (info->stream, "%llu (0x%llx)",
-					       (unsigned long long) dec.
+			(*info->fprintf_func) (info->stream, "%" PRIu64 " (0x%" PRIx64 ")",
+					       (uint64_t) dec.
 					       operands[i].val,
-					       (unsigned long long) dec.
+					       (uint64_t) dec.
 					       operands[i].val);
 		      }
 		  }
@@ -1317,7 +1317,7 @@ decode_prologue_epilogue_bundle (bfd_vma memaddr,
 	  int flags = fmt->flags;
 	  int shift = fmt->shift;
 	  int bias = fmt->bias;
-	  unsigned long long encoded_value, value = 0;
+	  uint64_t encoded_value, value = 0;
 
 	  for (int bf_idx = 0; bf_idx < bf_nb; bf_idx++)
 	    {
@@ -1329,7 +1329,7 @@ decode_prologue_epilogue_bundle (bfd_vma memaddr,
 	    }
 	  if (flags & kvxSIGNED)
 	    {
-	      unsigned long long signbit = 1LL << (width - 1);
+	      uint64_t signbit = 1LL << (width - 1);
 	      value = (value ^ signbit) - signbit;
 	    }
 	  value = (value << shift) + bias;
diff --git a/opcodes/kvx-dis.h b/opcodes/kvx-dis.h
index e82538b623a..435fe7d9fe9 100644
--- a/opcodes/kvx-dis.h
+++ b/opcodes/kvx-dis.h
@@ -45,7 +45,7 @@ enum kvx_prologue_epilogue_insn_type
 struct kvx_prologue_epilogue_insn
 {
   enum kvx_prologue_epilogue_insn_type insn_type;
-  unsigned long long immediate;
+  uint64_t immediate;
   int gpr_reg[3];
   int nb_gprs;
 };
-- 
2.35.1.500.gb896f729e2






^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 4/4] kvx: bfd/config.bfd & ld/configure.tgt
  2023-08-23 14:39       ` [PATCH 0/4] kvx: various fixes Paul Iannetta
                           ` (2 preceding siblings ...)
  2023-08-23 14:39         ` [PATCH 3/4] kvx: use {u,}int32_t and {u,}int64_t Paul Iannetta
@ 2023-08-23 14:39         ` Paul Iannetta
  2023-08-24  3:12         ` [PATCH 0/4] kvx: various fixes Alan Modra
  4 siblings, 0 replies; 19+ messages in thread
From: Paul Iannetta @ 2023-08-23 14:39 UTC (permalink / raw)
  To: binutils; +Cc: Paul Iannetta

ld/ChangeLog:

2023-08-23  Paul Iannetta  <piannetta@kalrayinc.com>

	* configure.tgt: Split long line.

bfd/ChangeLog:

2023-08-23  Paul Iannetta  <piannetta@kalrayinc.com>

	* config.bfd: Remove kvx_elf64_vec from targ_selvecs as it is
	  already in targ_defvec.
---
 bfd/config.bfd   | 2 +-
 ld/configure.tgt | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/bfd/config.bfd b/bfd/config.bfd
index 2a4622219ba..08129e6a8cb 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -807,7 +807,7 @@ case "${targ}" in
 
   kvx-*-*)
     targ_defvec=kvx_elf64_vec
-    targ_selvecs="kvx_elf64_vec kvx_elf32_vec"
+    targ_selvecs=kvx_elf32_vec
     want64=true
     ;;
 #endif
diff --git a/ld/configure.tgt b/ld/configure.tgt
index f78ba07e5ca..ff0aaaae257 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -476,7 +476,8 @@ lm32-*-*)		targ_emul=elf32lm32
 kvx-*-linux*)		targ_emul=elf64kvx_linux
 			targ_extra_emuls="elf64kvx"
 			;;
-kvx-*-*)		targ_emul=elf64kvx; targ_extra_emuls="elf64kvx_linux elf32kvx"
+kvx-*-*)		targ_emul=elf64kvx;
+			targ_extra_emuls="elf64kvx_linux elf32kvx"
 			;;
 m32c-*-elf)
 			targ_emul=elf32m32c
-- 
2.35.1.500.gb896f729e2






^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] kvx: fix 32-bit build and validation
  2023-08-23 12:14     ` Alan Modra
  2023-08-23 14:39       ` [PATCH 0/4] kvx: various fixes Paul Iannetta
@ 2023-08-23 14:40       ` Paul Iannetta
  1 sibling, 0 replies; 19+ messages in thread
From: Paul Iannetta @ 2023-08-23 14:40 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

On Wed, Aug 23, 2023 at 09:44:12PM +0930, Alan Modra wrote:
> On Wed, Aug 23, 2023 at 09:44:25AM +0200, Paul Iannetta wrote:
> > On Wed, Aug 23, 2023 at 09:57:26AM +0930, Alan Modra wrote:
> > > ..I don't see kvx_elf64_linux_vec defined anywhere.  Delete it?
> > 
> > Indeed, it somehow got missing from bfd/targets.c, it is mostly
> > similar to kvx_elf64_vec, and only exists to match what is done in the
> > linker with the emulation elf64kvx_linux.
> 
> Unless you really need it, don't add it.  If you have two target
> vectors that match kvx objects then people will run into "file format
> is ambiguous" errors when attempting to use any of objdump, objcopy,
> nm etc. on a kvx object.  You won't see that if you've built binutils
> with one of the kvx targets as the default, but will if you've built
> say --target=x86_64-linux-gnu --enable-targets=all.

I'll get rid of it then.  Thanks.





^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/4] kvx: various fixes
  2023-08-23 14:39       ` [PATCH 0/4] kvx: various fixes Paul Iannetta
                           ` (3 preceding siblings ...)
  2023-08-23 14:39         ` [PATCH 4/4] kvx: bfd/config.bfd & ld/configure.tgt Paul Iannetta
@ 2023-08-24  3:12         ` Alan Modra
  2023-08-24  6:26           ` Paul Iannetta
  2023-08-24  8:49           ` [PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds Paul Iannetta
  4 siblings, 2 replies; 19+ messages in thread
From: Alan Modra @ 2023-08-24  3:12 UTC (permalink / raw)
  To: Paul Iannetta; +Cc: binutils

On Wed, Aug 23, 2023 at 04:39:19PM +0200, Paul Iannetta via Binutils wrote:
> As discussed earlier, I removed kvx_elf64_linux_vec, fix the handling of unique
> symbols by using has_gnu_osabi instead of overwriting e_ident, change (unsigned)
> long long into {u,}int64 and at some place int by int32_t.

I've committed these for you.  BTW, oss-fuzz is poking at the kvx
support and finding holes.  See pr30793.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/4] kvx: various fixes
  2023-08-24  3:12         ` [PATCH 0/4] kvx: various fixes Alan Modra
@ 2023-08-24  6:26           ` Paul Iannetta
  2023-08-24  8:49           ` [PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds Paul Iannetta
  1 sibling, 0 replies; 19+ messages in thread
From: Paul Iannetta @ 2023-08-24  6:26 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

On Thu, Aug 24, 2023 at 12:42:33PM +0930, Alan Modra wrote:
> On Wed, Aug 23, 2023 at 04:39:19PM +0200, Paul Iannetta via Binutils wrote:
> > As discussed earlier, I removed kvx_elf64_linux_vec, fix the handling of unique
> > symbols by using has_gnu_osabi instead of overwriting e_ident, change (unsigned)
> > long long into {u,}int64 and at some place int by int32_t.
> 
> I've committed these for you.  BTW, oss-fuzz is poking at the kvx
> support and finding holes.  See pr30793.
> 

Thank you very much, I'll have a look.

Paul





^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds
  2023-08-24  3:12         ` [PATCH 0/4] kvx: various fixes Alan Modra
  2023-08-24  6:26           ` Paul Iannetta
@ 2023-08-24  8:49           ` Paul Iannetta
  2023-08-24  9:08             ` Alan Modra
  1 sibling, 1 reply; 19+ messages in thread
From: Paul Iannetta @ 2023-08-24  8:49 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 540 bytes --]

On Thu, Aug 24, 2023 at 12:42:33PM +0930, Alan Modra wrote:
> On Wed, Aug 23, 2023 at 04:39:19PM +0200, Paul Iannetta via Binutils wrote:
> > As discussed earlier, I removed kvx_elf64_linux_vec, fix the handling of unique
> > symbols by using has_gnu_osabi instead of overwriting e_ident, change (unsigned)
> > long long into {u,}int64 and at some place int by int32_t.
> 
> I've committed these for you.  BTW, oss-fuzz is poking at the kvx
> support and finding holes.  See pr30793.

The attached patch should fix pr30793.

Thanks,
Paul



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-kvx-fix-kvx_reassemble_bundle-index-8-out-of-bounds.patch --]
[-- Type: text/x-diff, Size: 1000 bytes --]

From 03c35cf18fa689bc7d727c506d30c396244cb307 Mon Sep 17 00:00:00 2001
From: Paul Iannetta <piannetta@kalrayinc.com>
Date: Thu, 24 Aug 2023 10:39:14 +0200
Subject: [PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds

opcodes/ChangeLog:

2023-08-24  Paul Iannetta  <piannetta@kalrayinc.com>

	* kvx-dis.c (print_insn_kvx): Change the loop condition so that
	  wordcount is always less than KVXMAXBUNDLEWORDS.
---
 opcodes/kvx-dis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/opcodes/kvx-dis.c b/opcodes/kvx-dis.c
index e63430a9e57..a78eb5f84ec 100644
--- a/opcodes/kvx-dis.c
+++ b/opcodes/kvx-dis.c
@@ -1056,7 +1056,7 @@ print_insn_kvx (bfd_vma memaddr, struct disassemble_info *info)
 	  wordcount++;
 	}
       while (kvx_has_parallel_bit (bundle_words[wordcount - 1])
-	     && wordcount < KVXMAXBUNDLEWORDS);
+	     && wordcount < KVXMAXBUNDLEWORDS - 1);
       invalid_bundle = kvx_reassemble_bundle (wordcount, &insncount);
     }
 
-- 
2.35.1.500.gb896f729e2


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds
  2023-08-24  8:49           ` [PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds Paul Iannetta
@ 2023-08-24  9:08             ` Alan Modra
  2023-08-24  9:26               ` Paul Iannetta
  0 siblings, 1 reply; 19+ messages in thread
From: Alan Modra @ 2023-08-24  9:08 UTC (permalink / raw)
  To: Paul Iannetta; +Cc: binutils

On Thu, Aug 24, 2023 at 10:49:06AM +0200, Paul Iannetta wrote:
> On Thu, Aug 24, 2023 at 12:42:33PM +0930, Alan Modra wrote:
> > On Wed, Aug 23, 2023 at 04:39:19PM +0200, Paul Iannetta via Binutils wrote:
> > > As discussed earlier, I removed kvx_elf64_linux_vec, fix the handling of unique
> > > symbols by using has_gnu_osabi instead of overwriting e_ident, change (unsigned)
> > > long long into {u,}int64 and at some place int by int32_t.
> > 
> > I've committed these for you.  BTW, oss-fuzz is poking at the kvx
> > support and finding holes.  See pr30793.
> 
> The attached patch should fix pr30793.

decode_prologue_epilogue_bundle too?

> 
> Thanks,
> Paul
> 
> 

> >From 03c35cf18fa689bc7d727c506d30c396244cb307 Mon Sep 17 00:00:00 2001
> From: Paul Iannetta <piannetta@kalrayinc.com>
> Date: Thu, 24 Aug 2023 10:39:14 +0200
> Subject: [PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds
> 
> opcodes/ChangeLog:
> 
> 2023-08-24  Paul Iannetta  <piannetta@kalrayinc.com>
> 
> 	* kvx-dis.c (print_insn_kvx): Change the loop condition so that
> 	  wordcount is always less than KVXMAXBUNDLEWORDS.
> ---
>  opcodes/kvx-dis.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/opcodes/kvx-dis.c b/opcodes/kvx-dis.c
> index e63430a9e57..a78eb5f84ec 100644
> --- a/opcodes/kvx-dis.c
> +++ b/opcodes/kvx-dis.c
> @@ -1056,7 +1056,7 @@ print_insn_kvx (bfd_vma memaddr, struct disassemble_info *info)
>  	  wordcount++;
>  	}
>        while (kvx_has_parallel_bit (bundle_words[wordcount - 1])
> -	     && wordcount < KVXMAXBUNDLEWORDS);
> +	     && wordcount < KVXMAXBUNDLEWORDS - 1);
>        invalid_bundle = kvx_reassemble_bundle (wordcount, &insncount);
>      }
>  
> -- 
> 2.35.1.500.gb896f729e2
> 


-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds
  2023-08-24  9:08             ` Alan Modra
@ 2023-08-24  9:26               ` Paul Iannetta
  2023-09-07 12:46                 ` Alan Modra
  0 siblings, 1 reply; 19+ messages in thread
From: Paul Iannetta @ 2023-08-24  9:26 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 2089 bytes --]

On Thu, Aug 24, 2023 at 06:38:25PM +0930, Alan Modra wrote:
> On Thu, Aug 24, 2023 at 10:49:06AM +0200, Paul Iannetta wrote:
> > On Thu, Aug 24, 2023 at 12:42:33PM +0930, Alan Modra wrote:
> > > On Wed, Aug 23, 2023 at 04:39:19PM +0200, Paul Iannetta via Binutils wrote:
> > > > As discussed earlier, I removed kvx_elf64_linux_vec, fix the handling of unique
> > > > symbols by using has_gnu_osabi instead of overwriting e_ident, change (unsigned)
> > > > long long into {u,}int64 and at some place int by int32_t.
> > > 
> > > I've committed these for you.  BTW, oss-fuzz is poking at the kvx
> > > support and finding holes.  See pr30793.
> > 
> > The attached patch should fix pr30793.
> 
> decode_prologue_epilogue_bundle too?

Indeed, thanks. (Currently, this is deadcode, because it is only used
by gdb which we have not contribued back yet).

> 
> > 
> > Thanks,
> > Paul
> > 
> > 
> 
> > >From 03c35cf18fa689bc7d727c506d30c396244cb307 Mon Sep 17 00:00:00 2001
> > From: Paul Iannetta <piannetta@kalrayinc.com>
> > Date: Thu, 24 Aug 2023 10:39:14 +0200
> > Subject: [PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds
> > 
> > opcodes/ChangeLog:
> > 
> > 2023-08-24  Paul Iannetta  <piannetta@kalrayinc.com>
> > 
> > 	* kvx-dis.c (print_insn_kvx): Change the loop condition so that
> > 	  wordcount is always less than KVXMAXBUNDLEWORDS.
> > ---
> >  opcodes/kvx-dis.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/opcodes/kvx-dis.c b/opcodes/kvx-dis.c
> > index e63430a9e57..a78eb5f84ec 100644
> > --- a/opcodes/kvx-dis.c
> > +++ b/opcodes/kvx-dis.c
> > @@ -1056,7 +1056,7 @@ print_insn_kvx (bfd_vma memaddr, struct disassemble_info *info)
> >  	  wordcount++;
> >  	}
> >        while (kvx_has_parallel_bit (bundle_words[wordcount - 1])
> > -	     && wordcount < KVXMAXBUNDLEWORDS);
> > +	     && wordcount < KVXMAXBUNDLEWORDS - 1);
> >        invalid_bundle = kvx_reassemble_bundle (wordcount, &insncount);
> >      }
> >  
> > -- 
> > 2.35.1.500.gb896f729e2
> > 
> 
> 
> -- 
> Alan Modra
> Australia Development Lab, IBM
> 
> 
> 
> 



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-kvx-fix-kvx_reassemble_bundle-index-8-out-of-bounds.patch --]
[-- Type: text/x-diff, Size: 1347 bytes --]

From 73bb3fb50eb05cf57795e6a078c0758658519df3 Mon Sep 17 00:00:00 2001
From: Paul Iannetta <piannetta@kalrayinc.com>
Date: Thu, 24 Aug 2023 10:39:14 +0200
Subject: [PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds

opcodes/ChangeLog:

2023-08-24  Paul Iannetta  <piannetta@kalrayinc.com>

	* kvx-dis.c (print_insn_kvx): Change the loop condition so that
	  wordcount is always less than KVXMAXBUNDLEWORDS.
	  (decode_prologue_epilogue_bundle): Likewise.
---
 opcodes/kvx-dis.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/opcodes/kvx-dis.c b/opcodes/kvx-dis.c
index e63430a9e57..2a5aa1d6cde 100644
--- a/opcodes/kvx-dis.c
+++ b/opcodes/kvx-dis.c
@@ -1056,7 +1056,7 @@ print_insn_kvx (bfd_vma memaddr, struct disassemble_info *info)
 	  wordcount++;
 	}
       while (kvx_has_parallel_bit (bundle_words[wordcount - 1])
-	     && wordcount < KVXMAXBUNDLEWORDS);
+	     && wordcount < KVXMAXBUNDLEWORDS - 1);
       invalid_bundle = kvx_reassemble_bundle (wordcount, &insncount);
     }
 
@@ -1237,7 +1237,7 @@ decode_prologue_epilogue_bundle (bfd_vma memaddr,
       nb_syl++;
     }
   while (kvx_has_parallel_bit (bundle_words[nb_syl - 1])
-	 && nb_syl < KVXMAXBUNDLEWORDS);
+	 && nb_syl < KVXMAXBUNDLEWORDS - 1);
   if (kvx_reassemble_bundle (nb_syl, &nb_insn))
     return -1;
 
-- 
2.35.1.500.gb896f729e2


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds
  2023-08-24  9:26               ` Paul Iannetta
@ 2023-09-07 12:46                 ` Alan Modra
  2023-09-07 15:27                   ` Paul Iannetta
  0 siblings, 1 reply; 19+ messages in thread
From: Alan Modra @ 2023-09-07 12:46 UTC (permalink / raw)
  To: Paul Iannetta; +Cc: binutils

On Thu, Aug 24, 2023 at 11:26:49AM +0200, Paul Iannetta wrote:
> > > 	* kvx-dis.c (print_insn_kvx): Change the loop condition so that
> > > 	  wordcount is always less than KVXMAXBUNDLEWORDS.

Hi Paul,
Does the following patch look good to you, and can you please craft a
testcase that exercises a maximum size bundle?

While the patch already committed for pr30793 prevents the asan error,
there is a problem: Now the last element of bundle_words never gets
written.  That's very likely wrong, or KVXMAXBUNDLEWORDS is too big.
So this patch rearranges things a little to support writing of all of
bundle_words and does the parallel bit checking only when filling
bundle_words.  In the normal case, kvx_reassemble_bundle will see
bundle_words[word_count-1] with the parallel bit clear and all other
words having it set.  In the error case where all words in
bundle_words have the parallel bit set, kvx_reassemble_bundle will be
passed a wordcount of KVXMAXBUNDLEWORDS + 1.  I've also made
kvx_reassemble_bundle return true for success rather than zero, and
removed the unnecessary check for zero wordcount.

	PR 30793
	* kvx-dis.c (kvx_reassemble_bundle): Return bool, true on success.
	Fail if wordcount is too large.  Don't check for wordcount zero.
	Don't check kvx_has_parallel_bit.
	(print_insn_kvx): Rewrite code reading bundle_words as a for loop.
	Don't stop reading at KVXMAXBUNDLEWORDS - 1.
	(decode_prologue_epilogue_bundle): Similarly.

diff --git a/opcodes/kvx-dis.c b/opcodes/kvx-dis.c
index ec9c7718b06..32865631569 100644
--- a/opcodes/kvx-dis.c
+++ b/opcodes/kvx-dis.c
@@ -257,7 +257,7 @@ kvx_dis_init (struct disassemble_info *info)
   env.initialized_p = 1;
 }
 
-static int
+static bool
 kvx_reassemble_bundle (int wordcount, int *_insncount)
 {
 
@@ -272,23 +272,23 @@ kvx_reassemble_bundle (int wordcount, int *_insncount)
   int mau_taken = 0;
   int lsu_taken = 0;
 
-  int i;
-  unsigned int j;
-
-  struct instr_s instr[KVXMAXBUNDLEISSUE];
-  assert (KVXMAXBUNDLEISSUE >= BundleIssue__);
-  memset (instr, 0, sizeof (instr));
-
   if (debug)
     fprintf (stderr, "kvx_reassemble_bundle: wordcount = %d\n", wordcount);
 
-  if (wordcount == 0)
+  if (wordcount > KVXMAXBUNDLEWORDS)
     {
       if (debug)
-	fprintf (stderr, "wordcount == 0\n");
-      return 1;
+	fprintf (stderr, "bundle exceeds maximum size\n");
+      return false;
     }
 
+  struct instr_s instr[KVXMAXBUNDLEISSUE];
+  memset (instr, 0, sizeof (instr));
+  assert (KVXMAXBUNDLEISSUE >= BundleIssue__);
+
+  int i;
+  unsigned int j;
+
   for (i = 0; i < wordcount; i++)
     {
       uint32_t syllable = bundle_words[i];
@@ -304,7 +304,7 @@ kvx_reassemble_bundle (int wordcount, int *_insncount)
 		    {
 		      if (debug)
 			fprintf (stderr, "Too many TCA instructions");
-		      return 1;
+		      return false;
 		    }
 		  if (debug)
 		    fprintf (stderr,
@@ -336,7 +336,7 @@ kvx_reassemble_bundle (int wordcount, int *_insncount)
 		    {
 		      if (debug)
 			fprintf (stderr, "Too many TCA instructions");
-		      return 1;
+		      return false;
 		    }
 		  if (debug)
 		    fprintf (stderr,
@@ -357,7 +357,7 @@ kvx_reassemble_bundle (int wordcount, int *_insncount)
 		    {
 		      if (debug)
 			fprintf (stderr, "Too many IMMX syllables");
-		      return 1;
+		      return false;
 		    }
 		  instr_p->immx[immx_count] = syllable;
 		  instr_p->immx_valid[immx_count] = 1;
@@ -425,7 +425,7 @@ kvx_reassemble_bundle (int wordcount, int *_insncount)
 	    {
 	      if (debug)
 		fprintf (stderr, "Too many ALU instructions");
-	      return 1;
+	      return false;
 	    }
 	  break;
 
@@ -434,7 +434,7 @@ kvx_reassemble_bundle (int wordcount, int *_insncount)
 	    {
 	      if (debug)
 		fprintf (stderr, "Too many MAU instructions");
-	      return 1;
+	      return false;
 	    }
 	  else
 	    {
@@ -453,7 +453,7 @@ kvx_reassemble_bundle (int wordcount, int *_insncount)
 	    {
 	      if (debug)
 		fprintf (stderr, "Too many LSU instructions");
-	      return 1;
+	      return false;
 	    }
 	  else
 	    {
@@ -466,21 +466,8 @@ kvx_reassemble_bundle (int wordcount, int *_insncount)
 	      lsu_taken = 1;
 	    }
 	}
-      if (!(kvx_has_parallel_bit (syllable)))
-	{
-	  if (debug)
-	    fprintf (stderr, "Stop! stop bit is set 0x%x\n", syllable);
-	  break;
-	}
       if (debug)
 	fprintf (stderr, "Continue %d < %d?\n", i, wordcount);
-
-    }
-  if (kvx_has_parallel_bit (bundle_words[i]))
-    {
-      if (debug)
-	fprintf (stderr, "bundle exceeds maximum size");
-      return 1;
     }
 
   /* Fill bundle_insn and count read syllables.  */
@@ -520,7 +507,7 @@ kvx_reassemble_bundle (int wordcount, int *_insncount)
     fprintf (stderr, "End => %d instructions\n", instr_idx);
 
   *_insncount = instr_idx;
-  return 0;
+  return true;
 }
 
 struct decoded_insn
@@ -1038,11 +1025,10 @@ print_insn_kvx (bfd_vma memaddr, struct disassemble_info *info)
      decentrifugate function.  */
   if (insnindex == 0)
     {
-      int wordcount = 0;
-      do
+      int wordcount;
+      for (wordcount = 0; wordcount < KVXMAXBUNDLEWORDS; wordcount++)
 	{
 	  int status;
-	  assert (wordcount < KVXMAXBUNDLEWORDS);
 	  status =
 	    (*info->read_memory_func) (memaddr + 4 * wordcount,
 				       (bfd_byte *) (bundle_words +
@@ -1053,11 +1039,11 @@ print_insn_kvx (bfd_vma memaddr, struct disassemble_info *info)
 					  info);
 	      return -1;
 	    }
-	  wordcount++;
+	  if (!kvx_has_parallel_bit (bundle_words[wordcount]))
+	    break;
 	}
-      while (kvx_has_parallel_bit (bundle_words[wordcount - 1])
-	     && wordcount < KVXMAXBUNDLEWORDS - 1);
-      invalid_bundle = kvx_reassemble_bundle (wordcount, &insncount);
+      wordcount++;
+      invalid_bundle = !kvx_reassemble_bundle (wordcount, &insncount);
     }
 
   assert (insnindex < KVXMAXBUNDLEISSUE);
@@ -1226,20 +1212,17 @@ decode_prologue_epilogue_bundle (bfd_vma memaddr,
     kvx_dis_init (info);
 
   /* Read the bundle.  */
-  nb_syl = 0;
-  do
+  for (nb_syl = 0; nb_syl < KVXMAXBUNDLEWORDS; nb_syl++)
     {
-      if (nb_syl >= KVXMAXBUNDLEWORDS)
-	return -1;
       if ((*info->read_memory_func) (memaddr + 4 * nb_syl,
 				     (bfd_byte *) &bundle_words[nb_syl], 4,
 				     info))
 	return -1;
-      nb_syl++;
+      if (!kvx_has_parallel_bit (bundle_words[nb_syl]))
+	break;
     }
-  while (kvx_has_parallel_bit (bundle_words[nb_syl - 1])
-	 && nb_syl < KVXMAXBUNDLEWORDS - 1);
-  if (kvx_reassemble_bundle (nb_syl, &nb_insn))
+  nb_syl++;
+  if (!kvx_reassemble_bundle (nb_syl, &nb_insn))
     return -1;
 
   /* Check for extension to right if this is not the end of bundle



-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds
  2023-09-07 12:46                 ` Alan Modra
@ 2023-09-07 15:27                   ` Paul Iannetta
  0 siblings, 0 replies; 19+ messages in thread
From: Paul Iannetta @ 2023-09-07 15:27 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

On Thu, Sep 07, 2023 at 10:16:28PM +0930, Alan Modra wrote:
> On Thu, Aug 24, 2023 at 11:26:49AM +0200, Paul Iannetta wrote:
> > > > 	* kvx-dis.c (print_insn_kvx): Change the loop condition so that
> > > > 	  wordcount is always less than KVXMAXBUNDLEWORDS.
> 
> Hi Paul,
> Does the following patch look good to you, and can you please craft a
> testcase that exercises a maximum size bundle?
> 
> While the patch already committed for pr30793 prevents the asan error,
> there is a problem: Now the last element of bundle_words never gets
> written.  That's very likely wrong, or KVXMAXBUNDLEWORDS is too big.
> So this patch rearranges things a little to support writing of all of
> bundle_words and does the parallel bit checking only when filling
> bundle_words.  In the normal case, kvx_reassemble_bundle will see
> bundle_words[word_count-1] with the parallel bit clear and all other
> words having it set.  In the error case where all words in
> bundle_words have the parallel bit set, kvx_reassemble_bundle will be
> passed a wordcount of KVXMAXBUNDLEWORDS + 1.  I've also made
> kvx_reassemble_bundle return true for success rather than zero, and
> removed the unnecessary check for zero wordcount.

Hi Alan,

Thank you for catching this, your patch looks good to me.  Below is a
patch which adds a test case, you can merge it with yours if you want.

Thanks,
--
Paul
Kalray


commit 8dbb32052cb0e1e5ea1569e3fb708582f8158290
Author: Paul Iannetta <piannetta@kalrayinc.com>
Date:   Thu Sep 7 17:10:01 2023 +0200

    kvx: Add a testcase for bundles with KVXMAXBUNDLEWORDS syllables

    The previous fix (f1917fc) for pr30793 introduced a bug when dealing
    with bundles of with KVXMAXBUNDLEWORDS syllables.  This adds a test case
    to ensure that such bundle are correctly disassembled.

    gas/ChangeLog:

    2023-09-07  Paul Iannetta  <piannetta@kalrayinc.com>

            * testsuite/gas/kvx/fat-bundles.s: New test.
            * testsuite/gas/kvx/kv3-1-fat-bundles.d: New test.
            * testsuite/gas/kvx/kv3-2-fat-bundles.d: New test.

diff --git a/gas/testsuite/gas/kvx/fat-bundles.s b/gas/testsuite/gas/kvx/fat-bundles.s
new file mode 100644
index 00000000000..8119c6043de
--- /dev/null
+++ b/gas/testsuite/gas/kvx/fat-bundles.s
@@ -0,0 +1,13 @@
+# The bundles in this file all have 8 syllables.
+
+	addd $r0 = $r0, 123456789010	# 1 ALU + 2 Immediate Extensions
+	addd $r0 = $r0, 123456789010	# 1 ALU + 2 Immediate Extensions
+	addd $r1 = $r2, 1234		# 1 ALU + 1 Immediate Extension
+	;;
+	igoto $r0			# 1 BCU
+	xmt44d $a0a1a2a3 = $a0a1a2a3	# 1 TCA
+	addd $r0 = $r0, 1234		# 1 ALU + 1 Immediate Extension
+	addd $r0 = $r0, 12345678901	# 1 ALU + 1 Immediate Extension
+	fmuld $r1 = $r2, $r3		# 1 MAU
+	lwz $r0 = 0[$r0]		# 1 LSU
+	;;
diff --git a/gas/testsuite/gas/kvx/kv3-1-fat-bundles.d b/gas/testsuite/gas/kvx/kv3-1-fat-bundles.d
new file mode 100644
index 00000000000..1f80e0444fd
--- /dev/null
+++ b/gas/testsuite/gas/kvx/kv3-1-fat-bundles.d
@@ -0,0 +1,20 @@
+#as: -march=kv3-1
+#objdump: -d
+#source: fat-bundles.s
+.*\/fat-bundles.o:     file format elf64-kvx
+
+
+Disassembly of section .text:
+
+0000000000000000 <.text>:
+   0:	82 34 04 e1 80 84 00 e1                         	addd \$r1 = \$r2, 1234 \(0x4d2\)
+   8:	80 84 00 e1 01 00 00 80 46 a6 2f 8f             	addd \$r0 = \$r0, 123456789010 \(0x1cbe991a12\)
+  14:	00 00 00 88 46 a6 2f 97 00 00 00 10             	addd \$r0 = \$r0, 123456789010 \(0x1cbe991a12\);;
+
+  20:	00 00 d8 8f                                     	igoto \$r0
+  24:	00 00 0c 84                                     	xmt44d \$a0a1a2a3 = \$a0a1a2a3
+  28:	80 34 00 e1 40 0d 00 e1                         	addd \$r0 = \$r0, 1234 \(0x4d2\)
+  30:	c2 70 05 d8 00 00 00 b0                         	addd \$r0 = \$r0, 12345678901 \(0x2dfdc1c35\)
+  38:	01 00 00 80                                     	fmuld \$r1 = \$r2, \$r3
+  3c:	07 f7 b7 08                                     	lwz \$r0 = 0 \(0x0\)\[\$r0\];;
+
diff --git a/gas/testsuite/gas/kvx/kv3-2-fat-bundles.d b/gas/testsuite/gas/kvx/kv3-2-fat-bundles.d
new file mode 100644
index 00000000000..54717eb55b4
--- /dev/null
+++ b/gas/testsuite/gas/kvx/kv3-2-fat-bundles.d
@@ -0,0 +1,20 @@
+#as: -march=kv3-2
+#objdump: -d
+#source: fat-bundles.s
+.*\/fat-bundles.o:     file format elf64-kvx
+
+
+Disassembly of section .text:
+
+0000000000000000 <.text>:
+   0:	82 34 04 e2 80 84 00 e2                         	addd \$r1 = \$r2, 1234 \(0x4d2\)
+   8:	80 84 00 e2 01 00 00 80 46 a6 2f 8f             	addd \$r0 = \$r0, 123456789010 \(0x1cbe991a12\)
+  14:	00 00 00 88 46 a6 2f 97 00 00 00 10             	addd \$r0 = \$r0, 123456789010 \(0x1cbe991a12\);;
+
+  20:	00 00 d8 8f                                     	igoto \$r0
+  24:	00 10 05 87                                     	xcopyv.td \$a0a1a2a3 = \$a0a1a2a3
+  28:	80 34 00 e2 40 0d 00 e2                         	addd \$r0 = \$r0, 1234 \(0x4d2\)
+  30:	c2 70 05 d8 00 00 00 b0                         	addd \$r0 = \$r0, 12345678901 \(0x2dfdc1c35\)
+  38:	01 00 00 80                                     	fmuld \$r1 = \$r2, \$r3
+  3c:	07 f7 b7 08                                     	lwz \$r0 = 0 \(0x0\)\[\$r0\];;
+





^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2023-09-07 15:27 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-22 16:01 [PATCH] kvx: fix 32-bit build and validation Paul Iannetta
2023-08-23  0:27 ` Alan Modra
2023-08-23  7:44   ` Paul Iannetta
2023-08-23 12:14     ` Alan Modra
2023-08-23 14:39       ` [PATCH 0/4] kvx: various fixes Paul Iannetta
2023-08-23 14:39         ` [PATCH 1/4] kvx: remove kvx_elf64_linux_vec Paul Iannetta
2023-08-23 14:39         ` [PATCH 2/4] kvx: fix handling of STB_GNU_UNIQUE symbols Paul Iannetta
2023-08-23 14:39         ` [PATCH 3/4] kvx: use {u,}int32_t and {u,}int64_t Paul Iannetta
2023-08-23 14:39         ` [PATCH 4/4] kvx: bfd/config.bfd & ld/configure.tgt Paul Iannetta
2023-08-24  3:12         ` [PATCH 0/4] kvx: various fixes Alan Modra
2023-08-24  6:26           ` Paul Iannetta
2023-08-24  8:49           ` [PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds Paul Iannetta
2023-08-24  9:08             ` Alan Modra
2023-08-24  9:26               ` Paul Iannetta
2023-09-07 12:46                 ` Alan Modra
2023-09-07 15:27                   ` Paul Iannetta
2023-08-23 14:40       ` [PATCH] kvx: fix 32-bit build and validation Paul Iannetta
2023-08-23  3:16 ` Alan Modra
2023-08-23 13:39   ` Luis Machado

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).