diff mbox

[U-Boot,v2,1/3] compiler_gcc: prevent redefining attributes

Message ID 1411063827-10068-1-git-send-email-jeroen@myspectrum.nl
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Jeroen Hofstee Sept. 18, 2014, 6:10 p.m. UTC
The libc headers on FreeBSD and likely related projects as well contain an
header file, cdefs.h which provides similiar functionality as linux/compiler.h.
It provides compiler independent defines like __weak __packed, to allow
compiling with multiple compilers which might have a different syntax for such
extension.

Since that header file is included in multiple standard headers, like stddef.h
and stdarg.h, multiple definitions of those defines will be present if both are
included. When compiling u-boot the compiler will warn about it hundreds of
times since e.g. common.h will include both files indirectly.

commit 7ea50d52849fe8ffa5b5b74c979b60b1045d6fc9 "compiler_gcc: do not redefine
__gnu_attributes" prevented such redefinitions, but this was undone by commit
fb8ffd7cfc68b3dc44e182356a207d784cb30b34 "compiler*.h: sync
include/linux/compiler*.h with Linux 3.16".

Add the checks back where necessary to prevent such warnings.

As the original patch this checkpatch warning is ignored:
"WARNING: Adding new packed members is to be done with care"

Cc: Masahiro Yamada <yamada.m@jp.panasonic.com>
Cc: Tom Rini <trini@ti.com>
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
---
changes since v1:
  As requested by Masahiro, elaborate a bit about what cdefs.h is and how these
  warnings are caused. Only this patch is reposted.
---
 include/linux/compiler-gcc.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Masahiro Yamada Sept. 19, 2014, 2:36 a.m. UTC | #1
On Thu, 18 Sep 2014 20:10:27 +0200
Jeroen Hofstee <jeroen@myspectrum.nl> wrote:

> The libc headers on FreeBSD and likely related projects as well contain an
> header file, cdefs.h which provides similiar functionality as linux/compiler.h.
> It provides compiler independent defines like __weak __packed, to allow
> compiling with multiple compilers which might have a different syntax for such
> extension.
> 
> Since that header file is included in multiple standard headers, like stddef.h
> and stdarg.h, multiple definitions of those defines will be present if both are
> included. When compiling u-boot the compiler will warn about it hundreds of
> times since e.g. common.h will include both files indirectly.
> 
> commit 7ea50d52849fe8ffa5b5b74c979b60b1045d6fc9 "compiler_gcc: do not redefine
> __gnu_attributes" prevented such redefinitions, but this was undone by commit
> fb8ffd7cfc68b3dc44e182356a207d784cb30b34 "compiler*.h: sync
> include/linux/compiler*.h with Linux 3.16".
> 
> Add the checks back where necessary to prevent such warnings.
> 
> As the original patch this checkpatch warning is ignored:
> "WARNING: Adding new packed members is to be done with care"
> 
> Cc: Masahiro Yamada <yamada.m@jp.panasonic.com>
> Cc: Tom Rini <trini@ti.com>
> Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>


Acked-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Tom Rini Sept. 25, 2014, 2:46 p.m. UTC | #2
On Thu, Sep 18, 2014 at 08:10:27PM +0200, Jeroen Hofstee wrote:

> The libc headers on FreeBSD and likely related projects as well contain an
> header file, cdefs.h which provides similiar functionality as linux/compiler.h.
> It provides compiler independent defines like __weak __packed, to allow
> compiling with multiple compilers which might have a different syntax for such
> extension.
> 
> Since that header file is included in multiple standard headers, like stddef.h
> and stdarg.h, multiple definitions of those defines will be present if both are
> included. When compiling u-boot the compiler will warn about it hundreds of
> times since e.g. common.h will include both files indirectly.
> 
> commit 7ea50d52849fe8ffa5b5b74c979b60b1045d6fc9 "compiler_gcc: do not redefine
> __gnu_attributes" prevented such redefinitions, but this was undone by commit
> fb8ffd7cfc68b3dc44e182356a207d784cb30b34 "compiler*.h: sync
> include/linux/compiler*.h with Linux 3.16".
> 
> Add the checks back where necessary to prevent such warnings.
> 
> As the original patch this checkpatch warning is ignored:
> "WARNING: Adding new packed members is to be done with care"
> 
> Cc: Masahiro Yamada <yamada.m@jp.panasonic.com>
> Cc: Tom Rini <trini@ti.com>
> Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
> Acked-by: Masahiro Yamada <yamada.m@jp.panasonic.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 02ae99e..e057bd2 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -64,8 +64,12 @@ 
 #endif
 
 #define __deprecated			__attribute__((deprecated))
+#ifndef __packed
 #define __packed			__attribute__((packed))
+#endif
+#ifndef __weak
 #define __weak				__attribute__((weak))
+#endif
 
 /*
  * it doesn't make sense on ARM (currently the only user of __naked) to trace
@@ -91,8 +95,12 @@ 
  * would be.
  * [...]
  */
+#ifndef __pure
 #define __pure				__attribute__((pure))
+#endif
+#ifndef __aligned
 #define __aligned(x)			__attribute__((aligned(x)))
+#endif
 #define __printf(a, b)			__attribute__((format(printf, a, b)))
 #define __scanf(a, b)			__attribute__((format(scanf, a, b)))
 #define  noinline			__attribute__((noinline))
@@ -115,4 +123,6 @@ 
  */
 #define uninitialized_var(x) x = x
 
+#ifndef __always_inline
 #define __always_inline		inline __attribute__((always_inline))
+#endif