linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] powerpc/64: ELFv2 conversion
@ 2023-06-06  9:38 Nicholas Piggin
  2023-06-06  9:38 ` [PATCH v2 1/4] powerpc/64: Force ELFv2 when building with LLVM linker Nicholas Piggin
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Nicholas Piggin @ 2023-06-06  9:38 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Naveen N . Rao, Nicholas Piggin

This is a follow on from the series here

https://lore.kernel.org/linuxppc-dev/20230505071850.228734-1-npiggin@gmail.com/

With feedback addressed and Christophe's -mprofile-kernel for BE added,

https://lore.kernel.org/linuxppc-dev/20230506011814.8766-1-npiggin@gmail.com/

And dropped the last RFC patch that removes ELFv1 entirely. Maybe we can
wait one or two releases after this before doing that.

Thanks,
Nick

Nicholas Piggin (4):
  powerpc/64: Force ELFv2 when building with LLVM linker
  powerpc/64: Make ELFv2 the default for big-endian builds
  powerpc/64: Use -mprofile-kernel for big endian ELFv2 kernels
  powerpc/64s: Remove support for ELFv1 little endian userspace

 arch/powerpc/Kconfig                            | 13 +++++++------
 arch/powerpc/include/asm/elf.h                  |  6 ++++++
 arch/powerpc/include/asm/thread_info.h          |  6 +++++-
 arch/powerpc/tools/gcc-check-mprofile-kernel.sh | 11 ++++++-----
 4 files changed, 24 insertions(+), 12 deletions(-)

-- 
2.40.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/4] powerpc/64: Force ELFv2 when building with LLVM linker
  2023-06-06  9:38 [PATCH v2 0/4] powerpc/64: ELFv2 conversion Nicholas Piggin
@ 2023-06-06  9:38 ` Nicholas Piggin
  2023-06-06  9:38 ` [PATCH v2 2/4] powerpc/64: Make ELFv2 the default for big-endian builds Nicholas Piggin
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Nicholas Piggin @ 2023-06-06  9:38 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Nathan Chancellor, Naveen N . Rao, Nicholas Piggin

The LLVM linker does not support ELFv1 at all, so BE kernels must be
built with ELFv2. The LLD version check was added to be conservative,
LLD simply fails to link ELFv1 entirely, effectively requiring LLD >= 15
and ELFv2 for BE builds. Instead remove that restriction until proven
otherwise (LLD 14.0 links a booting ELFv2 BE vmlinux for me).

The minimum GNU binutils has increased such that ELFv2 is always
supported, so remove that check while we're here.

Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/Kconfig | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index bff5820b7cda..e34ff0e59585 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -624,10 +624,10 @@ config ARCH_HAS_KEXEC_PURGATORY
 	def_bool KEXEC_FILE
 
 config PPC64_BIG_ENDIAN_ELF_ABI_V2
-	bool "Build big-endian kernel using ELF ABI V2 (EXPERIMENTAL)"
+	prompt "Build big-endian kernel using ELF ABI V2 (EXPERIMENTAL)" if LD_IS_BFD
+	def_bool y if LD_IS_LLD
 	depends on PPC64 && CPU_BIG_ENDIAN
 	depends on CC_HAS_ELFV2
-	depends on LD_VERSION >= 22400 || LLD_VERSION >= 150000
 	help
 	  This builds the kernel image using the "Power Architecture 64-Bit ELF
 	  V2 ABI Specification", which has a reduced stack overhead and faster
@@ -638,8 +638,6 @@ config PPC64_BIG_ENDIAN_ELF_ABI_V2
 	  it is less well tested by kernel and toolchain. However some distros
 	  build userspace this way, and it can produce a functioning kernel.
 
-	  This requires GCC and binutils 2.24 or newer.
-
 config RELOCATABLE
 	bool "Build a relocatable kernel"
 	depends on PPC64 || (FLATMEM && (44x || PPC_85xx))
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/4] powerpc/64: Make ELFv2 the default for big-endian builds
  2023-06-06  9:38 [PATCH v2 0/4] powerpc/64: ELFv2 conversion Nicholas Piggin
  2023-06-06  9:38 ` [PATCH v2 1/4] powerpc/64: Force ELFv2 when building with LLVM linker Nicholas Piggin
@ 2023-06-06  9:38 ` Nicholas Piggin
  2023-06-06  9:38 ` [PATCH v2 3/4] powerpc/64: Use -mprofile-kernel for big endian ELFv2 kernels Nicholas Piggin
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Nicholas Piggin @ 2023-06-06  9:38 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Naveen N . Rao, Nicholas Piggin

All supported toolchains now support ELFv2 on big-endian, so flip the
default on this and hide the option behind EXPERT for the purpose of
bug hunting.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/Kconfig | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index e34ff0e59585..296e0448b5fc 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -624,8 +624,10 @@ config ARCH_HAS_KEXEC_PURGATORY
 	def_bool KEXEC_FILE
 
 config PPC64_BIG_ENDIAN_ELF_ABI_V2
