(Userspace Tools) Fix a compilation error with -fstack-protector and -Werror
PATCH 1/1 (Userspace Tools) Fix a compilation error with -fstack-protector and -Werror
The following patch fixes compilation of the perf user-space tools on, for example, gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) . It should not break anything else.
--- tools/perf/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/Makefile +1 -2
@@ -288,7 +288,7 @@ endif -include feature-tests.mak ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -fstack-protector-all),y) - CFLAGS := $(CFLAGS) -fstack-protector-all + CFLAGS := $(CFLAGS) -fstack-protector-all --param ssp-buffer-size=1 endif --
Brian Gitonga Marete
Toshnix Systems
Tel: +254722151590
Quoted 3 lines · Brian Gitonga Marete
The following patch fixes compilation of the perf user-space tools on, for example, gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) . It should not break anything else.
Hi,
What kind of warning have you encountered and why it fixes it? Can you describe that in your changelog?
Thanks.
Quoted 27 lines
Signed-off-by Brian Gitonga Marete <[email protected]>--- tools/perf/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)tools/perf/Makefile +1
-2@@ -288,7 +288,7 @@ endif -include feature-tests.mak ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -fstack-protector-all),y) - CFLAGS := $(CFLAGS) -fstack-protector-all + CFLAGS := $(CFLAGS) -fstack-protector-all --param ssp-buffer-size=1 endif --Brian Gitonga Marete
Toshnix Systems
Tel: +254722151590
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 7 lines · Frederic Weisbecker
Quoted 3 lines · Brian Gitonga Marete
The following patch fixes compilation of the perf user-space tools on, for example, gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) . It should not break anything else.
Quoted 5 lines
Hi,
What kind of warning have you encountered and why it fixes it? Can you describe that in your changelog?
Hello Frederic,
Some versions of gcc, e.g. gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4), have the (default) minimum size of buffers protected by `-fstack-protector' set to 8. But in perf, there exist much smaller automatic buffers.
This in combination with the -fstack-protector-all, -Werror and -Wstack-protector causes the compile to fail for such a compiler.
The error encountered with the above-mentioned compiler is:
gcc -o util/ui/util.o -c -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wformat-y2k -Wshadow -Winit-self -Wpacked -Wredundant-decls -Wstack-protector -Wstrict-aliasing=3 -Wswitch-default -Wswitch-enum -Wno-system-headers -Wundef -Wvolatile-register-var -Wwrite-strings -Wbad-function-cast -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wstrict-prototypes -Wdeclaration-after-statement -fstack-protector-all -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Iutil/include -Iarch/x86/include -DLIBELF_NO_MMAP -I/usr/include/elfutils -DDWARF_SUPPORT -I/usr/include/slang -DSHA1_HEADER='<openssl/sha.h>' util/ui/util.c
cc1: warnings being treated as errorsutil/ui/util.c: In function ‘ui__dialog_yesno’:util/ui/util.c:110: error: not protecting function: no buffer at least 8 bytes long
--- tools/perf/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/Makefile +1 -1
@@ -288,7 +288,7 @@ endif -include feature-tests.mak ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -fstack-protector-all),y) - CFLAGS := $(CFLAGS) -fstack-protector-all + CFLAGS := $(CFLAGS) -fstack-protector-all --param ssp-buffer-size=1 endif
Signature · 7 lines
1.6.0.4 -- Brian Gitonga Marete Toshnix Systems Tel: +254722151590
Frederic Weisbecker
Tested-byQuoted 36 lines · Brian Gitonga Marete
Quoted 7 lines · Frederic Weisbecker
Quoted 3 lines · Brian Gitonga Marete
The following patch fixes compilation of the perf user-space tools on, for example, gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) . It should not break anything else.
Quoted 5 lines
Hi,
What kind of warning have you encountered and why it fixes it? Can you describe that in your changelog?
Hello Frederic,
Some versions of gcc, e.g. gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4), have the (default) minimum size of buffers protected by `-fstack-protector' set to 8. But in perf, there exist much smaller automatic buffers.
This in combination with the -fstack-protector-all, -Werror and -Wstack-protector causes the compile to fail for such a compiler.
The error encountered with the above-mentioned compiler is:
gcc -o
util/ui/util.o-c -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6(quoted diff) +0
-10-D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wformat-y2k -Wshadow -Winit-self -Wpacked -Wredundant-decls -Wstack-protector -Wstrict-aliasing=3 -Wswitch-default -Wswitch-enum -Wno-system-headers -Wundef -Wvolatile-register-var -Wwrite-strings -Wbad-function-cast -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wstrict-prototypes -Wdeclaration-after-statement -fstack-protector-all -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Iutil/include -Iarch/x86/include -DLIBELF_NO_MMAP -I/usr/include/elfutils -DDWARF_SUPPORT -I/usr/include/slang -DSHA1_HEADER='<openssl/sha.h>'
Quoted 5 lines
util/ui/util.c
cc1: warnings being treated as errorsutil/ui/util.c: In function ‘ui__dialog_yesno’:util/ui/util.c:110: error: not protecting function: no buffer at least 8 bytes long
Doh! So that was the reason of this warning. Yeah looks like a right fix. And that fixes the issue for me.
Thanks!
Quoted 27 lines
Signed-off-by Brian Gitonga Marete <[email protected]>--- tools/perf/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)tools/perf/Makefile +1
-1@@ -288,7 +288,7 @@ endif -include feature-tests.mak ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -fstack-protector-all),y) - CFLAGS := $(CFLAGS) -fstack-protector-all + CFLAGS := $(CFLAGS) -fstack-protector-all --param ssp-buffer-size=1 endifSignature · 7 lines
1.6.0.4 -- Brian Gitonga Marete Toshnix Systems Tel: +254722151590
Quoted 14 lines · Brian Gitonga Marete
Quoted 7 lines · Frederic Weisbecker
Quoted 3 lines · Brian Gitonga Marete
The following patch fixes compilation of the perf user-space tools on, for example, gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) . It should not break anything else.
Quoted 5 lines
Hi,
What kind of warning have you encountered and why it fixes it? Can you describe that in your changelog?
Quoted 5 lines
Hello Frederic,
Some versions of gcc, e.g. gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4), have the (default) minimum size of buffers protected by `-fstack-protector' set to 8. But in perf, there exist much smaller automatic buffers.
Hm, it's this code:
/* newtWinChoice should really be accepting const char pointers... */
char yes[] = "Yes", no[] = "No";
return newtWinChoice(NULL, yes, no, (char *)msg) == 1;I.e. the code is messy and GCC is right to warn about it. Hence it would be somewhat bad to actually remove the warning that pointed out some dodgy piece of code.
Even if marking it const doesnt work due to the external libnewt API, we could at least put 'yes' and 'no' into file scope and mark them static?
Ingo
Quoted 23 lines · Ingo Molnar
Quoted 14 lines · Brian Gitonga Marete
Quoted 7 lines · Frederic Weisbecker
Quoted 3 lines · Brian Gitonga Marete
The following patch fixes compilation of the perf user-space tools on, for example, gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) . It should not break anything else.
Quoted 5 lines
Hi,
What kind of warning have you encountered and why it fixes it? Can you describe that in your changelog?
Quoted 5 lines
Hello Frederic,
Some versions of gcc, e.g. gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4), have the (default) minimum size of buffers protected by `-fstack-protector' set to 8. But in perf, there exist much smaller automatic buffers.
Quoted 8 lines
Hm, it's this code:
/* newtWinChoice should really be accepting const char pointers... */ char yes[] = "Yes", no[] = "No"; return newtWinChoice(NULL, yes, no, (char *)msg) == 1;I.e. the code is messy and GCC is right to warn about it. Hence it would be somewhat bad to actually remove the warning that pointed out some dodgy piece of code.
Agreed.
Quoted 4 lines
Even if marking it const doesnt work due to the external libnewt API, we could at least put 'yes' and 'no' into file scope and mark them static?
How about making ui__dialog_yesno() a macro? ;) Like:
#define ui__dialog_yesno(msg) \
({newWinChoice(NULL, "Yes", "No", (char *)(msg)) == 1;})Quoted 29 lines · Ingo Molnar
Quoted 14 lines · Brian Gitonga Marete
Quoted 7 lines · Frederic Weisbecker
Quoted 3 lines · Brian Gitonga Marete
The following patch fixes compilation of the perf user-space tools on, for example, gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) . It should not break anything else.
Quoted 5 lines
Hi,
What kind of warning have you encountered and why it fixes it? Can you describe that in your changelog?
Quoted 5 lines
Hello Frederic,
Some versions of gcc, e.g. gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4), have the (default) minimum size of buffers protected by `-fstack-protector' set to 8. But in perf, there exist much smaller automatic buffers.
Hm, it's this code:
/* newtWinChoice should really be accepting const char pointers... */ char yes[] = "Yes", no[] = "No";
returnnewtWinChoice(NULL, yes, no, (char *)msg)== 1;
Quoted 5 lines
I.e. the code is messy and GCC is right to warn about it. Hence it would be somewhat bad to actually remove the warning that pointed out some dodgy piece of code.
Even if marking it const doesnt work due to the external libnewt API, we could at least put 'yes' and 'no' into file scope and mark them static?
OK. Now that I actually look closely at that fragment I can see its useless to create the automatic arrays. Local string literals would also work (i.e. just pass "Yes"' and "No"' to newtWinChoice). But can also do what you suggested if it is anticipated that they will be used somewhere else within the file at some other time -- Currently they are not.
Thanks.
Signature · 3 lines
Brian Gitonga Marete Toshnix Systems Tel: +254722151590
Quoted 36 lines · Brian Gitonga Marete
Quoted 29 lines · Ingo Molnar
Quoted 14 lines · Brian Gitonga Marete
Quoted 7 lines · Frederic Weisbecker
Quoted 3 lines · Brian Gitonga Marete
The following patch fixes compilation of the perf user-space tools on, for example, gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) . It should not break anything else.
Quoted 5 lines
Hi,
What kind of warning have you encountered and why it fixes it? Can you describe that in your changelog?
Quoted 5 lines
Hello Frederic,
Some versions of gcc, e.g. gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4), have the (default) minimum size of buffers protected by `-fstack-protector' set to 8. But in perf, there exist much smaller automatic buffers.
Hm, it's this code:
/* newtWinChoice should really be accepting const char pointers... */ char yes[] = "Yes", no[] = "No";
returnnewtWinChoice(NULL, yes, no, (char *)msg)== 1;Quoted 5 lines
I.e. the code is messy and GCC is right to warn about it. Hence it would be somewhat bad to actually remove the warning that pointed out some dodgy piece of code.
Even if marking it const doesnt work due to the external libnewt API, we could at least put 'yes' and 'no' into file scope and mark them static?
Quoted 7 lines
OK. Now that I actually look closely at that fragment I can see its useless to create the automatic arrays. Local string literals would also work (i.e. just pass
"Yes"' and"No"' to newtWinChoice). But can also do what you suggested if it is anticipated that they will be used somewhere else within the file at some other time -- Currently they are not.
Oops. Sorry. What I suggested won't work because of the -Wwrite-strings default option. Which actually makes me understand why the original author of the code made it the way it is. Your suggestion of file-scope, static does solve the problem.
Signature · 3 lines
Brian Gitonga Marete Toshnix Systems Tel: +254722151590
Quoted 46 lines · Brian Gitonga Marete
Quoted 36 lines · Brian Gitonga Marete
Quoted 29 lines · Ingo Molnar
Quoted 14 lines · Brian Gitonga Marete
Quoted 7 lines · Frederic Weisbecker
Quoted 3 lines · Brian Gitonga Marete
The following patch fixes compilation of the perf user-space tools on, for example, gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) . It should not break anything else.
Quoted 5 lines
Hi,
What kind of warning have you encountered and why it fixes it? Can you describe that in your changelog?
Quoted 5 lines
Hello Frederic,
Some versions of gcc, e.g. gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4), have the (default) minimum size of buffers protected by `-fstack-protector' set to 8. But in perf, there exist much smaller automatic buffers.
Hm, it's this code:
/* newtWinChoice should really be accepting const char pointers... */ char yes[] = "Yes", no[] = "No";
returnnewtWinChoice(NULL, yes, no, (char *)msg)== 1;Quoted 5 lines
I.e. the code is messy and GCC is right to warn about it. Hence it would be somewhat bad to actually remove the warning that pointed out some dodgy piece of code.
Even if marking it const doesnt work due to the external libnewt API, we could at least put 'yes' and 'no' into file scope and mark them static?
Quoted 7 lines
OK. Now that I actually look closely at that fragment I can see its useless to create the automatic arrays. Local string literals would also work (i.e. just pass
"Yes"' and"No"' to newtWinChoice). But can also do what you suggested if it is anticipated that they will be used somewhere else within the file at some other time -- Currently they are not.
Quoted 5 lines
Oops. Sorry. What I suggested won't work because of the -Wwrite-strings default option. Which actually makes me understand why the original author of the code made it the way it is. Your suggestion of file-scope, static does solve the problem.
As indeed does Americo's suggestion above.
Signature · 3 lines
Brian Gitonga Marete Toshnix Systems Tel: +254722151590
Quoted 10 lines · Brian Gitonga Marete
Quoted 5 lines
OK. Now that I actually look closely at that fragment I can see its useless to create the automatic arrays. Local string literals would also work (i.e. just pass
"Yes"' and"No"' to newtWinChoice). But can also do what you suggested if it is anticipated that they will be used somewhere else within the file at some other time -- Currently they are not.Oops. Sorry. What I suggested won't work because of the -Wwrite-strings default option. Which actually makes me understand why the original author of the code made it the way it is. Your suggestion of file-scope, static does solve the problem.
Btw., -Wwrite-strings has proven to be a really useful warning in practice, in that it ensured that we propagate string immutability/const-ness as widely as possible. This resulted is cleaner perf code in the long run.
Here we cannot fix the Newt prototype (it's an existing library outside of our control) to take a const so we have to do the (mild) workaround of moving it to file scope. (if this becomes common then we'd have to re-evaluate the use of this warning)
I think Arnaldo has plans to get rid of the libnewt dependency altogether - that might be a fix too.
Thanks,
Ingo
Em Tue, Oct 19, 2010 at 01:49:04PM +0200, Ingo Molnar escreveu:
Quoted 18 lines · Brian Gitonga Marete
Quoted 11 lines
Quoted 6 lines
OK. Now that I actually look closely at that fragment I can see its useless to create the automatic arrays. Local string literals would also work (i.e. just pass
"Yes"' and"No"' to newtWinChoice). But can also do what you suggested if it is anticipated that they will be used somewhere else within the file at some other time -- Currently they are not.Oops. Sorry. What I suggested won't work because of the -Wwrite-strings default option. Which actually makes me understand why the original author of the code made it the way it is. Your suggestion of file-scope, static does solve the problem.
Btw., -Wwrite-strings has proven to be a really useful warning in practice, in that it ensured that we propagate string immutability/const-ness as widely as possible. This resulted is cleaner perf code in the long run.
Quoted 7 lines
Here we cannot fix the Newt prototype (it's an existing library outside of our control) to take a const so we have to do the (mild) workaround of moving it to file scope. (if this becomes common then we'd have to re-evaluate the use of this warning)
I think Arnaldo has plans to get rid of the libnewt dependency altogether - that might be a fix too.
Yeah, but for now I'll just reap the results of this long discussion about this issue. :)
- Arnaldo
PATCH 1/1 Fix a compile error with -fstack-protector, -Wstack-protector and -Werror.
The following is as per Ingo's suggestion. Agains 2.6.36. Thanks.
In the function ui__dialog_yesno(), automatic buffers have to be used as long as we are compiling perf with the -Wwrite-stings and -Werror options. This is because the Newt library does not declare the string parameters in newtWinChoice() as constant when it should.
But the automatic buffers are not large enough to benefit from ssp at least on some gcc versions, e.g. the one that comes with Ubuntu 9.0.4. This along with -Wstack-protector causes a compile warning which is turned into an error by -Werror.
This patch works around this problem by making the buffers global and static.
--- tools/perf/util/ui/util.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
tools/perf/util/ui/util.c +3 -1
@@ -11,6 +11,9 @@#include "helpline.h" #include "util.h" +static char yes[] ="Yes" ; +static char no[] ="No" ; +newtComponent newt_form__new (void );static void newt_form__set_exit_keys (newtComponent self)
@@ -109,6 +112,5 @@ out_destroy_form:bool ui__dialog_yesno (const char *msg) {/* newtWinChoice should really be accepting const char pointers... */ -char yes[] ="Yes" , no[] ="No" ;return newtWinChoice (NULL , yes, no, (char *)msg) ==1 ; }
Signature · 1 line
1.7.1.1
Le mardi 19 octobre 2010 à 11:11 -0200, Arnaldo Carvalho de Melo a écrit :
Quoted 24 lines
Em Tue, Oct 19, 2010 at 01:49:04PM +0200, Ingo Molnar escreveu:
Quoted 23 lines · Brian Gitonga Marete
Quoted 11 lines
Quoted 6 lines
OK. Now that I actually look closely at that fragment I can see its useless to create the automatic arrays. Local string literals would also work (i.e. just pass
"Yes"' and"No"' to newtWinChoice). But can also do what you suggested if it is anticipated that they will be used somewhere else within the file at some other time -- Currently they are not.Oops. Sorry. What I suggested won't work because of the -Wwrite-strings default option. Which actually makes me understand why the original author of the code made it the way it is. Your suggestion of file-scope, static does solve the problem.
Btw., -Wwrite-strings has proven to be a really useful warning in practice, in that it ensured that we propagate string immutability/const-ness as widely as possible. This resulted is cleaner perf code in the long run.
Here we cannot fix the Newt prototype (it's an existing library outside of our control) to take a const so we have to do the (mild) workaround of moving it to file scope. (if this becomes common then we'd have to re-evaluate the use of this warning)
Quoted 6 lines
Quoted 2 lines
I think Arnaldo has plans to get rid of the libnewt dependency altogether - that might be a fix too.
Yeah, but for now I'll just reap the results of this long discussion about this issue. :)
Hi Arnaldo
Sorry if I missed something, but current linux-2.6 tree has the problem.
Is the fix under control ?
Thanks !
Em Thu, Nov 11, 2010 at 11:25:35AM +0100, Eric Dumazet escreveu:
Quoted 5 lines
Hi Arnaldo
Sorry if I missed something, but current linux-2.6 tree has the problem.
Is the fix under control ?
Ingo merged this while I'm away, its in tip/urgent.
commit a3da8e451321c31d88cebd12c234d0aac2a1cc35
Author: Cyrill Gorcunov <[email protected]> Date: Sat Nov 6 11:47:24 2010 +0300
perf, ui: Eliminate stack-smashing protection compiler complaint
- Arnaldo
Le jeudi 11 novembre 2010 à 12:05 -0500, Arnaldo Carvalho de Melo a écrit :
Quoted 1 line
Ingo merged this while I'm away, its in tip/urgent.
So far so good ;)
Thanks !