Skip to contentSkip to conversation

add -Werror-implicit-function-declaration to CFLAGS

PATCH In review Adrian Bunk 7 participants 11 messages Jul 6, 2006 – Jul 7, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add -Werror-implicit-function-declaration to CFLAGS

Currently, using an undeclared function gives a compile warning, but it can lead to a nasty to debug runtime stack corruptions if the prototype of the function is different from what gcc guessed.

With -Werror-implicit-function-declaration we are getting an immediate compile error instead.

---

 Makefile                               |    3 ++-
 drivers/input/joystick/iforce/Makefile |    2 --
 2 files changed, 2 insertions(+), 3 deletions(-)
Makefile renamed from Makefile.old +2 -1
@@ -318,7 +318,8 @@
 CPPFLAGS        := -D__KERNEL__ $(LINUXINCLUDE)
 
 CFLAGS          := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
-                   -fno-strict-aliasing -fno-common
+                   -fno-strict-aliasing -fno-common \
+		   -Werror-implicit-function-declaration
 # Force gcc to behave correct even for buggy distributions
 CFLAGS          += $(call cc-option, -fno-stack-protector-all \
                                      -fno-stack-protector)
drivers/input/joystick/iforce/Makefile renamed from drivers/input/joystick/iforce/Makefile.old +0 -2
@@ -16,5 +16,3 @@
 ifeq ($(CONFIG_JOYSTICK_IFORCE_USB),y)
 	iforce-objs += iforce-usb.o
 endif
-
-EXTRA_CFLAGS = -Werror-implicit-function-declaration
#1 lore raw
Quoted 9 lines · Adrian Bunk

Currently, using an undeclared function gives a compile warning, but it can lead to a nasty to debug runtime stack corruptions if the prototype of the function is different from what gcc guessed.

With -Werror-implicit-function-declaration we are getting an immediate compile error instead.

Makes good sense. It gets my vote.
Thanks Adrian.

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#2 lore raw
In reply to Adrian Bunk
Quoted 8 lines · Adrian Bunk

Currently, using an undeclared function gives a compile warning, but it can lead to a nasty to debug runtime stack corruptions if the prototype of the function is different from what gcc guessed.

With -Werror-implicit-function-declaration we are getting an immediate compile error instead.

I've been carrying pretty much the same patch in Fedora for months, and making sure it still builds across x86/x86-64/s390/ia64/ppc32/ppc64. It saves a lot of time when you're building a large heavily modular kernel. (like that from a distro config say)

Signature · 1 line
http://www.codemonkey.org.uk
#3 lore raw
In reply to Adrian Bunk
Quoted 6 lines · Adrian Bunk

Currently, using an undeclared function gives a compile warning, but it can lead to a nasty to debug runtime stack corruptions if the prototype of the function is different from what gcc guessed.

With -Werror-implicit-function-declaration we are getting an immediate compile error instead.

This patch broke (-rc1):

sparc allnoconfig build
ia64 allnoconfig build
ppc64 allnoconfig build

x86_64 succeded an allnoconfig build

I did not try other architectures. We need to fix the allnoconfig cases at least for the popular architectures before applying this patch otherwise it will create too much trouble/noise.

linux-arch copied in the hope that the arch maintaines may try it out and fix their issues.

Sam

---

 Makefile                               |    3 ++-
 drivers/input/joystick/iforce/Makefile |    2 --
 2 files changed, 2 insertions(+), 3 deletions(-)
Makefile renamed from Makefile.old +2 -1
@@ -318,7 +318,8 @@
 CPPFLAGS        := -D__KERNEL__ $(LINUXINCLUDE)
 
 CFLAGS          := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
-                   -fno-strict-aliasing -fno-common
+                   -fno-strict-aliasing -fno-common \
+		   -Werror-implicit-function-declaration
 # Force gcc to behave correct even for buggy distributions
 CFLAGS          += $(call cc-option, -fno-stack-protector-all \
                                      -fno-stack-protector)
drivers/input/joystick/iforce/Makefile renamed from drivers/input/joystick/iforce/Makefile.old +0 -2
@@ -16,5 +16,3 @@
 ifeq ($(CONFIG_JOYSTICK_IFORCE_USB),y)
 	iforce-objs += iforce-usb.o
 endif
-
-EXTRA_CFLAGS = -Werror-implicit-function-declaration
#4 lore raw
Quoted 4 lines · Sam Ravnborg
Quoted 2 lines · Adrian Bunk

With -Werror-implicit-function-declaration we are getting an immediate compile error instead.

This patch broke (-rc1):

...

Quoted 3 lines