-	prompt "Build big-endian kernel using ELF ABI V2 (EXPERIMENTAL)" if LD_IS_BFD
-	def_bool y if LD_IS_LLD
+	# Option is available to BFD, but LLD does not support ELFv1 so this is
+	# always true there.
+	prompt "Build big-endian kernel using ELF ABI V2" if LD_IS_BFD && EXPERT
+	def_bool y
 	depends on PPC64 && CPU_BIG_ENDIAN
 	depends on CC_HAS_ELFV2
 	help
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/4] powerpc/64: Use -mprofile-kernel for big endian ELFv2 kernels
  2023-06-06  9:38 [PATCH v2 0/4] powerpc/64: ELFv2 conversion Nicholas Piggin
  2023-06-06  9:38 ` [PATCH v2 1/4] powerpc/64: Force ELFv2 when building with LLVM linker Nicholas Piggin
  2023-06-06  9:38 ` [PATCH v2 2/4] powerpc/64: Make ELFv2 the default for big-endian builds Nicholas Piggin
@ 2023-06-06  9:38 ` Nicholas Piggin
  2023-06-06  9:38 ` [PATCH v2 4/4] powerpc/64s: Remove support for ELFv1 little endian userspace Nicholas Piggin
  2023-07-03  5:26 ` [PATCH v2 0/4] powerpc/64: ELFv2 conversion Michael Ellerman
  4 siblings, 0 replies; 6+ messages in thread
From: Nicholas Piggin @ 2023-06-06  9:38 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Naveen N . Rao, Nicholas Piggin

-mprofile-kernel is an optimised calling convention for mcount that
Linux  has only implemented with the ELFv2 ABI, so it was disabled for
big endian kernels. However it does work with ELFv2 big endian, so let's
allow that if the compiler supports it.

Acked-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Suggested-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/Kconfig                            |  5 +++--
 arch/powerpc/tools/gcc-check-mprofile-kernel.sh | 11 ++++++-----
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 296e0448b5fc..9db707829638 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -547,8 +547,9 @@ config LD_HEAD_STUB_CATCH
 	  If unsure, say "N".
 
 config MPROFILE_KERNEL
-	depends on PPC64 && CPU_LITTLE_ENDIAN && FUNCTION_TRACER
-	def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-mprofile-kernel.sh $(CC) -I$(srctree)/include -D__KERNEL__)
+	depends on PPC64_ELF_ABI_V2 && FUNCTION_TRACER
+	def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-mprofile-kernel.sh $(CC) -mlittle-endian) if CPU_LITTLE_ENDIAN
+	def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-mprofile-kernel.sh $(CC) -mbig-endian) if CPU_BIG_ENDIAN
 
 config HOTPLUG_CPU
 	bool "Support for enabling/disabling CPUs"
diff --git a/arch/powerpc/tools/gcc-check-mprofile-kernel.sh b/arch/powerpc/tools/gcc-check-mprofile-kernel.sh
index 137f3376ac2b..a31a56016c09 100755
--- a/arch/powerpc/tools/gcc-check-mprofile-kernel.sh
+++ b/arch/powerpc/tools/gcc-check-mprofile-kernel.sh
@@ -7,20 +7,21 @@ set -o pipefail
 # To debug, uncomment the following line
 # set -x
 
-# -mprofile-kernel is only supported on 64le, so this should not be invoked
-# for other targets. Therefore we can pass in -m64 and -mlittle-endian
-# explicitly, to take care of toolchains defaulting to other targets.
+# -mprofile-kernel is only supported on 64-bit, so this should not be invoked
+# for 32-bit. We pass in -m64 explicitly, and -mbig-endian and -mlittle-endian
+# are passed in from Kconfig, which takes care of toolchains defaulting to
+# other targets.
 
 # Test whether the compile option -mprofile-kernel exists and generates
 # profiling code (ie. a call to _mcount()).
 echo "int func() { return 0; }" | \
-    $* -m64 -mlittle-endian -S -x c -O2 -p -mprofile-kernel - -o - \
+    $* -m64 -S -x c -O2 -p -mprofile-kernel - -o - \
     2> /dev/null | grep -q "_mcount"
 
 # Test whether the notrace attribute correctly suppresses calls to _mcount().
 
 echo -e "#include <linux/compiler.h>\nnotrace int func() { return 0; }" | \
-    $* -m64 -mlittle-endian -S -x c -O2 -p -mprofile-kernel - -o - \
+    $* -m64 -S -x c -O2 -p -mprofile-kernel - -o - \
     2> /dev/null | grep -q "_mcount" && \
     exit 1
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 4/4] powerpc/64s: Remove support for ELFv1 little endian userspace
  2023-06-06  9:38 [PATCH v2 0/4] powerpc/64: ELFv2 conversion Nicholas Piggin
                   ` (2 preceding siblings ...)
  2023-06-06  9:38 ` [PATCH v2 3/4] powerpc/64: Use -mprofile-kernel for big endian ELFv2 kernels Nicholas Piggin
@ 2023-06-06  9:38 ` Nicholas Piggin
  2023-07-03  5:26 ` [PATCH v2 0/4] powerpc/64: ELFv2 conversion Michael Ellerman
  4 siblings, 0 replies; 6+ messages in thread
From: Nicholas Piggin @ 2023-06-06  9:38 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Naveen N . Rao, Nicholas Piggin

ELFv2 was introduced together with little-endian. ELFv1 with LE has
never been a thing. The GNU toolchain can create such a beast, but
anyone doing that is a maniac who needs to be stopped so I consider
this patch a feature.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/include/asm/elf.h         | 6 ++++++
 arch/powerpc/include/asm/thread_info.h | 6 +++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
index 79f1c480b5eb..a26ca097d032 100644
--- a/arch/powerpc/include/asm/elf.h
+++ b/arch/powerpc/include/asm/elf.h
@@ -12,8 +12,14 @@
 
 /*
  * This is used to ensure we don't load something for the wrong architecture.
+ * 64le only supports ELFv2 64-bit binaries (64be supports v1 and v2).
  */
+#if defined(CONFIG_PPC64) && defined(CONFIG_CPU_LITTLE_ENDIAN)
+#define elf_check_arch(x) (((x)->e_machine == ELF_ARCH) && \
+			   (((x)->e_flags & 0x3) == 0x2))
+#else
 #define elf_check_arch(x) ((x)->e_machine == ELF_ARCH)
+#endif
 #define compat_elf_check_arch(x)	((x)->e_machine == EM_PPC)
 
 #define CORE_DUMP_USE_REGSET
diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
index bf5dde1a4114..bc5d39a835fe 100644
--- a/arch/powerpc/include/asm/thread_info.h
+++ b/arch/powerpc/include/asm/thread_info.h
@@ -183,9 +183,13 @@ static inline bool test_thread_local_flags(unsigned int flags)
 #define clear_tsk_compat_task(tsk) do { } while (0)
 #endif
 
-#if defined(CONFIG_PPC64)
+#ifdef CONFIG_PPC64
+#ifdef CONFIG_CPU_BIG_ENDIAN
 #define is_elf2_task() (test_thread_flag(TIF_ELF2ABI))
 #else
+#define is_elf2_task() (1)
+#endif
+#else
 #define is_elf2_task() (0)
 #endif
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/4] powerpc/64: ELFv2 conversion
  2023-06-06  9:38 [PATCH v2 0/4] powerpc/64: ELFv2 conversion Nicholas Piggin
                   ` (3 preceding siblings ...)
  2023-06-06  9:38 ` [PATCH v2 4/4] powerpc/64s: Remove support for ELFv1 little endian userspace Nicholas Piggin
@ 2023-07-03  5:26 ` Michael Ellerman
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2023-07-03  5:26 UTC (permalink / raw)
  To: linuxppc-dev, Nicholas Piggin; +Cc: Naveen N . Rao

