Skip to contentSkip to conversation

x86/boot: clean up headers

PATCH Superseded Nick Desaulniers 5 participants 11 messages Mar 2, 2019 – Mar 21, 2019 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/boot: clean up headers

The inclusion of <linux/kernel.h> was causing issue as the definition of __arch_hweight64 from arch/x86/include/asm/arch_hweight.h eventually gets included. The definition is problematic when compiled with -m16 (all code in arch/x86/boot/ is) as the "D" inline assembly constraint is rejected by both compilers when passed an argument of type long long (regardless of signedness, anything smaller is fine).

Because GCC performs inlining before semantic analysis, and __arch_hweight64 is dead in this translation unit, GCC does not report any issues at compile time. Clang does the semantic analysis in the front end, before inlining (run in the middle) can determine the code is dead. I consider this another case of PR33587, which I think we can do more work to solve.

It turns out that arch/x86/boot/string.c doesn't actually need linux/kernel.h, simply linux/limits.h and linux/compiler.h. Include them, and sort the headers alphabetically.

---
Note that this only regresses for us on linux-next (not mainline).

 arch/x86/boot/string.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/boot/string.c +4 -3
index 315a67b8896b..f149316116d0 100644
@@ -12,10 +12,11 @@
  * Very basic string functions
  */
 
-#include <linux/types.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
 #include <asm/asm.h>
+#include <linux/compiler.h>
+#include <linux/errno.h>
+#include <linux/limits.h>
+#include <linux/types.h>
 #include "ctype.h"
 #include "string.h"
 
Signature · 1 line
2.21.0.352.gf09ad66450-goog
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 14 lines · Nick Desaulniers

The inclusion of <linux/kernel.h> was causing issue as the definition of __arch_hweight64 from arch/x86/include/asm/arch_hweight.h eventually gets included. The definition is problematic when compiled with -m16 (all code in arch/x86/boot/ is) as the "D" inline assembly constraint is rejected by both compilers when passed an argument of type long long (regardless of signedness, anything smaller is fine).

Because GCC performs inlining before semantic analysis, and __arch_hweight64 is dead in this translation unit, GCC does not report any issues at compile time. Clang does the semantic analysis in the front end, before inlining (run in the middle) can determine the code is dead. I consider this another case of PR33587, which I think we can do more work to solve.

Quoted 7 lines

It turns out that arch/x86/boot/string.c doesn't actually need linux/kernel.h, simply linux/limits.h and linux/compiler.h. Include them, and sort the headers alphabetically.

Quoted 28 lines

---
Note that this only regresses for us on linux-next (not mainline).

 arch/x86/boot/string.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/boot/string.c +4 -3
index 315a67b8896b..f149316116d0 100644
@@ -12,10 +12,11 @@
  * Very basic string functions
  */
 
-#include <linux/types.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
 #include <asm/asm.h>
+#include <linux/compiler.h>
+#include <linux/errno.h>
+#include <linux/limits.h>
+#include <linux/types.h>
 #include "ctype.h"
 #include "string.h"
 
Signature · 1 line
2.21.0.352.gf09ad66450-goog
#2 lore raw
In reply to Nick Desaulniers

Hi Nick,

Quoted 4 lines · On Fri, 1 Mar 2019 16:07:14 -0800 Nick Desaulniers <[email protected]>…

It turns out that arch/x86/boot/string.c doesn't actually need linux/kernel.h, simply linux/limits.h and linux/compiler.h. Include them, and sort the headers alphabetically.

One small nit: please do not do the sort in the same commit as the bug fix. It just complicates the review and has (a remote) possibility of adding a new problem. (Not a big issue here, but in general cleanups and bug fixes should be separate.)

Signature · 2 lines
Cheers,
Stephen Rothwell
#3 lore raw

Hi Nick,

Quoted 11 lines · On Sat, 2 Mar 2019 13:27:50 +1100 Stephen Rothwell <[email protected]> wrote:
Quoted 4 lines · On Fri, 1 Mar 2019 16:07:14 -0800 Nick Desaulniers <[email protected]>…

It turns out that arch/x86/boot/string.c doesn't actually need linux/kernel.h, simply linux/limits.h and linux/compiler.h. Include them, and sort the headers alphabetically.

One small nit: please do not do the sort in the same commit as the bug fix. It just complicates the review and has (a remote) possibility of adding a new problem. (Not a big issue here, but in general cleanups and bug fixes should be separate.)

Also it is *very* common for headers to be included in the order:
linux/ asm/ and then local.

Signature · 2 lines
Cheers,
Stephen Rothwell
#4 lore raw

PATCH v2 1/1 x86/boot: clean up headers

In reply to Stephen Rothwell

