Skip to contentSkip to conversation

Fixes for FreeBSD / clang

PATCH New Jeroen Hofstee 3 participants 16 messages Sep 17, 2014 – Sep 25, 2014

lore
Share & tools
lore
#0 lore raw

cover Fixes for FreeBSD / clang

- Some minor adjustments to the new compiler.h from linux.
- Updated README for FreeBSD

Jeroen Hofstee (3):
compiler_gcc: do not redefine __gnu_attributes
README.clang: update FreeBSD instructions
compiler.h: remove duplicated uninitialized_var

 doc/README.clang             |  6 +++---
 include/compiler.h           |  3 ---
 include/linux/compiler-gcc.h | 10 ++++++++++
 3 files changed, 13 insertions(+), 6 deletions(-)
Signature · 1 line
2.1.0
#1 lore raw

PATCH 1/3 compiler_gcc: do not redefine __gnu_attributes

commit fb8ffd7cfc68b3dc44e182356a207d784cb30b34 "compiler*.h:
sync include/linux/compiler*.h with Linux 3.16" undid the changes of 7ea50d52849fe8ffa5b5b74c979b60b1045d6fc9 "compiler_gcc: do not redefine __gnu_attributes". Add the checks back whether these macro's are already defined (as it causes a lot of noise on e.g. FreeBSD where these defines are already in cdefs.h)

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

Cc Masahiro Yamada <[email protected]>
Cc Tom Rini <[email protected]>
---
 include/linux/compiler-gcc.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/compiler-gcc.h +10 -0
index 02ae99e..e057bd2 100644
@@ -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
Signature · 1 line
2.1.0
#2 lore raw

PATCH 1/3 compiler_gcc: do not redefine __gnu_attributes

Jeroen,

Quoted 9 lines

commit fb8ffd7cfc68b3dc44e182356a207d784cb30b34 "compiler*.h:
sync include/linux/compiler*.h with Linux 3.16" undid the changes of 7ea50d52849fe8ffa5b5b74c979b60b1045d6fc9 "compiler_gcc: do not redefine __gnu_attributes". Add the checks back whether these macro's are already defined (as it causes a lot of noise on e.g. FreeBSD where these defines are already in cdefs.h)

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

Strange.

Which source files include cdefs.h?

For building u-boot images, sources should
only include headers in the u-boot source tree.
The standard system headers should not be used
except only a few files such as <stdarg.h>.

This is the same as Linux Kernel.

On the contrary, host programs are allowed to use standard system headers such as <stdio.h>, <stdlib.h> etc, where <linux/compiler.h> should not be included.

The root cause of warnings is _not_ that __packed and __weak are always defined in compiler-gcc.h.

I believe the real problem is there are some source files include both system headers and <linux/compiler.h> at the same time.

Best Regards
Masahiro Yamada

#3 lore raw

PATCH 1/3 compiler_gcc: do not redefine __gnu_attributes

Hello Masahiro,

Quoted 9 lines · Masahiro Yamada

Jeroen,

Quoted 7 lines

commit fb8ffd7cfc68b3dc44e182356a207d784cb30b34 "compiler*.h:
sync include/linux/compiler*.h with Linux 3.16" undid the changes of 7ea50d52849fe8ffa5b5b74c979b60b1045d6fc9 "compiler_gcc: do not redefine __gnu_attributes". Add the checks back whether these macro's are already defined (as it causes a lot of noise on e.g. FreeBSD where these defines are already in cdefs.h)

Quoted 6 lines
Quoted 2 lines

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

Strange.

Which source files include cdefs.h?

The host std* include this file, not a source file.

Quoted 6 lines

For building u-boot images, sources should
only include headers in the u-boot source tree.
The standard system headers should not be used
except only a few files such as <stdarg.h>.

This is the same as Linux Kernel.

Yes, and stdarg.h includes cdefs.h. So each include of common.h causes several warnings.

Quoted 8 lines

On the contrary, host programs are allowed to use standard system headers such as <stdio.h>, <stdlib.h> etc, where <linux/compiler.h> should not be included.

The root cause of warnings is _not_ that __packed and __weak are always defined in compiler-gcc.h.

This only works properly it u-boot for the target does not depend on any host header at all, which as you mentioned is not the case. Hence we shouldn't be surprised if they define something in their namespace and hence checking if that is done is fine.

Quoted 3 lines

I believe the real problem is there are some source files include both system headers and <linux/compiler.h> at the same time.

No it is a header issue only. The only alternative I can think of is a custom version of stdarg etc and I don't really like that idea.