On Tue, 06 Jun 2023 19:38:28 +1000, Nicholas Piggin wrote:
> This is a follow on from the series here
> 
> https://lore.kernel.org/linuxppc-dev/20230505071850.228734-1-npiggin@gmail.com/
> 
> With feedback addressed and Christophe's -mprofile-kernel for BE added,
> 
> https://lore.kernel.org/linuxppc-dev/20230506011814.8766-1-npiggin@gmail.com/
> 
> [...]

Applied to powerpc/next.

[1/4] powerpc/64: Force ELFv2 when building with LLVM linker
      https://git.kernel.org/powerpc/c/9d90161ca5c7234e80e14e563d198f322ca0c1d0
[2/4] powerpc/64: Make ELFv2 the default for big-endian builds
      https://git.kernel.org/powerpc/c/8c5fa3b5c4df3d071dab42b04b971df370d99354
[3/4] powerpc/64: Use -mprofile-kernel for big endian ELFv2 kernels
      https://git.kernel.org/powerpc/c/aec0ba7472a7b0c1c293932e7978197f1489a332
[4/4] powerpc/64s: Remove support for ELFv1 little endian userspace
      https://git.kernel.org/powerpc/c/606787fed7268feb256957872586370b56af697a

cheers

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-03  5:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-06  9:38 [PATCH v2 0/4] powerpc/64: ELFv2 conversion Nicholas Piggin
2023-06-06  9:38 ` [PATCH v2 1/4] powerpc/64: Force ELFv2 when building with LLVM linker Nicholas Piggin
2023-06-06  9:38 ` [PATCH v2 2/4] powerpc/64: Make ELFv2 the default for big-endian builds Nicholas Piggin
2023-06-06  9:38 ` [PATCH v2 3/4] powerpc/64: Use -mprofile-kernel for big endian ELFv2 kernels Nicholas Piggin
2023-06-06  9:38 ` [PATCH v2 4/4] powerpc/64s: Remove support for ELFv1 little endian userspace Nicholas Piggin
2023-07-03  5:26 ` [PATCH v2 0/4] powerpc/64: ELFv2 conversion Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).