Skip to contentSkip to conversation

mdadm: fix gcc8 maybe-uninitialized/format-overflow warning

PATCH In review [email protected] 4 participants 10 messages Mar 12, 2019 – Mar 22, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mdadm: fix gcc8 maybe-uninitialized/format-overflow warning

From: Changqing Li <[email protected]>

while compiled with -Werror=maybe-uninitialized/-Werror=format-overflow=, it failed

[snip]

| Incremental.c: In function 'Incremental_container':
| Incremental.c:1593:3: error: 'mdfd' may be used uninitialized in this function [-Werror=maybe-uninitialized]
| close(mdfd);
| ^~~~~~~~~~~

[snip]
super-intel.c: In function 'apply_takeover_update':

| super-intel.c:9615:15: error: '%d' directive writing between 1 and 11 bytes into a region of size 7 [-Werror=format-overflow=]
| " MISSING_%d", du->index);
| ^~
---
 ...maybe-uninitialized-format-overflow-warni.patch | 60 ++++++++++++++++++++++
 meta/recipes-extended/mdadm/mdadm_4.1.bb           |  1 +
 2 files changed, 61 insertions(+)
 create mode 100644 meta/recipes-extended/mdadm/files/0001-mdadm-gcc8-maybe-uninitialized-format-overflow-warni.patch
meta/recipes-extended/mdadm/files/0001-mdadm-gcc8-maybe-uninitialized-format-overflow-warni.patch new file +60 -0
new file mode 100644
index 0000000..237f83a
@@ -0,0 +1,60 @@
+From bf457a83834932ba06de3528b8779a023e73fa7b Mon Sep 17 00:00:00 2001
+From: Changqing Li <[email protected]>
+Date: Tue, 12 Mar 2019 16:17:29 +0800
+Subject: [PATCH] mdadm: gcc8 maybe-uninitialized/format-overflow warning
+
+while compiled with -Werror=maybe-uninitialized/-Werror=format-overflow=,
+it failed
+
+[snip]
+| Incremental.c: In function 'Incremental_container':
+| Incremental.c:1593:3: error: 'mdfd' may be used uninitialized in this function [-Werror=maybe-uninitialized]
+| close(mdfd);
+| ^~~~~~~~~~~
+
+[snip]
+super-intel.c: In function 'apply_takeover_update':
+| super-intel.c:9615:15: error: '%d' directive writing between 1 and 11 bytes into a region of size 7 [-Werror=format-overflow=]
+| " MISSING_%d", du->index);
+| ^~
+
+Upstream-Status: Submitted [https://github.com/neilbrown/mdadm/pull/36]
+
+Signed-off-by: Changqing Li <[email protected]>
+---
+ Incremental.c | 2 +-
+ super-intel.c | 4 ++--
+ 2 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/Incremental.c b/Incremental.c
+index a4ff7d4..b667868 100644
+--- a/Incremental.c
++++ b/Incremental.c
+@@ -1500,7 +1500,7 @@ static int Incremental_container(struct supertype *st, char *devname,
+ 		return 0;
+ 	}
+ 	for (ra = list ; ra ; ra = ra->next) {
+-		int mdfd;
++		int mdfd = 0;
+ 		char chosen_name[1024];
+ 		struct map_ent *mp;
+ 		struct mddev_ident *match = NULL;
+diff --git a/super-intel.c b/super-intel.c
+index 10d7218..c3741ea 100644
+--- a/super-intel.c
++++ b/super-intel.c
+@@ -9612,9 +9612,9 @@ static int apply_takeover_update(struct imsm_update_takeover *u,
+ 			du->major = 0;
+ 			du->index = (i * 2) + 1;
+ 			sprintf((char *)du->disk.serial,
+-				" MISSING_%d", du->index);
++				" MISSING_%hu", du->index);
+ 			sprintf((char *)du->serial,
+-				"MISSING_%d", du->index);
++				"MISSING_%hu", du->index);
+ 			du->next = super->missing;
+ 			super->missing = du;
+ 		}
+-- 
+2.7.4
+
meta/recipes-extended/mdadm/mdadm_4.1.bb +1 -0
index 2d7ade6..d79c533 100644
@@ -19,6 +19,7 @@ SRC_URI = "${KERNELORG_MIRROR}/linux/utils/raid/mdadm/${BPN}-${PV}.tar.xz \
            file://0001-fix-gcc-8-format-truncation-warning.patch \
 	   file://mdadm.init \
 	   file://mdmonitor.service \
+           file://0001-mdadm-gcc8-maybe-uninitialized-format-overflow-warni.patch \
            "
 SRC_URI[md5sum] = "51bf3651bd73a06c413a2f964f299598"
 SRC_URI[sha256sum] = "ab7688842908d3583a704d491956f31324c3a5fc9f6a04653cb75d19f1934f4a"