The inclusion of <linux/kernel.h> was causing issue as the definition of __arch_hweight64 from arch/x86/include/asm/arch_hweight.h eventually gets included. The definition is problematic when compiled with -m16 (all code in arch/x86/boot/ is) as the "D" inline assembly constraint is rejected by both compilers when passed an argument of type long long (regardless of signedness, anything smaller is fine).

Because GCC performs inlining before semantic analysis, and __arch_hweight64 is dead in this translation unit, GCC does not report any issues at compile time. Clang does the semantic analysis in the front end, before inlining (run in the middle) can determine the code is dead. I consider this another case of PR33587, which I think we can do more work to solve.

It turns out that arch/x86/boot/string.c doesn't actually need linux/kernel.h, simply linux/limits.h and linux/compiler.h. Include them, and sort the headers alphabetically.

---
Changes V1 -> V2:
* Add Reviewed, Tested, Suggested tags.
* Drop linux/types.h; it's included in linux/limits.h.

My original intention was to unsort the headers (sorted in V1), but if we drop the out of place linux/types.h, then we can insert the two more specific headers in alphabetic order.

 arch/x86/boot/string.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/boot/string.c +2 -2
index 315a67b8896b..597589cafb45 100644
@@ -12,9 +12,9 @@
  * Very basic string functions
  */
 
-#include <linux/types.h>
-#include <linux/kernel.h>
+#include <linux/compiler.h>
 #include <linux/errno.h>
+#include <linux/limits.h>
 #include <asm/asm.h>
 #include "ctype.h"
 #include "string.h"
Signature · 1 line
2.21.0.352.gf09ad66450-goog
#5 lore raw

Hi Nick,

Quoted 8 lines · On Mon, 4 Mar 2019 09:50:16 -0800 Nick Desaulniers <[email protected]>…

Changes V1 -> V2:
* Add Reviewed, Tested, Suggested tags.
* Drop linux/types.h; it's included in linux/limits.h.

My original intention was to unsort the headers (sorted in V1), but if we drop the out of place linux/types.h, then we can insert the two more specific headers in alphabetic order.

I don't understand why you care about the include file ordering.

Also, since this file uses things from linux/types.h, I would argue that we need the explicit include of linux/types.h. Just imagine if someone at a later date reomves the linux/types.h include from linux/limits.h (however unlikely that is).

Just do your bug fix.

Signature · 2 lines
Cheers,
Stephen Rothwell
#6 lore raw

PATCH v3 1/1 x86/boot: clean up headers

The inclusion of <linux/kernel.h> was causing issue as the definition of __arch_hweight64 from arch/x86/include/asm/arch_hweight.h eventually gets included. The definition is problematic when compiled with -m16 (all code in arch/x86/boot/ is) as the "D" inline assembly constraint is rejected by both compilers when passed an argument of type long long (regardless of signedness, anything smaller is fine).

Because GCC performs inlining before semantic analysis, and __arch_hweight64 is dead in this translation unit, GCC does not report any issues at compile time. Clang does the semantic analysis in the front end, before inlining (run in the middle) can determine the code is dead. I consider this another case of PR33587, which I think we can do more work to solve.

It turns out that arch/x86/boot/string.c doesn't actually need linux/kernel.h, simply linux/limits.h and linux/compiler.h. Include them, and sort the headers alphabetically.

---
Changes V2 -> V3:
* keep linux/types.h

Changes V1 -> V2:
* Add Reviewed, Tested, Suggested tags.
* Drop linux/types.h; it's included in linux/limits.h.

 arch/x86/boot/string.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/boot/string.c +2 -1
index 315a67b8896b..90154df8f125 100644
@@ -13,8 +13,9 @@
  */
 
 #include <linux/types.h>
-#include <linux/kernel.h>
+#include <linux/compiler.h>
 #include <linux/errno.h>
+#include <linux/limits.h>
 #include <asm/asm.h>
 #include "ctype.h"
 #include "string.h"
Signature · 1 line
2.21.0.352.gf09ad66450-goog
#7 lore raw
Quoted 15 lines · Nick Desaulniers

The inclusion of <linux/kernel.h> was causing issue as the definition of __arch_hweight64 from arch/x86/include/asm/arch_hweight.h eventually gets included. The definition is problematic when compiled with -m16 (all code in arch/x86/boot/ is) as the "D" inline assembly constraint is rejected by both compilers when passed an argument of type long long (regardless of signedness, anything smaller is fine).

Because GCC performs inlining before semantic analysis, and __arch_hweight64 is dead in this translation unit, GCC does not report any issues at compile time. Clang does the semantic analysis in the front end, before inlining (run in the middle) can determine the code is dead. I consider this another case of PR33587, which I think we can do more work to solve.

Quoted 3 lines

It turns out that arch/x86/boot/string.c doesn't actually need linux/kernel.h, simply linux/limits.h and linux/compiler.h. Include them, and sort the headers alphabetically.

