Skip to contentSkip to conversation

kbuild: Fix '-S -c' in x86 stack protector scripts

PATCH In review Nathan Chancellor 3 participants 8 messages Jul 26, 2024 – Jul 28, 2024

Subsystems (2)
lore
Share & tools
lore

Nathan Chancellor

author maintainer
#0 lore raw

PATCH 1/1 kbuild: Fix '-S -c' in x86 stack protector scripts

After a recent change in clang to stop consuming all instances of '-S' and '-c' [1], the stack protector scripts break due to the kernel's use of -Werror=unused-command-line-argument to catch cases where flags are not being properly consumed by the compiler driver:

  $ echo | clang -o - -x c - -S -c -Werror=unused-command-line-argument
  clang: error: argument unused during compilation: '-c' [-Werror,-Wunused-command-line-argument]

This results in CONFIG_STACKPROTECTOR getting disabled because CONFIG_CC_HAS_SANE_STACKPROTECTOR is no longer set.

'-c' and '-S' both instruct the compiler to stop at different stages of the pipeline ('-S' after compiling, '-c' after assembling), so having them present together in the same command makes little sense. In this case, the test wants to stop before assembling because it is looking at the textual assembly output of the compiler for either '%fs' or '%gs', so remove '-c' from the list of arguments to resolve the error.

All versions of GCC continue to work after this change, along with versions of clang that do or do not contain the change mentioned above.

Fixes 4f7fd4d7a791 ("[PATCH] Add the -fstack-protector option to the CFLAGS")
Fixes 60a5317ff0f4 ("x86: implement x86_32 stack protector")

---
I think this could go via either -tip or Kbuild?

Perhaps this is an issue in the clang commit mentioned in the message above since it deviates from GCC (Fangrui is on CC here) but I think the combination of these options is a little dubious to begin with, hence this change.

---
 scripts/gcc-x86_32-has-stack-protector.sh | 2 +-
 scripts/gcc-x86_64-has-stack-protector.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
scripts/gcc-x86_32-has-stack-protector.sh +1 -1
index 825c75c5b715..9459ca4f0f11 100755
@@ -5,4 +5,4 @@
 # -mstack-protector-guard-reg, added by
 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81708
 
-echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -m32 -O0 -fstack-protector -mstack-protector-guard-reg=fs -mstack-protector-guard-symbol=__stack_chk_guard - -o - 2> /dev/null | grep -q "%fs"
+echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -m32 -O0 -fstack-protector -mstack-protector-guard-reg=fs -mstack-protector-guard-symbol=__stack_chk_guard - -o - 2> /dev/null | grep -q "%fs"
scripts/gcc-x86_64-has-stack-protector.sh +1 -1
index 75e4e22b986a..f680bb01aeeb 100755
@@ -1,4 +1,4 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 
-echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -m64 -O0 -mcmodel=kernel -fno-PIE -fstack-protector - -o - 2> /dev/null | grep -q "%gs"
+echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -m64 -O0 -mcmodel=kernel -fno-PIE -fstack-protector - -o - 2> /dev/null | grep -q "%gs"

---
base-commit: 1722389b0d863056d78287a120a1d6cadb8d4f7b
change-id: 20240726-fix-x86-stack-protector-tests-b542b1b9416b

Best regards,

Signature · 1 line
Nathan Chancellor <[email protected]>
#1 lore raw
Quoted 27 lines · Nathan Chancellor

After a recent change in clang to stop consuming all instances of '-S' and '-c' [1], the stack protector scripts break due to the kernel's use of -Werror=unused-command-line-argument to catch cases where flags are not being properly consumed by the compiler driver:

  $ echo | clang -o - -x c - -S -c -Werror=unused-command-line-argument
  clang: error: argument unused during compilation: '-c' [-Werror,-Wunused-command-line-argument]

