Skip to content

Commit 069f988

Browse files
committed
toolchain: binutils: fix compilation with GCC15
GCC15 has switched the C language default from GNU17 to GNU23[1] and this causes builds to fail with: In file included from mips-opc.c:29: mips-opc.c: In function 'decode_mips_operand': mips-formats.h:86:7: error: expected identifier or '(' before 'static_assert' 86 | static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \ | ^~~~~~~~~~~~~ mips-opc.c:214:15: note: in expansion of macro 'MAPPED_REG' 214 | case 'z': MAPPED_REG (0, 0, GP, reg_0_map); | ^~~~~~~~~~ So, backport upstream fix for this[2] to fix compilation with GCC15. Patch for 2.40 was manually refreshed as part of the S390 code does not exist in 2.40 as it was added after it. [1] https://gcc.gnu.org/gcc-15/porting_to.html#c23 [2] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=8ebe62f3f0d27806b1bf69f301f5e188b4acd2b4 Fixes: #18678 Link: openwrt/openwrt#18681 Signed-off-by: Robert Marko <[email protected]> (cherry picked from commit d321617)
1 parent cc1b909 commit 069f988

File tree

3 files changed

+222
-0
lines changed

3 files changed

+222
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
From 8ebe62f3f0d27806b1bf69f301f5e188b4acd2b4 Mon Sep 17 00:00:00 2001
2+
From: Sam James <[email protected]>
3+
Date: Sat, 16 Nov 2024 05:03:52 +0000
4+
Subject: [PATCH] opcodes: fix -std=gnu23 compatibility wrt static_assert
5+
6+
static_assert is declared in C23 so we can't reuse that identifier:
7+
* Define our own static_assert conditionally;
8+
9+
* Rename "static assert" hacks to _N as we do already in some places
10+
to avoid a conflict.
11+
12+
ChangeLog:
13+
PR ld/32372
14+
15+
* i386-gen.c (static_assert): Define conditionally.
16+
* mips-formats.h (MAPPED_INT): Rename identifier.
17+
(MAPPED_REG): Rename identifier.
18+
(OPTIONAL_MAPPED_REG): Rename identifier.
19+
* s390-opc.c (static_assert): Define conditionally.
20+
---
21+
opcodes/i386-gen.c | 2 ++
22+
opcodes/mips-formats.h | 6 +++---
23+
opcodes/s390-opc.c | 2 ++
24+
3 files changed, 7 insertions(+), 3 deletions(-)
25+
26+
--- a/opcodes/i386-gen.c
27+
+++ b/opcodes/i386-gen.c
28+
@@ -33,7 +33,9 @@
29+
30+
/* Build-time checks are preferrable over runtime ones. Use this construct
31+
in preference where possible. */
32+
+#ifndef static_assert
33+
#define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
34+
+#endif
35+
36+
static const char *program_name = NULL;
37+
static int debug = 0;
38+
--- a/opcodes/mips-formats.h
39+
+++ b/opcodes/mips-formats.h
40+
@@ -49,7 +49,7 @@
41+
#define MAPPED_INT(SIZE, LSB, MAP, PRINT_HEX) \
42+
{ \
43+
typedef char ATTRIBUTE_UNUSED \
44+
- static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
45+
+ static_assert_3[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
46+
static const struct mips_mapped_int_operand op = { \
47+
{ OP_MAPPED_INT, SIZE, LSB }, MAP, PRINT_HEX \
48+
}; \
49+
@@ -83,7 +83,7 @@
50+
#define MAPPED_REG(SIZE, LSB, BANK, MAP) \
51+
{ \
52+
typedef char ATTRIBUTE_UNUSED \
53+
- static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
54+
+ static_assert_4[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
55+
static const struct mips_reg_operand op = { \
56+
{ OP_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
57+
}; \
58+
@@ -93,7 +93,7 @@
59+
#define OPTIONAL_MAPPED_REG(SIZE, LSB, BANK, MAP) \
60+
{ \
61+
typedef char ATTRIBUTE_UNUSED \
62+
- static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
63+
+ static_assert_5[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
64+
static const struct mips_reg_operand op = { \
65+
{ OP_OPTIONAL_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
66+
}; \
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
From 8ebe62f3f0d27806b1bf69f301f5e188b4acd2b4 Mon Sep 17 00:00:00 2001
2+
From: Sam James <[email protected]>
3+
Date: Sat, 16 Nov 2024 05:03:52 +0000
4+
Subject: [PATCH] opcodes: fix -std=gnu23 compatibility wrt static_assert
5+
6+
static_assert is declared in C23 so we can't reuse that identifier:
7+
* Define our own static_assert conditionally;
8+
9+
* Rename "static assert" hacks to _N as we do already in some places
10+
to avoid a conflict.
11+
12+
ChangeLog:
13+
PR ld/32372
14+
15+
* i386-gen.c (static_assert): Define conditionally.
16+
* mips-formats.h (MAPPED_INT): Rename identifier.
17+
(MAPPED_REG): Rename identifier.
18+
(OPTIONAL_MAPPED_REG): Rename identifier.
19+
* s390-opc.c (static_assert): Define conditionally.
20+
---
21+
opcodes/i386-gen.c | 2 ++
22+
opcodes/mips-formats.h | 6 +++---
23+
opcodes/s390-opc.c | 2 ++
24+
3 files changed, 7 insertions(+), 3 deletions(-)
25+
26+
--- a/opcodes/i386-gen.c
27+
+++ b/opcodes/i386-gen.c
28+
@@ -30,7 +30,9 @@
29+
30+
/* Build-time checks are preferrable over runtime ones. Use this construct
31+
in preference where possible. */
32+
+#ifndef static_assert
33+
#define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
34+
+#endif
35+
36+
static const char *program_name = NULL;
37+
static int debug = 0;
38+
--- a/opcodes/mips-formats.h
39+
+++ b/opcodes/mips-formats.h
40+
@@ -49,7 +49,7 @@
41+
#define MAPPED_INT(SIZE, LSB, MAP, PRINT_HEX) \
42+
{ \
43+
typedef char ATTRIBUTE_UNUSED \
44+
- static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
45+
+ static_assert_3[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
46+
static const struct mips_mapped_int_operand op = { \
47+
{ OP_MAPPED_INT, SIZE, LSB }, MAP, PRINT_HEX \
48+
}; \
49+
@@ -83,7 +83,7 @@
50+
#define MAPPED_REG(SIZE, LSB, BANK, MAP) \
51+
{ \
52+
typedef char ATTRIBUTE_UNUSED \
53+
- static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
54+
+ static_assert_4[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
55+
static const struct mips_reg_operand op = { \
56+
{ OP_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
57+
}; \
58+
@@ -93,7 +93,7 @@
59+
#define OPTIONAL_MAPPED_REG(SIZE, LSB, BANK, MAP) \
60+
{ \
61+
typedef char ATTRIBUTE_UNUSED \
62+
- static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
63+
+ static_assert_5[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
64+
static const struct mips_reg_operand op = { \
65+
{ OP_OPTIONAL_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
66+
}; \
67+
--- a/opcodes/s390-opc.c
68+
+++ b/opcodes/s390-opc.c
69+
@@ -36,7 +36,9 @@
70+
71+
/* Build-time checks are preferrable over runtime ones. Use this construct
72+
in preference where possible. */
73+
+#ifndef static_assert
74+
#define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
75+
+#endif
76+
77+
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
78+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
From 8ebe62f3f0d27806b1bf69f301f5e188b4acd2b4 Mon Sep 17 00:00:00 2001
2+
From: Sam James <[email protected]>
3+
Date: Sat, 16 Nov 2024 05:03:52 +0000
4+
Subject: [PATCH] opcodes: fix -std=gnu23 compatibility wrt static_assert
5+
6+
static_assert is declared in C23 so we can't reuse that identifier:
7+
* Define our own static_assert conditionally;
8+
9+
* Rename "static assert" hacks to _N as we do already in some places
10+
to avoid a conflict.
11+
12+
ChangeLog:
13+
PR ld/32372
14+
15+
* i386-gen.c (static_assert): Define conditionally.
16+
* mips-formats.h (MAPPED_INT): Rename identifier.
17+
(MAPPED_REG): Rename identifier.
18+
(OPTIONAL_MAPPED_REG): Rename identifier.
19+
* s390-opc.c (static_assert): Define conditionally.
20+
---
21+
opcodes/i386-gen.c | 2 ++
22+
opcodes/mips-formats.h | 6 +++---
23+
opcodes/s390-opc.c | 2 ++
24+
3 files changed, 7 insertions(+), 3 deletions(-)
25+
26+
--- a/opcodes/i386-gen.c
27+
+++ b/opcodes/i386-gen.c
28+
@@ -30,7 +30,9 @@
29+
30+
/* Build-time checks are preferrable over runtime ones. Use this construct
31+
in preference where possible. */
32+
+#ifndef static_assert
33+
#define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
34+
+#endif
35+
36+
static const char *program_name = NULL;
37+
static int debug = 0;
38+
--- a/opcodes/mips-formats.h
39+
+++ b/opcodes/mips-formats.h
40+
@@ -49,7 +49,7 @@
41+
#define MAPPED_INT(SIZE, LSB, MAP, PRINT_HEX) \
42+
{ \
43+
typedef char ATTRIBUTE_UNUSED \
44+
- static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
45+
+ static_assert_3[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
46+
static const struct mips_mapped_int_operand op = { \
47+
{ OP_MAPPED_INT, SIZE, LSB }, MAP, PRINT_HEX \
48+
}; \
49+
@@ -83,7 +83,7 @@
50+
#define MAPPED_REG(SIZE, LSB, BANK, MAP) \
51+
{ \
52+
typedef char ATTRIBUTE_UNUSED \
53+
- static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
54+
+ static_assert_4[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
55+
static const struct mips_reg_operand op = { \
56+
{ OP_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
57+
}; \
58+
@@ -93,7 +93,7 @@
59+
#define OPTIONAL_MAPPED_REG(SIZE, LSB, BANK, MAP) \
60+
{ \
61+
typedef char ATTRIBUTE_UNUSED \
62+
- static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
63+
+ static_assert_5[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
64+
static const struct mips_reg_operand op = { \
65+
{ OP_OPTIONAL_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
66+
}; \
67+
--- a/opcodes/s390-opc.c
68+
+++ b/opcodes/s390-opc.c
69+
@@ -36,7 +36,9 @@
70+
71+
/* Build-time checks are preferrable over runtime ones. Use this construct
72+
in preference where possible. */
73+
+#ifndef static_assert
74+
#define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
75+
+#endif
76+
77+
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
78+

0 commit comments

Comments
 (0)