linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT
@ 2023-01-05 13:23 Michael Ellerman
  2023-01-05 13:23 ` [PATCH 2/3] powerpc/vmlinux.lds: Don't discard .rela* for relocatable builds Michael Ellerman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Michael Ellerman @ 2023-01-05 13:23 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: masahiroy, linux-kernel, linux-arch, schwab, ardb, nathan

The powerpc linker script explicitly includes .exit.text, because
otherwise the link fails due to references from __bug_table and
__ex_table. The code is freed (discarded) at runtime along with
.init.text and data.

That has worked in the past despite powerpc not defining
RUNTIME_DISCARD_EXIT because DISCARDS appears late in the powerpc linker
script (line 410), and the explicit inclusion of .exit.text
earlier (line 280) supersedes the discard.

However commit 99cb0d917ffa ("arch: fix broken BuildID for arm64 and
riscv") introduced an earlier use of DISCARD as part of the RO_DATA
macro (line 136). With binutils < 2.36 that causes the DISCARD
directives later in the script to be applied earlier [1], causing
.exit.text to actually be discarded at link time, leading to build
errors:

  '.exit.text' referenced in section '__bug_table' of crypto/algboss.o: defined in
  discarded section '.exit.text' of crypto/algboss.o
  '.exit.text' referenced in section '__ex_table' of drivers/nvdimm/core.o: defined in
  discarded section '.exit.text' of drivers/nvdimm/core.o

Fix it by defining RUNTIME_DISCARD_EXIT, which causes the generic
DISCARDS macro to not include .exit.text at all.

1: https://lore.kernel.org/lkml/87fscp2v7k.fsf@igel.home/

Fixes: 99cb0d917ffa ("arch: fix broken BuildID for arm64 and riscv")
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index 8c3862b4c259..c5ea7d03d539 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -8,6 +8,7 @@
 #define BSS_FIRST_SECTIONS *(.bss.prominit)
 #define EMITS_PT_NOTE
 #define RO_EXCEPTION_TABLE_ALIGN	0
+#define RUNTIME_DISCARD_EXIT
 
 #define SOFT_MASK_TABLE(align)						\
 	. = ALIGN(align);						\
-- 
2.39.0


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

* [PATCH 2/3] powerpc/vmlinux.lds: Don't discard .rela* for relocatable builds
  2023-01-05 13:23 [PATCH 1/3] powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT Michael Ellerman
@ 2023-01-05 13:23 ` Michael Ellerman
  2023-01-05 13:23 ` [PATCH 3/3] powerpc/vmlinux.lds: Don't discard .comment Michael Ellerman
  2023-01-08 12:49 ` [PATCH 1/3] powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT Michael Ellerman
  2 siblings, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2023-01-05 13:23 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: masahiroy, linux-kernel, linux-arch, schwab, ardb, nathan

Relocatable kernels must not discard relocations, they need to be
processed at runtime. As such they are included for CONFIG_RELOCATABLE
builds in the powerpc linker script (line 340).

However they are also unconditionally discarded later in the
script (line 414). Previously that worked because the earlier inclusion
superseded the discard.

However commit 99cb0d917ffa ("arch: fix broken BuildID for arm64 and
riscv") introduced an earlier use of DISCARD as part of the RO_DATA
macro (line 137). With binutils < 2.36 that causes the DISCARD
directives later in the script to be applied earlier, causing .rela* to
actually be discarded at link time, leading to build warnings and a
kernel that doesn't boot:

  ld: warning: discarding dynamic section .rela.init.rodata

Fix it by conditionally discarding .rela* only when CONFIG_RELOCATABLE
is disabled.

Fixes: 99cb0d917ffa ("arch: fix broken BuildID for arm64 and riscv")
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/kernel/vmlinux.lds.S | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index c5ea7d03d539..a4c6efadc90c 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -411,9 +411,12 @@ SECTIONS
 	DISCARDS
 	/DISCARD/ : {
 		*(*.EMB.apuinfo)
-		*(.glink .iplt .plt .rela* .comment)
+		*(.glink .iplt .plt .comment)
 		*(.gnu.version*)
 		*(.gnu.attributes)
 		*(.eh_frame)
+#ifndef CONFIG_RELOCATABLE
+		*(.rela*)
+#endif
 	}
 }