This results in CONFIG_STACKPROTECTOR getting disabled because CONFIG_CC_HAS_SANE_STACKPROTECTOR is no longer set.

'-c' and '-S' both instruct the compiler to stop at different stages of the pipeline ('-S' after compiling, '-c' after assembling), so having them present together in the same command makes little sense. In this case, the test wants to stop before assembling because it is looking at the textual assembly output of the compiler for either '%fs' or '%gs', so remove '-c' from the list of arguments to resolve the error.

All versions of GCC continue to work after this change, along with versions of clang that do or do not contain the change mentioned above.

Fixes 4f7fd4d7a791 ("[PATCH] Add the -fstack-protector option to the CFLAGS")
Fixes 60a5317ff0f4 ("x86: implement x86_32 stack protector")
Quoted 7 lines

---
I think this could go via either -tip or Kbuild?

Perhaps this is an issue in the clang commit mentioned in the message above since it deviates from GCC (Fangrui is on CC here) but I think the combination of these options is a little dubious to begin with, hence this change.

As part of my stack protector cleanup series, I found that these scripts can simply be removed. I can repost those patches as a standalone cleanup.

https://lore.kernel.org/lkml/[email protected]/

Brian Gerst

Reviewed-by on v1 1/1
#6 lore raw
In reply to Nathan Chancellor
Quoted 27 lines · Nathan Chancellor

After a recent change in clang to stop consuming all instances of '-S' and '-c' [1], the stack protector scripts break due to the kernel's use of -Werror=unused-command-line-argument to catch cases where flags are not being properly consumed by the compiler driver:

  $ echo | clang -o - -x c - -S -c -Werror=unused-command-line-argument
  clang: error: argument unused during compilation: '-c' [-Werror,-Wunused-command-line-argument]

This results in CONFIG_STACKPROTECTOR getting disabled because CONFIG_CC_HAS_SANE_STACKPROTECTOR is no longer set.

'-c' and '-S' both instruct the compiler to stop at different stages of the pipeline ('-S' after compiling, '-c' after assembling), so having them present together in the same command makes little sense. In this case, the test wants to stop before assembling because it is looking at the textual assembly output of the compiler for either '%fs' or '%gs', so remove '-c' from the list of arguments to resolve the error.

All versions of GCC continue to work after this change, along with versions of clang that do or do not contain the change mentioned above.

Fixes 4f7fd4d7a791 ("[PATCH] Add the -fstack-protector option to the CFLAGS")
Fixes 60a5317ff0f4 ("x86: implement x86_32 stack protector")
Quoted 7 lines

---
I think this could go via either -tip or Kbuild?

Perhaps this is an issue in the clang commit mentioned in the message above since it deviates from GCC (Fangrui is on CC here) but I think the combination of these options is a little dubious to begin with, hence this change.

I agree.

I can offer to pick up this to kbuild/fixes.

If this goes somewhere else,

Quoted 35 lines
---
 scripts/gcc-x86_32-has-stack-protector.sh | 2 +-
 scripts/gcc-x86_64-has-stack-protector.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
scripts/gcc-x86_32-has-stack-protector.sh +1 -1
index 825c75c5b715..9459ca4f0f11 100755
@@ -5,4 +5,4 @@
 # -mstack-protector-guard-reg, added by
 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81708
 
-echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -m32 -O0 -fstack-protector -mstack-protector-guard-reg=fs -mstack-protector-guard-symbol=__stack_chk_guard - -o - 2> /dev/null | grep -q "%fs"
+echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -m32 -O0 -fstack-protector -mstack-protector-guard-reg=fs -mstack-protector-guard-symbol=__stack_chk_guard - -o - 2> /dev/null | grep -q "%fs"
scripts/gcc-x86_64-has-stack-protector.sh +1 -2
index 75e4e22b986a..f680bb01aeeb 100755
@@ -1,4 +1,4 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 
-echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -m64 -O0 -mcmodel=kernel -fno-PIE -fstack-protector - -o - 2> /dev/null | grep -q "%gs"
+echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -m64 -O0 -mcmodel=kernel -fno-PIE -fstack-protector - -o - 2> /dev/null | grep -q "%gs"
 