Signature · 1 line
2.7.4
#1 lore raw
Quoted 11 lines · On Tue, Mar 12, 2019 at 05:41:58PM +0800, [email protected] wrote:

From: Changqing Li <[email protected]>

while compiled with -Werror=maybe-uninitialized/-Werror=format-overflow=, it failed

[snip]

| Incremental.c: In function 'Incremental_container':
| Incremental.c:1593:3: error: 'mdfd' may be used uninitialized in this function [-Werror=maybe-uninitialized]
| close(mdfd);
| ^~~~~~~~~~~
Quoted 6 lines

[snip]
super-intel.c: In function 'apply_takeover_update':

| super-intel.c:9615:15: error: '%d' directive writing between 1 and 11 bytes into a region of size 7 [-Werror=format-overflow=]
| " MISSING_%d", du->index);
| ^~

...

I am seeing these warnings only with -Og, are you also seeing them with -Og (DEBUG_OPTIMIZATION) only?

If this is true, I would consider
https://sources.debian.org/src/mdadm/4.1-2/debian/patches/debian-no-Werror.diff/
a better workaround.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#2 lore raw
Quoted 20 lines · Adrian Bunk
Quoted 11 lines · On Tue, Mar 12, 2019 at 05:41:58PM +0800, [email protected] wrote:

From: Changqing Li <[email protected]>

while compiled with -Werror=maybe-uninitialized/-Werror=format-overflow=, it failed

[snip]

| Incremental.c: In function 'Incremental_container':
| Incremental.c:1593:3: error: 'mdfd' may be used uninitialized in this function [-Werror=maybe-uninitialized]
| close(mdfd);
| ^~~~~~~~~~~
Quoted 6 lines

[snip]
super-intel.c: In function 'apply_takeover_update':

| super-intel.c:9615:15: error: '%d' directive writing between 1 and 11 bytes into a region of size 7 [-Werror=format-overflow=]
| " MISSING_%d", du->index);
| ^~

...

Quoted 7 lines

I am seeing these warnings only with -Og, are you also seeing them with -Og (DEBUG_OPTIMIZATION) only?

If this is true, I would consider
https://sources.debian.org/src/mdadm/4.1-2/debian/patches/debian-no-Werror.diff/
a better workaround.

This seems a broader brush, I really dont like to relegate Werror if we dont have to, because it will force us
to fix the code. However, I am seeing it fail with clang now

https://errors.yoctoproject.org/Errors/Details/233618/

Quoted 15 lines

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core

#3 lore raw
Quoted 24 lines · Khem Raj
Quoted 23 lines · Adrian Bunk
Quoted 11 lines · On Tue, Mar 12, 2019 at 05:41:58PM +0800, [email protected] wrote:

From: Changqing Li <[email protected]>

while compiled with -Werror=maybe-uninitialized/-Werror=format-overflow=, it failed

[snip]

| Incremental.c: In function 'Incremental_container':
| Incremental.c:1593:3: error: 'mdfd' may be used uninitialized in this function [-Werror=maybe-uninitialized]
| close(mdfd);
| ^~~~~~~~~~~
Quoted 6 lines

[snip]
super-intel.c: In function 'apply_takeover_update':

| super-intel.c:9615:15: error: '%d' directive writing between 1 and 11 bytes into a region of size 7 [-Werror=format-overflow=]
| " MISSING_%d", du->index);
| ^~

...

I am seeing these warnings only with -Og, are you also seeing them with -Og (DEBUG_OPTIMIZATION) only?

Quoted 7 lines
Quoted 4 lines

If this is true, I would consider
https://sources.debian.org/src/mdadm/4.1-2/debian/patches/debian-no-Werror.diff/
a better workaround.

This seems a broader brush, I really dont like to relegate Werror if we dont have to, because it will force us
to fix the code.

How are we getting such fixes properly reviewed?

What actually happens is that the easiest change that silences a warning gets applied.