-- 
2.39.0


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

* [PATCH 3/3] powerpc/vmlinux.lds: Don't discard .comment
  2023-01-05 13:23 [PATCH 1/3] powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT Michael Ellerman
  2023-01-05 13:23 ` [PATCH 2/3] powerpc/vmlinux.lds: Don't discard .rela* for relocatable builds Michael Ellerman
@ 2023-01-05 13:23 ` Michael Ellerman
  2023-01-08 12:49 ` [PATCH 1/3] powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT Michael Ellerman
  2 siblings, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2023-01-05 13:23 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: masahiroy, linux-kernel, linux-arch, schwab, ardb, nathan

Although the powerpc linker script mentions .comment in the DISCARD
section, that has never actually caused it to be discarded, because the
earlier ELF_DETAILS macro (previously STABS_DEBUG) explicitly includes
.comment.

However commit 99cb0d917ffa ("arch: fix broken BuildID for arm64 and
riscv") introduced an earlier use of DISCARD as part of the RO_DATA
macro. With binutils < 2.36 that causes the DISCARD directives later in
the script to be applied earlier, causing .comment to actually be
discarded.

It's confusing to explicitly include and discard .comment, and even more
so if the behaviour depends on the toolchain version. So don't discard
.comment in order to maintain the existing behaviour in all cases.

Fixes: 83a092cf95f2 ("powerpc: Link warning for orphan sections")
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/kernel/vmlinux.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index a4c6efadc90c..958e77a24f85 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -411,7 +411,7 @@ SECTIONS
 	DISCARDS
 	/DISCARD/ : {
 		*(*.EMB.apuinfo)
-		*(.glink .iplt .plt .comment)
+		*(.glink .iplt .plt)
 		*(.gnu.version*)
 		*(.gnu.attributes)
 		*(.eh_frame)
-- 
2.39.0


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

* Re: [PATCH 1/3] powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT
  2023-01-05 13:23 [PATCH 1/3] powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT Michael Ellerman
  2023-01-05 13:23 ` [PATCH 2/3] powerpc/vmlinux.lds: Don't discard .rela* for relocatable builds Michael Ellerman
  2023-01-05 13:23 ` [PATCH 3/3] powerpc/vmlinux.lds: Don't discard .comment Michael Ellerman
@ 2023-01-08 12:49 ` Michael Ellerman
  2 siblings, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2023-01-08 12:49 UTC (permalink / raw)
  To: linuxppc-dev, Michael Ellerman
  Cc: linux-kernel, ardb, masahiroy, schwab, linux-arch, nathan

On Fri, 6 Jan 2023 00:23:47 +1100, Michael Ellerman wrote:
> The powerpc linker script explicitly includes .exit.text, because
> otherwise the link fails due to references from __bug_table and
> __ex_table. The code is freed (discarded) at runtime along with
> .init.text and data.
> 
> That has worked in the past despite powerpc not defining
> RUNTIME_DISCARD_EXIT because DISCARDS appears late in the powerpc linker
> script (line 410), and the explicit inclusion of .exit.text
> earlier (line 280) supersedes the discard.
> 
> [...]

Applied to powerpc/fixes.

[1/3] powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT
      https://git.kernel.org/powerpc/c/4b9880dbf3bdba3a7c56445137c3d0e30aaa0a40
[2/3] powerpc/vmlinux.lds: Don't discard .rela* for relocatable builds
      https://git.kernel.org/powerpc/c/07b050f9290ee012a407a0f64151db902a1520f5
[3/3] powerpc/vmlinux.lds: Don't discard .comment
      https://git.kernel.org/powerpc/c/be5f95c8779e19779dd81927c8574fec5aaba36c

cheers

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

end of thread, other threads:[~2023-01-08 12:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-05 13:23 [PATCH 1/3] powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT Michael Ellerman
2023-01-05 13:23 ` [PATCH 2/3] powerpc/vmlinux.lds: Don't discard .rela* for relocatable builds Michael Ellerman
2023-01-05 13:23 ` [PATCH 3/3] powerpc/vmlinux.lds: Don't discard .comment Michael Ellerman
2023-01-08 12:49 ` [PATCH 1/3] powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT 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).