I did not try other architectures. We need to fix the allnoconfig cases at least for the popular architectures before applying this patch otherwise it will create too much trouble/noise.

What source files did it break on, and with what error message? And is there a reason to focus on 'allnoconfig', or do the other canned config targets (allyes, allmod, rand, and so on) matter too?

#5 lore raw
Quoted 5 lines · On Fri, Jul 07, 2006 at 01:02:18AM -0400, [email protected] wrote:
Quoted 4 lines · Sam Ravnborg
Quoted 2 lines · Adrian Bunk

With -Werror-implicit-function-declaration we are getting an immediate compile error instead.

This patch broke (-rc1):

Quoted 8 lines

...

Quoted 3 lines

I did not try other architectures. We need to fix the allnoconfig cases at least for the popular architectures before applying this patch otherwise it will create too much trouble/noise.

What source files did it break on, and with what error message? And is there a reason to focus on 'allnoconfig', or do the other canned config targets (allyes, allmod, rand, and so on) matter too?

The other configs matters too - but it just seemed most logical to start out with the config that deselected the most.
One could say that passing 'allnoconfig' was the minimal test.

The error messages follows (for ia64, sparc and ppc64). I have not tried to fix any of them.

Sam

make -C /home/sam/kernel/kbuild.git O=/home/sam/kernel/oia64
Using /home/sam/kernel/kbuild.git as source for kernel

  GEN     /home/sam/kernel/oia64/Makefile
  CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h
  CC      arch/ia64/kernel/asm-offsets.s
In file included from /home/sam/kernel/kbuild.git/include/linux/poll.h:11,
                 from /home/sam/kernel/kbuild.git/include/linux/rtc.h:113,
                 from /home/sam/kernel/kbuild.git/include/linux/efi.h:19,
                 from include2/asm/sal.h:40,
                 from /home/sam/kernel/kbuild.git/include/asm-ia64/mca.h:20,
                 from /home/sam/kernel/kbuild.git/arch/ia64/kernel/asm-offsets.c:15:
/home/sam/kernel/kbuild.git/include/linux/mm.h: In function `lowmem_page_address':
/home/sam/kernel/kbuild.git/include/linux/mm.h:530: error: implicit declaration of function `page_to_pfn'
In file included from /home/sam/kernel/kbuild.git/include/linux/poll.h:12,
                 from /home/sam/kernel/kbuild.git/include/linux/rtc.h:113,
                 from /home/sam/kernel/kbuild.git/include/linux/efi.h:19,
                 from include2/asm/sal.h:40,
                 from /home/sam/kernel/kbuild.git/include/asm-ia64/mca.h:20,
                 from /home/sam/kernel/kbuild.git/arch/ia64/kernel/asm-offsets.c:15:

include2/asm/uaccess.h: In function `xlate_dev_mem_ptr':
include2/asm/uaccess.h:374: error: implicit declaration of function pfn_to_page' include2/asm/uaccess.h:374: warning: assignment makes pointer from integer without a cast include2/asm/uaccess.h: In function xlate_dev_kmem_ptr':
include2/asm/uaccess.h:392: warning: assignment makes pointer from integer without a cast make[3]: *** [arch/ia64/kernel/asm-offsets.s] Error 1
make[2]: *** [prepare0] Error 2
make[1]: *** [_all] Error 2
make: *** [all] Error 2

make -C /home/sam/kernel/kbuild.git O=/home/sam/kernel/oia64
Using /home/sam/kernel/kbuild.git as source for kernel

  GEN     /home/sam/kernel/oia64/Makefile
  CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h
  CC      arch/ia64/kernel/asm-offsets.s
In file included from /home/sam/kernel/kbuild.git/include/linux/poll.h:11,
                 from /home/sam/kernel/kbuild.git/include/linux/rtc.h:113,
                 from /home/sam/kernel/kbuild.git/include/linux/efi.h:19,
                 from include2/asm/sal.h:40,
                 from /home/sam/kernel/kbuild.git/include/asm-ia64/mca.h:20,
                 from /home/sam/kernel/kbuild.git/arch/ia64/kernel/asm-offsets.c:15:
/home/sam/kernel/kbuild.git/include/linux/mm.h: In function `lowmem_page_address':
/home/sam/kernel/kbuild.git/include/linux/mm.h:530: error: implicit declaration of function `page_to_pfn'
In file included from /home/sam/kernel/kbuild.git/include/linux/poll.h:12,
                 from /home/sam/kernel/kbuild.git/include/linux/rtc.h:113,
                 from /home/sam/kernel/kbuild.git/include/linux/efi.h:19,
                 from include2/asm/sal.h:40,
                 from /home/sam/kernel/kbuild.git/include/asm-ia64/mca.h:20,
                 from /home/sam/kernel/kbuild.git/arch/ia64/kernel/asm-offsets.c:15:

include2/asm/uaccess.h: In function `xlate_dev_mem_ptr':
include2/asm/uaccess.h:374: error: implicit declaration of function pfn_to_page' include2/asm/uaccess.h:374: warning: assignment makes pointer from integer without a cast include2/asm/uaccess.h: In function xlate_dev_kmem_ptr':
include2/asm/uaccess.h:392: warning: assignment makes pointer from integer without a cast make[3]: *** [arch/ia64/kernel/asm-offsets.s] Error 1
make[2]: *** [prepare0] Error 2
make[1]: *** [_all] Error 2
make: *** [all] Error 2
make -C /home/sam/kernel/kbuild.git O=/home/sam/kernel/osparc
Using /home/sam/kernel/kbuild.git as source for kernel

  GEN     /home/sam/kernel/osparc/Makefile
  CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h
  CHK     include/linux/compile.h
  CC      arch/sparc/mm/init.o

