printf: fix Woverride-init warning for EDEADLK errno
PATCH 1/1 printf: fix Woverride-init warning for EDEADLK errno
From: Arnd Bergmann <[email protected]>
On most architectures, gcc -Wextra warns about the list of error numbers containing both EDEADLK and EDEADLOCK:
lib/errname.c:15:67: warning: initialized field overwritten [-Woverride-init]
15 | #define E(err) [err + BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = "-" #err
| ^~~lib/errname.c:172:2: note: in expansion of macro 'E'
172 | E(EDEADLK), /* EDEADLOCK */
| ^lib/errname.c:15:67: note: (near initialization for 'names_0[35]')
15 | #define E(err) [err + BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = "-" #err
| ^~~lib/errname.c:172:2: note: in expansion of macro 'E'
172 | E(EDEADLK), /* EDEADLOCK */
| ^Make that line conditional on the two values being distinct.
--- lib/errname.c | 2 ++ 1 file changed, 2 insertions(+)
lib/errname.c +2 -0
@@ -169,7 +169,9 @@ static const char *names_0[] = {E (ECANCELED ),/* ECANCELLED */ E (EAGAIN ),/* EWOULDBLOCK */ E (ECONNREFUSED ),/* EREFUSED */ +#if EDEADLK != EDEADLOCK E(EDEADLK), /* EDEADLOCK */ +#endif };#undef E
Signature · 1 line
2.27.0
Good morning Arnd,
Quoted 9 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
On most architectures, gcc -Wextra warns about the list of error numbers containing both EDEADLK and EDEADLOCK:
lib/errname.c:15:67: warning: initialized field overwritten [-Woverride-init]
15 | #define E(err) [err +BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = "-" #err
| ^~~lib/errname.c:172:2: note: in expansion of macro 'E'
Quoted 8 lines
172 | E(EDEADLK), /* EDEADLOCK */ | ^
lib/errname.c:15:67: note: (near initialization for 'names_0[35]')
15 | #define E(err) [err +BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = "-" #err
| ^~~lib/errname.c:172:2: note: in expansion of macro 'E'172 | E(EDEADLK), /* EDEADLOCK */ | ^
bad performance of gcc to warn twice about the same line and not mentioning the line that has E(EDEADLOCK).
Quoted 13 lines
Make that line conditional on the two values being distinct.
Fixes 57f5677e535b ("printf: add support for printing symbolic error names")Signed-off-by Arnd Bergmann <[email protected]>--- lib/errname.c | 2 ++ 1 file changed, 2 insertions(+)lib/errname.c +0
-0
lib/errname.c static const char *names_0[] = { · line 174
Quoted 6 lines
lib/errname.c +2
-0@@ -169,7 +169,9 @@ static const char *names_0[] = {E (ECANCELED ),/* ECANCELLED */ E (EAGAIN ),/* EWOULDBLOCK */ E (ECONNREFUSED ),/* EREFUSED */ +#if EDEADLK != EDEADLOCK E(EDEADLK), /* EDEADLOCK */ +#endif
The comments suggest that duplicates are expected. Would it make sense to add similar conditions to the other three entries?
Best regards
Uwe
Quoted 3 lines
lib/errname.c +0
-0};#undef E
Quoted 9 lines · Uwe Kleine-König
Quoted 8 lines · Arnd Bergmann
Make that line conditional on the two values being distinct.
Fixes 57f5677e535b ("printf: add support for printing symbolic error names")Signed-off-by Arnd Bergmann <[email protected]>--- lib/errname.c | 2 ++ 1 file changed, 2 insertions(+)
Quoted 14 lines
lib/errname.c static const char *names_0[] = { · line 174
Quoted 11 lines
lib/errname.c +2
-0@@ -169,7 +169,9 @@ static const char *names_0[] = {E (ECANCELED ),/* ECANCELLED */ E (EAGAIN ),/* EWOULDBLOCK */ E (ECONNREFUSED ),/* EREFUSED */ +#if EDEADLK != EDEADLOCK E(EDEADLK), /* EDEADLOCK */ +#endifThe comments suggest that duplicates are expected. Would it make sense to add similar conditions to the other three entries?
The other ones are always aliases, so there is no point in having an #ifdef. The reason we need to handle EDEADLK separately is that it's an alias on most architectures but not on on others, specifically mips, powerpc and sparc.
Arnd
Quoted 11 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
On most architectures, gcc -Wextra warns about the list of error numbers containing both EDEADLK and EDEADLOCK:
lib/errname.c:15:67: warning: initialized field overwritten [-Woverride-init]
15 | #define E(err) [err +BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = "-" #err
| ^~~lib/errname.c:172:2: note: in expansion of macro 'E'172 | E(EDEADLK), /* EDEADLOCK */ | ^
Quoted 9 lines
lib/errname.c:15:67: note: (near initialization for 'names_0[35]')
15 | #define E(err) [err +BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = "-" #err
| ^~~lib/errname.c:172:2: note: in expansion of macro 'E'172 | E(EDEADLK), /* EDEADLOCK */ | ^Make that line conditional on the two values being distinct.
NAK. That would end up using the "EDEADLOCK" string for the value 35 on those architectures where they are the same, despite EDEADLK being the by far the most used symbol. See the comments and original commit log, the placement of these is deliberate.
How about we do this instead?
From: Rasmus Villemoes <[email protected]>
The table of errno value->name contains a few duplicate entries since e.g. EDEADLK == EDEADLOCK on most architectures. For the known cases, the most used symbolic constant is listed last so that takes precedence - the idea being that if someone sees "can't do that:-EDEADLK" in dmesg, grepping for EDEADLK is more likely to find the place where that error was generated (grepping for "can't do that" will find the printk() that emitted it, but the source would often be a few calls down).
However, that means one gets
warning: initialized field overwritten [-Woverride-init]
when building with W=1. As the use of multiple initializers for the same entry here is quite deliberate, explicitly disable that warning for errname.o.
names")
--- lib/Makefile | 1 + 1 file changed, 1 insertion(+)
lib/Makefile +1 -0
@@ -224,6 +224,7 @@ obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o +CFLAGS_errname.o += $(call cc-disable-warning, override-init) obj-$(CONFIG_NLATTR) += nlattr.o
Signature · 1 line
2.23.0
Quoted 3 lines · Rasmus Villemoes
How about we do this instead?
From: Rasmus Villemoes <[email protected]>
Missed:
Subject: lib/errname.o: disable -Woverride-init
Quoted 38 lines
The table of errno
value->namecontains a few duplicate entries since e.g. EDEADLK == EDEADLOCK on most architectures. For the known cases, the most used symbolic constant is listed last so that takes precedence - the idea being that if someone sees "can't do that:-EDEADLK" in dmesg, grepping for EDEADLK is more likely to find the place where that error was generated (grepping for "can't do that" will find theprintk()that emitted it, but the source would often be a few calls down).However, that means one gets
warning: initialized field overwritten [-Woverride-init]
when building with W=1. As the use of multiple initializers for the same entry here is quite deliberate, explicitly disable that warning for errname.o.
Reported-by Arnd Bergmann <[email protected]>Fixes 57f5677e535b ("printf: add support for printing symbolic errornames")
Signed-off-by Rasmus Villemoes <[email protected]>--- lib/Makefile | 1 + 1 file changed, 1 insertion(+)lib/Makefile +1
-0@@ -224,6 +224,7 @@ obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o +CFLAGS_errname.o += $(call cc-disable-warning, override-init) obj-$(CONFIG_NLATTR) += nlattr.o
Signature · 8 lines
Rasmus Villemoes Software Developer Prevas A/S Hedeager 3 DK-8200 Aarhus N +45 51210274 [email protected] www.prevas.dk
Quoted 7 lines · Rasmus Villemoes
Quoted 1 line · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
NAK. That would end up using the "EDEADLOCK" string for the value 35 on those architectures where they are the same, despite EDEADLK being the by far the most used symbol. See the comments and original commit log, the placement of these is deliberate.
Ok, I see.
Quoted 34 lines
How about we do this instead?
From: Rasmus Villemoes <[email protected]>
The table of errno
value->namecontains a few duplicate entries since e.g. EDEADLK == EDEADLOCK on most architectures. For the known cases, the most used symbolic constant is listed last so that takes precedence - the idea being that if someone sees "can't do that:-EDEADLK" in dmesg, grepping for EDEADLK is more likely to find the place where that error was generated (grepping for "can't do that" will find theprintk()that emitted it, but the source would often be a few calls down).However, that means one gets
warning: initialized field overwritten [-Woverride-init]
when building with W=1. As the use of multiple initializers for the same entry here is quite deliberate, explicitly disable that warning for errname.o.
Reported-by Arnd Bergmann <[email protected]>Fixes 57f5677e535b ("printf: add support for printing symbolic errornames")
Signed-off-by Rasmus Villemoes <[email protected]>--- lib/Makefile | 1 + 1 file changed, 1 insertion(+)lib/Makefile +0
-0
lib/Makefile obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o · line 228
Quoted 5 lines
lib/Makefile +1
-0@@ -224,6 +224,7 @@ obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o +CFLAGS_errname.o += $(call cc-disable-warning, override-init)
This works, but it conflicts with a different patch series I have, and it disables a potentially useful warning in case we get another conflict in this file, so I'd prefer to find a way to avoid the warning rather than force-disabling it.
How about adding the #ifdef around the EDEADLOCK line instead of the EDEADLK one? Something like
lib/errname.c +3 -1
@@ -38,7 +38,10 @@ static const char *names_0[] = {E (ECOMM ),E (ECONNABORTED ),E (ECONNRESET ), +E (EDEADLK ),/* EDEADLOCK */ +#if EDEADLK != EDEADLOCK /* mips, sparc, powerpc */E (EDEADLOCK ), +#endifE (EDESTADDRREQ ),E (EDOM ), E(EDOTDOT),
@@ -169,7 +172,6 @@ static const char *names_0[] = {E (ECANCELED ),/* ECANCELLED */ E (EAGAIN ),/* EWOULDBLOCK */ E(ECONNREFUSED), /* EREFUSED */ - E(EDEADLK), /* EDEADLOCK */ };#undef E
Arnd
Quoted 9 lines · Arnd Bergmann
Quoted 7 lines · Rasmus Villemoes
Quoted 1 line · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
NAK. That would end up using the "EDEADLOCK" string for the value 35 on those architectures where they are the same, despite EDEADLK being the by far the most used symbol. See the comments and original commit log, the placement of these is deliberate.
Good point.
Quoted 14 lines
Ok, I see.
Quoted 12 lines
How about we do this instead?
when building with W=1. As the use of multiple initializers for the same entry here is quite deliberate, explicitly disable that warning for errname.o.
lib/Makefile +0
-0@@ -224,6 +224,7 @@ obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o
Quoted 8 lines
lib/Makefile obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o · line 228
Quoted 4 lines
lib/Makefile +1
-0obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o +CFLAGS_errname.o += $(call cc-disable-warning, override-init)This works, but it disables a potentially useful warning in case we get another conflict in this file, so I'd prefer to find a way to avoid the warning rather than force-disabling it.
Yeah, I think that it is better to explicitely disable the less used variant in the code than hiding the double initialization. It will be clear what is going on.
Quoted 19 lines
How about adding the #ifdef around the EDEADLOCK line instead of the EDEADLK one? Something like
lib/errname.c +3
-0@@ -38,7 +38,10 @@ static const char *names_0[] = {E (ECOMM ),E (ECONNABORTED ),E (ECONNRESET ), +E (EDEADLK ),/* EDEADLOCK */ +#if EDEADLK != EDEADLOCK /* mips, sparc, powerpc */E (EDEADLOCK ), +#endifE (EDESTADDRREQ ),E (EDOM ), E(EDOTDOT),
lib/errname.c static const char *names_0[] = { · line 172
Quoted 4 lines
lib/errname.c +0
-1@@ -169,7 +172,6 @@ static const char *names_0[] = {E (ECANCELED ),/* ECANCELLED */ E (EAGAIN ),/* EWOULDBLOCK */ E(ECONNREFUSED), /* EREFUSED */ - E(EDEADLK), /* EDEADLOCK */
This should stay :-)
And we should remove the ECANCELLED definition. It is always the same as ECANCELED and replaced. We do not define EWOULDBLOCK and EREFUSED either.
Best Regards,
Petr
Quoted 58 lines · Petr Mladek
Quoted 9 lines · Arnd Bergmann
Quoted 7 lines · Rasmus Villemoes
Quoted 1 line · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
NAK. That would end up using the "EDEADLOCK" string for the value 35 on those architectures where they are the same, despite EDEADLK being the by far the most used symbol. See the comments and original commit log, the placement of these is deliberate.
Good point.
Quoted 14 lines
Ok, I see.
Quoted 12 lines
How about we do this instead?
when building with W=1. As the use of multiple initializers for the same entry here is quite deliberate, explicitly disable that warning for errname.o.
lib/Makefile +0
-0@@ -224,6 +224,7 @@ obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.oQuoted 8 lines
lib/Makefile obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o · line 228
Quoted 4 lines
lib/Makefile +1
-0obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o +CFLAGS_errname.o += $(call cc-disable-warning, override-init)This works, but it disables a potentially useful warning in case we get another conflict in this file, so I'd prefer to find a way to avoid the warning rather than force-disabling it.
Yeah, I think that it is better to explicitely disable the less used variant in the code than hiding the double initialization. It will be clear what is going on.
Quoted 17 lines
How about adding the #ifdef around the EDEADLOCK line instead of the EDEADLK one? Something like
lib/errname.c +3
-0@@ -38,7 +38,10 @@ static const char *names_0[] = {E (ECOMM ),E (ECONNABORTED ),E (ECONNRESET ), +E (EDEADLK ),/* EDEADLOCK */ +#if EDEADLK != EDEADLOCK /* mips, sparc, powerpc */E (EDEADLOCK ), +#endifE (EDESTADDRREQ ), E(EDOM),
Quoted 9 lines
lib/errname.c static const char *names_0[] = { · line 172
Quoted 6 lines
lib/errname.c +0
-1E(EDOTDOT),@@ -169,7 +172,6 @@ static const char *names_0[] = {E (ECANCELED ),/* ECANCELLED */ E (EAGAIN ),/* EWOULDBLOCK */ E(ECONNREFUSED), /* EREFUSED */ - E(EDEADLK), /* EDEADLOCK */This should stay :-)
No, Arnd moved it next to EDEADLOCK, which is fine (it can lose the comment /* EDEADLOCK */, though; the comment on the ifdef is sufficient). Especially when:
Quoted 3 lines
And we should remove the ECANCELLED definition. It is always the same as ECANCELED and replaced. We do not define EWOULDBLOCK and EREFUSED either.
Yes, I'm not sure why I elided EWOULDBLOCK and EREFUSED but not ECANCELLED. So let's move EAGAIN, ECONNREFUSED and ECANCELED to their proper alphabetic place. But I also want to add a check that the things we've elided match some value that we do handle. So add something like
#ifdef EREFUSED /* parisc */static_assert(EREFUSED == ECONNREFUSED);
#endif
#ifdef ECANCELLED /* parisc */static_assert(ECANCELLED == ECANCELED);
#endif
static_assert(EAGAIN == EWOULDBLOCK); /* everywhere */
so that if we ever import some arch that defines EREFUSED to something other than ECONNREFUSED, it would be caught. Essentially, errname.c should mention every #define E* that appears in any errno*.h.
Rasmus
Quoted 90 lines · Rasmus Villemoes
Quoted 58 lines · Petr Mladek
Quoted 9 lines · Arnd Bergmann
Quoted 7 lines · Rasmus Villemoes
Quoted 1 line · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
NAK. That would end up using the "EDEADLOCK" string for the value 35 on those architectures where they are the same, despite EDEADLK being the by far the most used symbol. See the comments and original commit log, the placement of these is deliberate.
Good point.
Quoted 14 lines
Ok, I see.
Quoted 12 lines
How about we do this instead?
when building with W=1. As the use of multiple initializers for the same entry here is quite deliberate, explicitly disable that warning for errname.o.
lib/Makefile +0
-0@@ -224,6 +224,7 @@ obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.oQuoted 8 lines
lib/Makefile obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o · line 228
Quoted 4 lines
lib/Makefile +1
-0obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o +CFLAGS_errname.o += $(call cc-disable-warning, override-init)This works, but it disables a potentially useful warning in case we get another conflict in this file, so I'd prefer to find a way to avoid the warning rather than force-disabling it.
Yeah, I think that it is better to explicitely disable the less used variant in the code than hiding the double initialization. It will be clear what is going on.
Quoted 17 lines
How about adding the #ifdef around the EDEADLOCK line instead of the EDEADLK one? Something like
lib/errname.c +3
-0@@ -38,7 +38,10 @@ static const char *names_0[] = {E (ECOMM ),E (ECONNABORTED ),E (ECONNRESET ), +E (EDEADLK ),/* EDEADLOCK */ +#if EDEADLK != EDEADLOCK /* mips, sparc, powerpc */E (EDEADLOCK ), +#endifE (EDESTADDRREQ ), E(EDOM),Quoted 9 lines
lib/errname.c static const char *names_0[] = { · line 172
Quoted 6 lines
lib/errname.c +0
-1E(EDOTDOT),@@ -169,7 +172,6 @@ static const char *names_0[] = {E (ECANCELED ),/* ECANCELLED */ E (EAGAIN ),/* EWOULDBLOCK */ E(ECONNREFUSED), /* EREFUSED */ - E(EDEADLK), /* EDEADLOCK */This should stay :-)
No, Arnd moved it next to EDEADLOCK, which is fine (it can lose the comment /* EDEADLOCK */, though; the comment on the ifdef is sufficient). Especially when:
Quoted 3 lines
And we should remove the ECANCELLED definition. It is always the same as ECANCELED and replaced. We do not define EWOULDBLOCK and EREFUSED either.
Yes, I'm not sure why I elided EWOULDBLOCK and EREFUSED but not ECANCELLED. So let's move EAGAIN, ECONNREFUSED and ECANCELED to their proper alphabetic place. But I also want to add a check that the things we've elided match some value that we do handle. So add something like
#ifdef EREFUSED /* parisc */
static_assert(EREFUSED == ECONNREFUSED);
#endif#ifdef ECANCELLED /* parisc */
static_assert(ECANCELLED == ECANCELED);
#endif
Quoted 5 lines
static_assert(EAGAIN == EWOULDBLOCK); /* everywhere */so that if we ever import some arch that defines EREFUSED to something other than ECONNREFUSED, it would be caught. Essentially,
errname.cshould mention every #define E* that appears in any errno*.h.
Sounds like a good plan.
Arnd, are you going to take care of this or should we clean up it ourself?
Best Regards,
Petr