Regards,
Jeroen

#4 lore raw

PATCH 1/3 compiler_gcc: do not redefine __gnu_attributes

Hi Jeroen,

Quoted 25 lines · On Thu, 18 Sep 2014 11:15:25 +0200 Jeroen Hofstee <[email protected]> wrote:

Hello Masahiro,

Quoted 9 lines · Masahiro Yamada

Jeroen,

Quoted 7 lines

commit fb8ffd7cfc68b3dc44e182356a207d784cb30b34 "compiler*.h:
sync include/linux/compiler*.h with Linux 3.16" undid the changes of 7ea50d52849fe8ffa5b5b74c979b60b1045d6fc9 "compiler_gcc: do not redefine __gnu_attributes". Add the checks back whether these macro's are already defined (as it causes a lot of noise on e.g. FreeBSD where these defines are already in cdefs.h)

Quoted 6 lines
Quoted 2 lines

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

Strange.

Which source files include cdefs.h?

The host std* include this file, not a source file.

Quoted 5 lines

For building u-boot images, sources should
only include headers in the u-boot source tree.
The standard system headers should not be used
except only a few files such as <stdarg.h>.

Quoted 4 lines
Quoted 1 line

This is the same as Linux Kernel.

Yes, and stdarg.h includes cdefs.h. So each include of common.h causes several warnings.

Oh, my dear!
This is really unfortunate.

Quoted 14 lines
Quoted 8 lines

On the contrary, host programs are allowed to use standard system headers such as <stdio.h>, <stdlib.h> etc, where <linux/compiler.h> should not be included.

The root cause of warnings is _not_ that __packed and __weak are always defined in compiler-gcc.h.

This only works properly it u-boot for the target does not depend on any host header at all, which as you mentioned is not the case. Hence we shouldn't be surprised if they define something in their namespace and hence checking if that is done is fine.

Quoted 6 lines
Quoted 3 lines

I believe the real problem is there are some source files include both system headers and <linux/compiler.h> at the same time.

No it is a header issue only. The only alternative I can think of is a custom version of stdarg etc and I don't really like that idea.

Me neither.

Thanks for explaining this and fully understood.

(Ideally, I hope a little more comments
because I did not know <stdarg.h> on FreeBSD defines __packed, __weak etc.)

Best Regards
Masahiro Yamada

#5 lore raw

PATCH 2/3 README.clang: update FreeBSD instructions

In reply to Jeroen Hofstee

The mentioned binutils port got removed while the patch was pending. As Ian pointed out there is another port providing the binutils for arm now. Update the instructions accordingly.

Cc ian at FreeBSD.org
Cc Tom Rini <[email protected]>
---
 doc/README.clang | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
doc/README.clang +3 -3
index 9ad689f..8c5bf12 100644
@@ -34,14 +34,14 @@ make HOSTCC=clang CC="clang -target $TRIPLET -mllvm -arm-use-movt=0 -no-integrat
 FreeBSD 11 (Current):
 --------------------
 Since llvm 3.4 is currently in the base system, the integrated as is
-incapable of building U-Boot. Therefore gas from devel/arm-eabi-binutils
+incapable of building U-Boot. Therefore gas from devel/arm-gnueabi-binutils
 is used instead. It needs a symlinks to be picked up correctly though:
 
-ln -s /usr/local/bin/arm-eabi-as /usr/bin/arm-freebsd-eabi-as
+ln -s /usr/local/bin/arm-gnueabi-freebsd-as /usr/bin/arm-freebsd-eabi-as
 
 # The following commands compile U-Boot using the clang xdev toolchain.
 # NOTE: CROSS_COMPILE and target differ on purpose!
-export CROSS_COMPILE=arm-eabi-
+export CROSS_COMPILE=arm-gnueabi-freebsd-
 gmake CC="clang -target arm-freebsd-eabi --sysroot /usr/arm-freebsd -no-integrated-as -mllvm -arm-use-movt=0" rpi_b_defconfig
 gmake CC="clang -target arm-freebsd-eabi --sysroot /usr/arm-freebsd -no-integrated-as -mllvm -arm-use-movt=0" -j8
 
Signature · 1 line
2.1.0
#6 lore raw

PATCH 3/3 compiler.h: remove duplicated uninitialized_var

In reply to Jeroen Hofstee

Since clang has a different definition for uninitialized_var it will complain that it is redefined in include/compiler.h. Since these are already defined in linux/compiler.h just remove this instance.