And for such bogus -Og only warnings there was no problem in the code, meaning regression risks by OE/Yocto-only patches without fixing anything.

Quoted 3 lines

However, I am seeing it fail with clang now

https://errors.yoctoproject.org/Errors/Details/233618/

This is caused by the "fix" for the -Og gcc warning.

Which looks bogus, and might be harmful.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#4 lore raw
Quoted 34 lines · Adrian Bunk
Quoted 24 lines · Khem Raj
Quoted 23 lines · Adrian Bunk
Quoted 11 lines · On Tue, Mar 12, 2019 at 05:41:58PM +0800, [email protected] wrote:

From: Changqing Li <[email protected]>

while compiled with -Werror=maybe-uninitialized/-Werror=format-overflow=, it failed

[snip]

| Incremental.c: In function 'Incremental_container':
| Incremental.c:1593:3: error: 'mdfd' may be used uninitialized in this function [-Werror=maybe-uninitialized]
| close(mdfd);
| ^~~~~~~~~~~
Quoted 6 lines

[snip]
super-intel.c: In function 'apply_takeover_update':

| super-intel.c:9615:15: error: '%d' directive writing between 1 and 11 bytes into a region of size 7 [-Werror=format-overflow=]
| " MISSING_%d", du->index);
| ^~

...

I am seeing these warnings only with -Og, are you also seeing them with -Og (DEBUG_OPTIMIZATION) only?

Quoted 7 lines
Quoted 4 lines

If this is true, I would consider
https://sources.debian.org/src/mdadm/4.1-2/debian/patches/debian-no-Werror.diff/
a better workaround.

This seems a broader brush, I really dont like to relegate Werror if we dont have to, because it will force us
to fix the code.

Quoted 6 lines

How are we getting such fixes properly reviewed?

What actually happens is that the easiest change that silences a warning gets applied.

And for such bogus -Og only warnings there was no problem in the code,

so then probably a better fix is to add -Wno-error to DEBUG_FLAGS which will limit it to -Og case, and revert the original fix.

Quoted 9 lines

meaning regression risks by OE/Yocto-only patches without fixing anything.

Quoted 3 lines

However, I am seeing it fail with clang now

https://errors.yoctoproject.org/Errors/Details/233618/

This is caused by the "fix" for the -Og gcc warning.

Which looks bogus, and might be harmful.

I think that is right. the fix seems to be regressing on gcc 9 as well so it has to be done differently.

Quoted 11 lines

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

#5 lore raw
Quoted 61 lines · Khem Raj
Quoted 41 lines · Adrian Bunk
Quoted 31 lines · Khem Raj
Quoted 29 lines · Adrian Bunk
Quoted 14 lines · On Tue, Mar 12, 2019 at 05:41:58PM +0800, [email protected] wrote:

From: Changqing Li <[email protected]>

while compiled with -Werror=maybe-uninitialized/-
Werror=format-overflow=,
it failed

[snip]

Quoted 6 lines

Incremental.c: In function 'Incremental_container':
Incremental.c:1593:3: error: 'mdfd' may be used uninitialized in this function [-Werror=maybe- uninitialized]
close(mdfd);
^~~~~~~~~~~

Quoted 8 lines

[snip]
super-intel.c: In function 'apply_takeover_update':

Quoted 5 lines

super-intel.c:9615:15: error: '%d' directive writing between 1 and 11 bytes into a region of size 7 [- Werror=format-overflow=]
" MISSING_%d", du->index);
^~

...

I am seeing these warnings only with -Og, are you also seeing them with
-Og (DEBUG_OPTIMIZATION) only?

Quoted 8 lines
Quoted 4 lines

If this is true, I would consider
https://sources.debian.org/src/mdadm/4.1-2/debian/patches/debian-no-Werror.diff/
a better workaround.

This seems a broader brush, I really dont like to relegate Werror if
we dont have to, because it will force us
to fix the code.

Quoted 8 lines

How are we getting such fixes properly reviewed?

What actually happens is that the easiest change that silences a warning
gets applied.

And for such bogus -Og only warnings there was no problem in the code,

so then probably a better fix is to add -Wno-error to DEBUG_FLAGS which will limit it to -Og case, and revert the original fix.

Quoted 5 lines

meaning regression risks by OE/Yocto-only patches without fixing anything.

Quoted 2 lines

However, I am seeing it fail with clang now

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