Well, should have cut that out of the commit message too in V3...sigh. Boris assuming everyone's ok with this patch; can you just drop this sentence from the commit message should you apply the patch (or shall I send a v4)?

Quoted 36 lines

---
Changes V2 -> V3:
* keep linux/types.h

Changes V1 -> V2:
* Add Reviewed, Tested, Suggested tags.
* Drop linux/types.h; it's included in linux/limits.h.

 arch/x86/boot/string.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/boot/string.c +2 -2
index 315a67b8896b..90154df8f125 100644
@@ -13,8 +13,9 @@
  */
 
 #include <linux/types.h>
-#include <linux/kernel.h>
+#include <linux/compiler.h>
 #include <linux/errno.h>
+#include <linux/limits.h>
 #include <asm/asm.h>
 #include "ctype.h"
 #include "string.h"
--

2.21.0.352.gf09ad66450-goog

Signature · 2 lines
Thanks,
~Nick Desaulniers
maintainer
#8 lore raw
Quoted 4 lines · Nick Desaulniers

Well, should have cut that out of the commit message too in V3...sigh. Boris assuming everyone's ok with this patch; can you just drop this sentence from the commit message should you apply the patch (or shall I send a v4)?

I'll take a look once the merge window is over and all the dust settles.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#9 lore raw

PATCH v4 1/1 x86/boot: clean up headers

The inclusion of <linux/kernel.h> was causing issue as the definition of __arch_hweight64 from arch/x86/include/asm/arch_hweight.h eventually gets included. The definition is problematic when compiled with -m16 (all code in arch/x86/boot/ is) as the "D" inline assembly constraint is rejected by both compilers when passed an argument of type long long (regardless of signedness, anything smaller is fine).

Because GCC performs inlining before semantic analysis, and __arch_hweight64 is dead in this translation unit, GCC does not report any issues at compile time. Clang does the semantic analysis in the front end, before inlining (run in the middle) can determine the code is dead. I consider this another case of PR33587, which I think we can do more work to solve.

It turns out that arch/x86/boot/string.c doesn't actually need linux/kernel.h, simply linux/limits.h and linux/compiler.h.

---
Changes V3 -> V4:
* Drop sentence from commit message about sorting headers.

Changes V2 -> V3:
* keep linux/types.h

Changes V1 -> V2:
* Add Reviewed, Tested, Suggested tags.
* Drop linux/types.h; it's included in linux/limits.h.

 arch/x86/boot/string.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/boot/string.c +2 -1
index 315a67b8896b..90154df8f125 100644
@@ -13,8 +13,9 @@
  */
 
 #include <linux/types.h>
-#include <linux/kernel.h>
+#include <linux/compiler.h>
 #include <linux/errno.h>
+#include <linux/limits.h>
 #include <asm/asm.h>
 #include "ctype.h"
 #include "string.h"
Signature · 1 line
2.21.0.360.g471c308f928-goog
#10 lore raw

[tip:x86/urgent] x86/boot: Restrict header scope to make Clang happy

x86/boot: Restrict header scope to make Clang happy
Commit-ID:  a9c640ac96e19b3966357ec9bb586edd2e1e74de
Gitweb:     https://git.kernel.org/tip/a9c640ac96e19b3966357ec9bb586edd2e1e74de
Author:     Nick Desaulniers <[email protected]>
AuthorDate: Thu, 14 Mar 2019 15:14:57 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 21 Mar 2019 12:24:38 +0100

x86/boot: Restrict header scope to make Clang happy

The inclusion of <linux/kernel.h> was causing issue as the definition of __arch_hweight64 from arch/x86/include/asm/arch_hweight.h eventually gets included. The definition is problematic when compiled with -m16 (all code in arch/x86/boot/ is) as the "D" inline assembly constraint is rejected by both compilers when passed an argument of type long long (regardless of signedness, anything smaller is fine).

Because GCC performs inlining before semantic analysis, and __arch_hweight64 is dead in this translation unit, GCC does not report any issues at compile time. Clang does the semantic analysis in the front end, before inlining (run in the middle) can determine the code is dead. I consider this another case of PR33587, which I think we can do more work to solve.

It turns out that arch/x86/boot/string.c doesn't actually need linux/kernel.h, simply linux/limits.h and linux/compiler.h.

---
 arch/x86/boot/string.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/boot/string.c +2 -1
index 315a67b8896b..90154df8f125 100644
@@ -13,8 +13,9 @@
  */
 
 #include <linux/types.h>
-#include <linux/kernel.h>
+#include <linux/compiler.h>
 #include <linux/errno.h>
+#include <linux/limits.h>
 #include <asm/asm.h>
 #include "ctype.h"
 #include "string.h"