---

base-commit: 1722389b0d863056d78287a120a1d6cadb8d4f7b
change-id: 20240726-fix-x86-stack-protector-tests-b542b1b9416b

Best regards,
--
Nathan Chancellor <[email protected]>

Signature · 2 lines
Best Regards
Masahiro Yamada
#2 lore raw
In reply to Brian Gerst
Quoted 37 lines · Brian Gerst
Quoted 27 lines · Nathan Chancellor

After a recent change in clang to stop consuming all instances of '-S' and '-c' [1], the stack protector scripts break due to the kernel's use of -Werror=unused-command-line-argument to catch cases where flags are not being properly consumed by the compiler driver:

  $ echo | clang -o - -x c - -S -c -Werror=unused-command-line-argument
  clang: error: argument unused during compilation: '-c' [-Werror,-Wunused-command-line-argument]

This results in CONFIG_STACKPROTECTOR getting disabled because CONFIG_CC_HAS_SANE_STACKPROTECTOR is no longer set.

'-c' and '-S' both instruct the compiler to stop at different stages of the pipeline ('-S' after compiling, '-c' after assembling), so having them present together in the same command makes little sense. In this case, the test wants to stop before assembling because it is looking at the textual assembly output of the compiler for either '%fs' or '%gs', so remove '-c' from the list of arguments to resolve the error.

All versions of GCC continue to work after this change, along with versions of clang that do or do not contain the change mentioned above.

Fixes 4f7fd4d7a791 ("[PATCH] Add the -fstack-protector option to the CFLAGS")
Fixes 60a5317ff0f4 ("x86: implement x86_32 stack protector")
Quoted 7 lines

---
I think this could go via either -tip or Kbuild?

Perhaps this is an issue in the clang commit mentioned in the message above since it deviates from GCC (Fangrui is on CC here) but I think the combination of these options is a little dubious to begin with, hence this change.

Quoted 7 lines

As part of my stack protector cleanup series, I found that these scripts can simply be removed. I can repost those patches as a standalone cleanup.

https://lore.kernel.org/lkml/[email protected]/

Brian Gerst

Judging from the Fixes tags, Nathan meant this patch is
a back-port candidate so that the latest LLVM can be used for stable kernels.

You are making big changes, and do you mean they can be back-ported?

Signature · 2 lines
Best Regards
Masahiro Yamada
#3 lore raw
Quoted 43 lines · Masahiro Yamada
Quoted 41 lines · Brian Gerst
Quoted 27 lines · Nathan Chancellor

After a recent change in clang to stop consuming all instances of '-S' and '-c' [1], the stack protector scripts break due to the kernel's use of -Werror=unused-command-line-argument to catch cases where flags are not being properly consumed by the compiler driver:

  $ echo | clang -o - -x c - -S -c -Werror=unused-command-line-argument
  clang: error: argument unused during compilation: '-c' [-Werror,-Wunused-command-line-argument]

This results in CONFIG_STACKPROTECTOR getting disabled because CONFIG_CC_HAS_SANE_STACKPROTECTOR is no longer set.

'-c' and '-S' both instruct the compiler to stop at different stages of the pipeline ('-S' after compiling, '-c' after assembling), so having them present together in the same command makes little sense. In this case, the test wants to stop before assembling because it is looking at the textual assembly output of the compiler for either '%fs' or '%gs', so remove '-c' from the list of arguments to resolve the error.

All versions of GCC continue to work after this change, along with versions of clang that do or do not contain the change mentioned above.

Fixes 4f7fd4d7a791 ("[PATCH] Add the -fstack-protector option to the CFLAGS")
Fixes 60a5317ff0f4 ("x86: implement x86_32 stack protector")
Quoted 7 lines