https://errors.yoctoproject.org/Errors/Details/233618/

This is caused by the "fix" for the -Og gcc warning.

Which looks bogus, and might be harmful.

I think that is right. the fix seems to be regressing on gcc 9 as well so it has to be done differently.

Agreed, we should revert it, its creating more problems than it solves.

Cheers,

Richard

#6 lore raw
In reply to Khem Raj
Quoted 37 lines · Khem Raj
Quoted 36 lines · Adrian Bunk
Quoted 24 lines · Khem Raj
Quoted 23 lines · Adrian Bunk
Quoted 11 lines · On Tue, Mar 12, 2019 at 05:41:58PM +0800, [email protected] wrote:

From: Changqing Li <[email protected]>

while compiled with -Werror=maybe-uninitialized/-Werror=format-overflow=, it failed

[snip]

| Incremental.c: In function 'Incremental_container':
| Incremental.c:1593:3: error: 'mdfd' may be used uninitialized in this function [-Werror=maybe-uninitialized]
| close(mdfd);
| ^~~~~~~~~~~
Quoted 6 lines

[snip]
super-intel.c: In function 'apply_takeover_update':

| super-intel.c:9615:15: error: '%d' directive writing between 1 and 11 bytes into a region of size 7 [-Werror=format-overflow=]
| " MISSING_%d", du->index);
| ^~

...

I am seeing these warnings only with -Og, are you also seeing them with -Og (DEBUG_OPTIMIZATION) only?

Quoted 7 lines
Quoted 4 lines

If this is true, I would consider
https://sources.debian.org/src/mdadm/4.1-2/debian/patches/debian-no-Werror.diff/
a better workaround.

This seems a broader brush, I really dont like to relegate Werror if we dont have to, because it will force us
to fix the code.

How are we getting such fixes properly reviewed?

Quoted 7 lines
Quoted 4 lines

What actually happens is that the easiest change that silences a warning gets applied.

And for such bogus -Og only warnings there was no problem in the code,

so then probably a better fix is to add -Wno-error to DEBUG_FLAGS which will limit it to -Og case, and revert the original fix.

For mdadm this might work, for puzzles it would not.

Order matters, and upstream can insert your flags before or after the -Werror. So unfortunately this would not cover all recipes.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#7 lore raw
Quoted 44 lines · Adrian Bunk
Quoted 42 lines · Khem Raj
Quoted 40 lines · Adrian Bunk
Quoted 24 lines · Khem Raj
Quoted 23 lines · Adrian Bunk
Quoted 11 lines · On Tue, Mar 12, 2019 at 05:41:58PM +0800, [email protected] wrote:

From: Changqing Li <[email protected]>

while compiled with -Werror=maybe-uninitialized/-Werror=format-overflow=, it failed

[snip]

| Incremental.c: In function 'Incremental_container':
| Incremental.c:1593:3: error: 'mdfd' may be used uninitialized in this function [-Werror=maybe-uninitialized]
| close(mdfd);
| ^~~~~~~~~~~
Quoted 6 lines

[snip]
super-intel.c: In function 'apply_takeover_update':

| super-intel.c:9615:15: error: '%d' directive writing between 1 and 11 bytes into a region of size 7 [-Werror=format-overflow=]
| " MISSING_%d", du->index);
| ^~

...

I am seeing these warnings only with -Og, are you also seeing them with -Og (DEBUG_OPTIMIZATION) only?

Quoted 7 lines
Quoted 4 lines

If this is true, I would consider
https://sources.debian.org/src/mdadm/4.1-2/debian/patches/debian-no-Werror.diff/
a better workaround.

This seems a broader brush, I really dont like to relegate Werror if we dont have to, because it will force us
to fix the code.

How are we getting such fixes properly reviewed?

What actually happens is that the easiest change that silences a warning gets applied.

And for such bogus -Og only warnings there was no problem in the code,

Quoted 8 lines
Quoted 2 lines

so then probably a better fix is to add -Wno-error to DEBUG_FLAGS which will limit it to -Og case, and revert the original fix.

For mdadm this might work, for puzzles it would not.

Order matters, and upstream can insert your flags before or after the -Werror. So unfortunately this would not cover all recipes.

suggestion was not global, but just for this recipe. I still would suggest that we disable it only where needed

Quoted 10 lines

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