In file included from include2/asm/tlb.h:22,
from /home/sam/kernel/kbuild.git/arch/sparc/mm/init.c:32:
/home/sam/kernel/kbuild.git/include/asm-generic/tlb.h: In function `tlb_flush_mmu':
/home/sam/kernel/kbuild.git/include/asm-generic/tlb.h:76: error: implicit declaration of function release_pages' /home/sam/kernel/kbuild.git/include/asm-generic/tlb.h: In function tlb_remove_page':
/home/sam/kernel/kbuild.git/include/asm-generic/tlb.h:105: error: implicit declaration of function `page_cache_release' make[3]: *** [arch/sparc/mm/init.o] Error 1
make[2]: *** [arch/sparc/mm] Error 2
make[1]: *** [_all] Error 2
make: *** [all] Error 2

make -C /home/sam/kernel/kbuild.git O=/home/sam/kernel/oppc64
Using /home/sam/kernel/kbuild.git as source for kernel

  GEN     /home/sam/kernel/oppc64/Makefile
  CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h

SYMLINK include/asm -> include/asm-powerpc
CHK include/linux/compile.h
CC arch/powerpc/mm/tlb_32.o
In file included from include2/asm/tlb.h:52,

                 from /home/sam/kernel/kbuild.git/arch/powerpc/mm/tlb_32.c:31:

/home/sam/kernel/kbuild.git/include/asm-generic/tlb.h: In function `tlb_flush_mmu':
/home/sam/kernel/kbuild.git/include/asm-generic/tlb.h:76: error: implicit declaration of function release_pages' /home/sam/kernel/kbuild.git/include/asm-generic/tlb.h: In function tlb_remove_page':
/home/sam/kernel/kbuild.git/include/asm-generic/tlb.h:105: error: implicit declaration of function `page_cache_release' make[3]: *** [arch/powerpc/mm/tlb_32.o] Error 1
make[2]: *** [arch/powerpc/mm] Error 2
make[1]: *** [_all] Error 2
make: *** [all] Error 2

#8 lore raw
In reply to Sam Ravnborg
Quoted 5 lines · Sam Ravnborg
Quoted 4 lines · Adrian Bunk

Currently, using an undeclared function gives a compile warning, but it can lead to a nasty to debug runtime stack corruptions if the prototype of the function is different from what gcc guessed.

Quoted 8 lines
Quoted 2 lines

With -Werror-implicit-function-declaration we are getting an immediate compile error instead.

This patch broke (-rc1):

sparc allnoconfig build
ia64 allnoconfig build
ppc64 allnoconfig build
...

I did defconfig builds on 12 architectures, but no allnoconfig builds.

I'll try to fix them.

Quoted 2 lines

Sam
...

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
#6 lore raw
In reply to Sam Ravnborg
Quoted 8 lines · Sam Ravnborg

...
make -C /home/sam/kernel/kbuild.git O=/home/sam/kernel/osparc
Using /home/sam/kernel/kbuild.git as source for kernel

  GEN     /home/sam/kernel/osparc/Makefile
  CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h
  CHK     include/linux/compile.h
  CC      arch/sparc/mm/init.o
Quoted 11 lines