---
I think this could go via either -tip or Kbuild?

Perhaps this is an issue in the clang commit mentioned in the message above since it deviates from GCC (Fangrui is on CC here) but I think the combination of these options is a little dubious to begin with, hence this change.

As part of my stack protector cleanup series, I found that these scripts can simply be removed. I can repost those patches as a standalone cleanup.

Quoted 8 lines
Quoted 3 lines

https://lore.kernel.org/lkml/[email protected]/

Brian Gerst

Judging from the Fixes tags, Nathan meant this patch is
a back-port candidate so that the latest LLVM can be used for stable kernels.

You are making big changes, and do you mean they can be back-ported?

I was referring to just the first two patches of that series. That said, it would be simpler to take Nathan's fix for backporting.

Brian Gerst

#4 lore raw
Quoted 49 lines · Brian Gerst
Quoted 47 lines · Masahiro Yamada
Quoted 44 lines · Brian Gerst
Quoted 27 lines · Nathan Chancellor

After a recent change in clang to stop consuming all instances of '-S' and '-c' [1], the stack protector scripts break due to the kernel's use of -Werror=unused-command-line-argument to catch cases where flags are not being properly consumed by the compiler driver:

  $ echo | clang -o - -x c - -S -c -Werror=unused-command-line-argument
  clang: error: argument unused during compilation: '-c' [-Werror,-Wunused-command-line-argument]

This results in CONFIG_STACKPROTECTOR getting disabled because CONFIG_CC_HAS_SANE_STACKPROTECTOR is no longer set.

'-c' and '-S' both instruct the compiler to stop at different stages of the pipeline ('-S' after compiling, '-c' after assembling), so having them present together in the same command makes little sense. In this case, the test wants to stop before assembling because it is looking at the textual assembly output of the compiler for either '%fs' or '%gs', so remove '-c' from the list of arguments to resolve the error.

All versions of GCC continue to work after this change, along with versions of clang that do or do not contain the change mentioned above.

Fixes 4f7fd4d7a791 ("[PATCH] Add the -fstack-protector option to the CFLAGS")
Fixes 60a5317ff0f4 ("x86: implement x86_32 stack protector")
Quoted 7 lines

---
I think this could go via either -tip or Kbuild?

Perhaps this is an issue in the clang commit mentioned in the message above since it deviates from GCC (Fangrui is on CC here) but I think the combination of these options is a little dubious to begin with, hence this change.

As part of my stack protector cleanup series, I found that these scripts can simply be removed. I can repost those patches as a standalone cleanup.

https://lore.kernel.org/lkml/[email protected]/

Brian Gerst

Quoted 7 lines
Quoted 4 lines

Judging from the Fixes tags, Nathan meant this patch is
a back-port candidate so that the latest LLVM can be used for stable kernels.

You are making big changes, and do you mean they can be back-ported?

I was referring to just the first two patches of that series. That said, it would be simpler to take Nathan's fix for backporting.

Even the first two patches are not trivial.

The second patch 02/16:
https://lore.kernel.org/lkml/[email protected]/

is completely removing scripts/gcc-x86_64-has-stack-protector.sh,

In fact, I also noticed it was a workaround for old buggy compilers. I attempted to do the equivalent clean up, then it was rejected.
https://lore.kernel.org/lkml/[email protected]/

It was 6 years ago, so the situation might have changed. Good luck.

--
Best Regards
Masahiro Yamada

#5 lore raw
Quoted 69 lines · Masahiro Yamada
Quoted 49 lines · Brian Gerst
Quoted 47 lines · Masahiro Yamada
Quoted 44 lines · Brian Gerst
Quoted 27 lines · Nathan Chancellor