Cc Masahiro Yamada <[email protected]>
Cc Tom Rini <[email protected]>

---
This is only used in ubifs related code and MAKEALL for arm is fine (besides the 5 boards with build issues)

---
 include/compiler.h | 3 ---
 1 file changed, 3 deletions(-)
include/compiler.h +0 -3
index 9afc11b..1451916 100644
@@ -129,9 +129,6 @@ typedef unsigned long int uintptr_t;
 
 #endif /* USE_HOSTCC */
 
-/* compiler options */
-#define uninitialized_var(x)		x = x
-
 #define likely(x)	__builtin_expect(!!(x), 1)
 #define unlikely(x)	__builtin_expect(!!(x), 0)
 
Signature · 1 line
2.1.0
#7 lore raw

PATCH 3/3 compiler.h: remove duplicated uninitialized_var

Jeroen,

Quoted 8 lines

Since clang has a different definition for uninitialized_var it will complain that it is redefined in include/compiler.h. Since these are already defined in linux/compiler.h just remove this instance.

Cc Masahiro Yamada <[email protected]>
Cc Tom Rini <[email protected]>

I don't mind this patch but it has made me realize another problem.

We have both include/compiler.h and include/linux/compiler.h. Some sources use tha former and others use the latter.

I don't know how to use the right one in the right place.

Header file policy is one of the biggest problem in U-boot.

Everyone has added ugly work-arounds to solve his own problem without correct views or judgement.

Quoted 5 lines
include/compiler.h +0 -0
index 9afc11b..1451916 100644

include/compiler.h typedef unsigned long int uintptr_t; · line 134

Quoted 9 lines
include/compiler.h +0 -3
@@ -129,9 +129,6 @@ typedef unsigned long int uintptr_t;
 
 #endif /* USE_HOSTCC */
 
-/* compiler options */
-#define uninitialized_var(x)		x = x
-
 #define likely(x)	__builtin_expect(!!(x), 1)
 #define unlikely(x)	__builtin_expect(!!(x), 0)
 

I am not sure if likely(x) and unlikely(x) should also duplicated here.

Best Regards
Masahiro Yamada

#8 lore raw

PATCH 3/3 compiler.h: remove duplicated uninitialized_var

Hello Masahiro,

Quoted 10 lines · Masahiro Yamada
Quoted 8 lines

Since clang has a different definition for uninitialized_var it will complain that it is redefined in include/compiler.h. Since these are already defined in linux/compiler.h just remove this instance.

Cc Masahiro Yamada <[email protected]>
Cc Tom Rini <[email protected]>
Quoted 8 lines

I don't mind this patch but it has made me realize another problem.

We have both include/compiler.h and include/linux/compiler.h. Some sources use tha former and others use the latter.

I don't know how to use the right one in the right place.

no me neither, although it seems arch / drivers tend to use linux/compiler.h more while tools include compiler.h more.

Quoted 14 lines

Header file policy is one of the biggest problem in U-boot.

Everyone has added ugly work-arounds to solve his own problem without correct views or judgement.

Quoted 8 lines
include/compiler.h +0 -0
index 9afc11b..1451916 100644
@@ -129,9 +129,6 @@ typedef unsigned long int uintptr_t;
 
  #endif /* USE_HOSTCC */
 
Quoted 10 lines

include/compiler.h typedef unsigned long int uintptr_t; · line 134

Quoted 6 lines
include/compiler.h +0 -3
-/* compiler options */
-#define uninitialized_var(x)		x = x
-
  #define likely(x)	__builtin_expect(!!(x), 1)
  #define unlikely(x)	__builtin_expect(!!(x), 0)
 

I am not sure if likely(x) and unlikely(x) should also duplicated here.

yup I wondered about that too. likely / unlikely are used a lot more though then the isolated use of uninitialized_var. And as they don't cause any problems (the definitions are the same) I let them alone, but I think they should be removed as well some day.

Regards,
Jeroen

#9 lore raw

PATCH 3/3 compiler.h: remove duplicated uninitialized_var

Quoted 17 lines · Jeroen Hofstee

Hello Masahiro,

Quoted 14 lines · Masahiro Yamada
Quoted 8 lines

Since clang has a different definition for uninitialized_var it will complain that it is redefined in include/compiler.h. Since these are already defined in linux/compiler.h just remove this instance.

Cc Masahiro Yamada <[email protected]>
Cc Tom Rini <[email protected]>

I don't mind this patch but it has made me realize another problem.