In file included from include2/asm/tlb.h:22,
from /home/sam/kernel/kbuild.git/arch/sparc/mm/init.c:32:
/home/sam/kernel/kbuild.git/include/asm-generic/tlb.h: In function `tlb_flush_mmu':
/home/sam/kernel/kbuild.git/include/asm-generic/tlb.h:76: error: implicit declaration of function release_pages' /home/sam/kernel/kbuild.git/include/asm-generic/tlb.h: In function tlb_remove_page':
/home/sam/kernel/kbuild.git/include/asm-generic/tlb.h:105: error: implicit declaration of function `page_cache_release' make[3]: *** [arch/sparc/mm/init.o] Error 1
make[2]: *** [arch/sparc/mm] Error 2
make[1]: *** [_all] Error 2
make: *** [all] Error 2
...

OK, I tried starting with this one.

The problem is that in the CONFIG_SWAP=n case, linux/swap.h uses these functions.

These implicit declarations are bugs that should be fixed.

I tried adding an #include <linux/pagemap.h> to linux/swap.h, but this broke things faster than I could fix them.

Does anyone know our header mess good enough for being able to help me with this issue?

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
#9 lore raw
In reply to Sam Ravnborg
Quoted 12 lines
Quoted 6 lines

Currently, using an undeclared function gives a compile warning, but it can lead to a nasty to debug runtime stack corruptions if the prototype of the function is different from what gcc guessed.

With -Werror-implicit-function-declaration we are getting an immediate compile error instead.

This patch broke (-rc1):

sparc allnoconfig build
ia64 allnoconfig build
ppc64 allnoconfig build

Quoted 5 lines

x86_64 succeded an allnoconfig build

I did not try other architectures. We need to fix the allnoconfig cases at least for the popular architectures before applying this patch otherwise it will create too much trouble/noise.

s390 builds with defconfig and allnoconfig and a few other variants as well.

#7 lore raw
In reply to [email protected]
Quoted 10 lines · Sam Ravnborg
Quoted 4 lines · Adrian Bunk
Quoted 2 lines

With -Werror-implicit-function-declaration we are getting an immediate compile error instead.

This patch broke (-rc1):

...

Quoted 3 lines

I did not try other architectures. We need to fix the allnoconfig cases at least for the popular architectures before applying this patch otherwise it will create too much trouble/noise.

Sam wrote on Fri Jul 07 2006 - 02:40:55 EST::

Quoted 11 lines

The error messages follows (for ia64, sparc and ppc64). make -C /home/sam/kernel/kbuild.git O=/home/sam/kernel/oppc64 Using /home/sam/kernel/kbuild.git as source for kernel GEN /home/sam/kernel/oppc64/Makefile
CHK include/linux/version.h
CHK include/linux/utsrelease.h
SYMLINK include/asm -> include/asm-powerpc
CHK include/linux/compile.h
CC arch/powerpc/mm/tlb_32.o
In file included from include2/asm/tlb.h:52,
from /home/sam/kernel/kbuild.git/arch/powerpc/mm/tlb_32.c:31:

Quoted 9 lines

/home/sam/kernel/kbuild.git/include/asm-generic/tlb.h: In function `tlb_flush_mmu':
/home/sam/kernel/kbuild.git/include/asm-generic/tlb.h:76: error: implicit declaration of function release_pages' /home/sam/kernel/kbuild.git/include/asm-generic/tlb.h: In function tlb_remove_page':
/home/sam/kernel/kbuild.git/include/asm-generic/tlb.h:105: error: implicit declaration of function `page_cache_release' make[3]: *** [arch/powerpc/mm/tlb_32.o] Error 1
make[2]: *** [arch/powerpc/mm] Error 2
make[1]: *** [_all] Error 2
make: *** [all] Error 2

That is cross architcture (asm-generic) CONFIG_SWAP=n

http://marc.theaimsgroup.com/?l=linux-kernel&m=106674447120368&w=2

My vote is if the file needs it in an inline, add the include. Otherwise
split the definition to a new file..

miton

#10 lore raw
In reply to Heiko Carstens
Quoted 12 lines · Heiko Carstens
Quoted 12 lines
Quoted 6 lines

Currently, using an undeclared function gives a compile warning, but it can lead to a nasty to debug runtime stack corruptions if the prototype of the function is different from what gcc guessed.

With -Werror-implicit-function-declaration we are getting an immediate compile error instead.

This patch broke (-rc1):

sparc allnoconfig build
ia64 allnoconfig build
ppc64 allnoconfig build

Quoted 7 lines
Quoted 5 lines

x86_64 succeded an allnoconfig build

I did not try other architectures. We need to fix the allnoconfig cases at least for the popular architectures before applying this patch otherwise it will create too much trouble/noise.

s390 builds with defconfig and allnoconfig and a few other variants as well.

Thanks for testing.

Sam