From: Paul Iannetta <piannetta@kalrayinc.com>
To: binutils@sourceware.org
Subject: [PATCH] kvx: fix 32-bit build and validation
Date: Tue, 22 Aug 2023 18:01:42 +0200 [thread overview]
Message-ID: <20230822160142.ocnjgkuboicpncii@ws2202.lin.mbt.kalray.eu> (raw)
[-- 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
next reply other threads:[~2023-08-22 16:01 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-22 16:01 Paul Iannetta [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230822160142.ocnjgkuboicpncii@ws2202.lin.mbt.kalray.eu \
--to=piannetta@kalrayinc.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).