Quoted 7 lines
Quoted 4 lines

We have both include/compiler.h and include/linux/compiler.h. Some sources use tha former and others use the latter.

I don't know how to use the right one in the right place.

no me neither, although it seems arch / drivers tend to use linux/compiler.h more while tools include compiler.h more.

My first guess is that we can't as easily throw <linux/compiler.h> into tools and thus need that around just for tools. Perhaps we should note as much in <compiler.h> and fix regular code to use <linux/compiler.h> ?

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140918/fde4b1a3/attachment.pgp>
#10 lore raw

PATCH 3/3 compiler.h: remove duplicated uninitialized_var

In reply to Jeroen Hofstee
Quoted 8 lines · Jeroen Hofstee

Since clang has a different definition for uninitialized_var it will complain that it is redefined in include/compiler.h. Since these are already defined in linux/compiler.h just remove this instance.

Cc Masahiro Yamada <[email protected]>
Cc Tom Rini <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140925/c935987f/attachment.pgp>
#11 lore raw

PATCH v2 1/3 compiler_gcc: prevent redefining attributes

In reply to Jeroen Hofstee

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 <[email protected]>
Cc Tom Rini <[email protected]>

---
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(+)
include/linux/compiler-gcc.h +10 -0
index 02ae99e..e057bd2 100644
@@ -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
Signature · 1 line
2.1.0
#12 lore raw

PATCH v2 1/3 compiler_gcc: prevent redefining attributes

Quoted 16 lines · On Thu, 18 Sep 2014 20:10:27 +0200 Jeroen Hofstee <[email protected]> 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".

Quoted 8 lines

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 <[email protected]>
Cc Tom Rini <[email protected]>
#13 lore raw

PATCH v2 1/3 compiler_gcc: prevent redefining attributes

In reply to Jeroen Hofstee
Quoted 18 lines · Jeroen Hofstee

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.

Quoted 7 lines

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

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140925/2e1dccfb/attachment.pgp>
#14 lore raw

PATCH v2 2/3 README.clang: update FreeBSD instructions

In reply to Jeroen Hofstee

The mentioned binutils port got removed while the patch was pending. As Ian pointed out there is another port providing the binutils for arm now. Update the instructions accordingly.

Cc ian at FreeBSD.org
Cc Tom Rini <[email protected]>
---
 doc/README.clang | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

---
changes since v1: update the name of the scipt as well.

doc/README.clang +4 -4
index 9ad689f..52495d3 100644
@@ -34,21 +34,21 @@ make HOSTCC=clang CC="clang -target $TRIPLET -mllvm -arm-use-movt=0 -no-integrat
 FreeBSD 11 (Current):
 --------------------
 Since llvm 3.4 is currently in the base system, the integrated as is
-incapable of building U-Boot. Therefore gas from devel/arm-eabi-binutils
+incapable of building U-Boot. Therefore gas from devel/arm-gnueabi-binutils
 is used instead. It needs a symlinks to be picked up correctly though:
 
-ln -s /usr/local/bin/arm-eabi-as /usr/bin/arm-freebsd-eabi-as
+ln -s /usr/local/bin/arm-gnueabi-freebsd-as /usr/bin/arm-freebsd-eabi-as
 
 # The following commands compile U-Boot using the clang xdev toolchain.
 # NOTE: CROSS_COMPILE and target differ on purpose!
-export CROSS_COMPILE=arm-eabi-
+export CROSS_COMPILE=arm-gnueabi-freebsd-
 gmake CC="clang -target arm-freebsd-eabi --sysroot /usr/arm-freebsd -no-integrated-as -mllvm -arm-use-movt=0" rpi_b_defconfig
 gmake CC="clang -target arm-freebsd-eabi --sysroot /usr/arm-freebsd -no-integrated-as -mllvm -arm-use-movt=0" -j8
 
 Given that u-boot will default to gcc, above commands can be
 simplified with a simple wrapper script, listed below.
 
-/usr/local/bin/arm-eabi-gcc
+/usr/local/bin/arm-gnueabi-freebsd-gcc
 ---
 #!/bin/sh
 
Signature · 1 line
2.1.0
#15 lore raw

PATCH v2 2/3 README.clang: update FreeBSD instructions

Quoted 7 lines · Jeroen Hofstee

The mentioned binutils port got removed while the patch was pending. As Ian pointed out there is another port providing the binutils for arm now. Update the instructions accordingly.

Cc ian at FreeBSD.org
Cc Tom Rini <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140925/b263cb56/attachment.pgp>