linux-stable/arch/um
Nathan Chancellor fd06e32ea4 um: Fix adding '-no-pie' for clang
commit 846cfbeed0 upstream.

The kernel builds with -fno-PIE, so commit 883354afbc ("um: link
vmlinux with -no-pie") added the compiler linker flag '-no-pie' via
cc-option because '-no-pie' was only supported in GCC 6.1.0 and newer.

While this works for GCC, this does not work for clang because cc-option
uses '-c', which stops the pipeline right before linking, so '-no-pie'
is unconsumed and clang warns, causing cc-option to fail just as it
would if the option was entirely unsupported:

  $ clang -Werror -no-pie -c -o /dev/null -x c /dev/null
  clang-16: error: argument unused during compilation: '-no-pie' [-Werror,-Wunused-command-line-argument]

A recent version of clang exposes this because it generates a relocation
under '-mcmodel=large' that is not supported in PIE mode:

  /usr/sbin/ld: init/main.o: relocation R_X86_64_32 against symbol `saved_command_line' can not be used when making a PIE object; recompile with -fPIE
  /usr/sbin/ld: failed to set dynamic section sizes: bad value
  clang: error: linker command failed with exit code 1 (use -v to see invocation)

Remove the cc-option check altogether. It is wasteful to invoke the
compiler to check for '-no-pie' because only one supported compiler
version does not support it, GCC 5.x (as it is supported with the
minimum version of clang and GCC 6.1.0+). Use a combination of the
gcc-min-version macro and CONFIG_CC_IS_CLANG to unconditionally add
'-no-pie' with CONFIG_LD_SCRIPT_DYN=y, so that it is enabled with all
compilers that support this. Furthermore, using gcc-min-version can help
turn this back into

  LINK-$(CONFIG_LD_SCRIPT_DYN) += -no-pie

when the minimum version of GCC is bumped past 6.1.0.

Cc: stable@vger.kernel.org
Closes: https://github.com/ClangBuiltLinux/linux/issues/1982
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-02-23 09:25:03 +01:00
..
configs um: Fix hostaudio build errors 2023-08-19 23:30:22 +02:00
drivers um: net: Fix return type of uml_net_start_xmit() 2024-02-05 20:14:31 +00:00
include work around gcc bugs with 'asm goto' with outputs 2024-02-23 09:24:47 +01:00
kernel um: time-travel: fix time corruption 2024-02-05 20:14:31 +00:00
os-Linux um: Don't use vfprintf() for os_info() 2024-02-05 20:14:31 +00:00
scripts um: prevent user code in modules 2023-04-20 23:06:38 +02:00
.gitignore um: gitignore: Add kernel/capflags.c 2021-12-21 21:22:43 +01:00
Kbuild um: use obj-y to descend into arch/um/*/ 2023-08-26 22:41:34 +02:00
Kconfig Landlock updates for v6.5-rc1 2023-06-27 17:10:27 -07:00
Kconfig.debug
Makefile um: Fix adding '-no-pie' for clang 2024-02-23 09:25:03 +01:00
Makefile-os-Linux
Makefile-skas