#8 lore raw
Quoted 17 lines · Khem Raj
Quoted 16 lines · Adrian Bunk
Quoted 15 lines · Khem Raj
Quoted 14 lines · Adrian Bunk
Quoted 13 lines · Khem Raj
Quoted 12 lines · Adrian Bunk
Quoted 11 lines · On Tue, Mar 12, 2019 at 05:41:58PM +0800, [email protected] wrote:

From: Changqing Li <[email protected]>

while compiled with -Werror=maybe-uninitialized/-Werror=format-overflow=, it failed

[snip]

| Incremental.c: In function 'Incremental_container':
| Incremental.c:1593:3: error: 'mdfd' may be used uninitialized in this function [-Werror=maybe-uninitialized]
| close(mdfd);
| ^~~~~~~~~~~
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

[snip]
super-intel.c: In function 'apply_takeover_update':

| super-intel.c:9615:15: error: '%d' directive writing between 1 and 11 bytes into a region of size 7 [-Werror=format-overflow=]
| " MISSING_%d", du->index);
| ^~

...

I am seeing these warnings only with -Og, are you also seeing them with -Og (DEBUG_OPTIMIZATION) only?

yes.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

If this is true, I would consider
https://sources.debian.org/src/mdadm/4.1-2/debian/patches/debian-no-Werror.diff/
a better workaround.

This seems a broader brush, I really dont like to relegate Werror if we dont have to, because it will force us
to fix the code.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

How are we getting such fixes properly reviewed?

What actually happens is that the easiest change that silences a warning gets applied.

And for such bogus -Og only warnings there was no problem in the code,

so then probably a better fix is to add -Wno-error to DEBUG_FLAGS which will limit it to -Og case, and revert the original fix.

Both DEBUG_OPTIMIZATION and FULL_OPTIMIZATION appended DEBUG_FLAGS.

in order limit it to -Og case,  I will add  -Wno-error to DEBUG_OPTIMIZATION, and send a v2.

[snip]

FULL_OPTIMIZATION = "-O2 -pipe ${DEBUG_FLAGS}"

DEBUG_OPTIMIZATION = "-Og ${DEBUG_FLAGS} -pipe"

SELECTED_OPTIMIZATION = "${@d.getVar(oe.utils.vartrue('DEBUG_BUILD', 'DEBUG_OPTIMIZATION', 'FULL_OPTIMIZATION', d))}"

Quoted 18 lines
Quoted 5 lines

For mdadm this might work, for puzzles it would not.

Order matters, and upstream can insert your flags before or after the -Werror. So unfortunately this would not cover all recipes.

suggestion was not global, but just for this recipe. I still would suggest that we disable it only where needed

Quoted 10 lines

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

Signature · 3 lines
BRs

Sandy(Li Changqing)
#9 lore raw

PATCH v2 1/1 mdadm: add -Wno-error to DEBUG_OPTIMIZATION

In reply to Khem Raj

From: Changqing Li <[email protected]>

when compile with DEBUG_OPTIMIZATION(-Og), compile failed with below error, fix by add -Wno-error:

[snip]

| Incremental.c: In function 'Incremental_container':
| Incremental.c:1593:3: error: 'mdfd' may be used uninitialized in this function [-Werror=maybe-uninitialized]
| close(mdfd);
| ^~~~~~~~~~~

[snip]
super-intel.c: In function 'apply_takeover_update':

| super-intel.c:9615:15: error: '%d' directive writing between 1 and 11 bytes into a region of size 7 [-Werror=format-overflow=]
| " MISSING_%d", du->index);
| ^~

...

---
 meta/recipes-extended/mdadm/mdadm_4.1.bb | 2 ++
 1 file changed, 2 insertions(+)
meta/recipes-extended/mdadm/mdadm_4.1.bb +2 -0
index d79c533..ab3ea41 100644
@@ -41,6 +41,8 @@ CFLAGS_append_mipsarchn32 = ' -D__SANE_USERSPACE_TYPES__'
 
 EXTRA_OEMAKE = 'CHECK_RUN_DIR=0 CXFLAGS="${CFLAGS}"'
 
+DEBUG_OPTIMIZATION_append = " -Wno-error"
+
 do_compile() {
 	# Point to right sbindir
 	sed -i -e "s;BINDIR  = /sbin;BINDIR = $base_sbindir;" -e "s;UDEVDIR = /lib;UDEVDIR = $nonarch_base_libdir;" ${S}/Makefile
Signature · 1 line
2.7.4