After a recent change in clang to stop consuming all instances of '-S' and '-c' [1], the stack protector scripts break due to the kernel's use of -Werror=unused-command-line-argument to catch cases where flags are not being properly consumed by the compiler driver:

  $ echo | clang -o - -x c - -S -c -Werror=unused-command-line-argument
  clang: error: argument unused during compilation: '-c' [-Werror,-Wunused-command-line-argument]

This results in CONFIG_STACKPROTECTOR getting disabled because CONFIG_CC_HAS_SANE_STACKPROTECTOR is no longer set.

'-c' and '-S' both instruct the compiler to stop at different stages of the pipeline ('-S' after compiling, '-c' after assembling), so having them present together in the same command makes little sense. In this case, the test wants to stop before assembling because it is looking at the textual assembly output of the compiler for either '%fs' or '%gs', so remove '-c' from the list of arguments to resolve the error.

All versions of GCC continue to work after this change, along with versions of clang that do or do not contain the change mentioned above.

Fixes 4f7fd4d7a791 ("[PATCH] Add the -fstack-protector option to the CFLAGS")
Fixes 60a5317ff0f4 ("x86: implement x86_32 stack protector")
Quoted 7 lines

---
I think this could go via either -tip or Kbuild?

Perhaps this is an issue in the clang commit mentioned in the message above since it deviates from GCC (Fangrui is on CC here) but I think the combination of these options is a little dubious to begin with, hence this change.

As part of my stack protector cleanup series, I found that these scripts can simply be removed. I can repost those patches as a standalone cleanup.

https://lore.kernel.org/lkml/[email protected]/

Brian Gerst

Quoted 7 lines
Quoted 4 lines

Judging from the Fixes tags, Nathan meant this patch is
a back-port candidate so that the latest LLVM can be used for stable kernels.

You are making big changes, and do you mean they can be back-ported?

I was referring to just the first two patches of that series. That said, it would be simpler to take Nathan's fix for backporting.

Even the first two patches are not trivial.

The second patch 02/16:
https://lore.kernel.org/lkml/[email protected]/

is completely removing scripts/gcc-x86_64-has-stack-protector.sh,

Quoted 6 lines

In fact, I also noticed it was a workaround for old buggy compilers. I attempted to do the equivalent clean up, then it was rejected.
https://lore.kernel.org/lkml/[email protected]/

It was 6 years ago, so the situation might have changed. Good luck.

It's a workaround for an old buggy compiler that isn't even supported by the kernel anymore.

Brian Gerst

Quoted 10 lines

--
Best Regards
Masahiro Yamada

#7 lore raw
In reply to Nathan Chancellor
Quoted 22 lines · Nathan Chancellor

After a recent change in clang to stop consuming all instances of '-S' and '-c' [1], the stack protector scripts break due to the kernel's use of -Werror=unused-command-line-argument to catch cases where flags are not being properly consumed by the compiler driver:

  $ echo | clang -o - -x c - -S -c -Werror=unused-command-line-argument
  clang: error: argument unused during compilation: '-c' [-Werror,-Wunused-command-line-argument]

This results in CONFIG_STACKPROTECTOR getting disabled because CONFIG_CC_HAS_SANE_STACKPROTECTOR is no longer set.

'-c' and '-S' both instruct the compiler to stop at different stages of the pipeline ('-S' after compiling, '-c' after assembling), so having them present together in the same command makes little sense. In this case, the test wants to stop before assembling because it is looking at the textual assembly output of the compiler for either '%fs' or '%gs', so remove '-c' from the list of arguments to resolve the error.

All versions of GCC continue to work after this change, along with versions of clang that do or do not contain the change mentioned above.

Quoted 7 lines
Fixes 4f7fd4d7a791 ("[PATCH] Add the -fstack-protector option to the CFLAGS")
Fixes 60a5317ff0f4 ("x86: implement x86_32 stack protector")

---
I think this could go via either -tip or Kbuild?

Applied to linux-kbuild/fixes, and included in the pull request. Thanks!

Signature · 2 lines
Best Regards
Masahiro Yamada