Blob Blame History Raw
From fa71cc4400924859467812705749ee9b98b3eec6 Mon Sep 17 00:00:00 2001
From: Oscar Salvador <osalvador@suse.de>
Date: Wed, 5 Oct 2022 18:09:21 +0200
Subject: [PATCH] arm64: Discard .note.GNU-stack section

Git-commit: 99cb0d917ffa1ab628bb67364ca9b162c07699b1 (partial - arm64 only)
Patch-mainline: v6.2-rc2
References: bsc#1203693 bsc#1209798

Note: the more general upstream solution requires at least

4b9880dbf3bd powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT
07b050f9290e powerpc/vmlinux.lds: Don't discard .rela* for relocatable builds
a494398bde27 s390: define RUNTIME_DISCARD_EXIT to fix link error with GNU ld < 2.36

which are not applicable to the 4.12 kernel

Commit "Makefile: link with -z noexecstack --no-warn-rwx-segments: ddbd47d2219a"
creates a new section .note.GNU-stack, which is not discarded by arm64.
This changes the ELF layout and causes the build to fail on arm64.

Quoting Michal Matz:

 "The .note.GNU-stack section in head.o is created by 'ld -r -z noexecstack',
  when relinking head.o into head.o (for various reasons).  That section is created
  with SHT_PROGBITS, and as the kernel linker script doesn't discard those
  it also makes the output ".notes" section (which
  collects all .note* sections) SHT_PROGBITS, which in turn makes ld not generate
  a PT_NOTE segment covering all these.

  Now, I initially thought the linker with 'ld -r', when generating a
  .note.GNU-stack section because of a command line option should simply create it
  with the type SHT_NOTE and all would be well.  That somewhat works, but is actually
  wrong: a SHT_NOTE section has a specific layout per the gABI (at least
  it must contain a header), but .note.GNU-stack is empty.  So it really can't
  be SHT_NOTE but must remain either SHT_PROGBITS or SHT_NOBITS."

Fix it for now by discarding that section.

Signed-off-by: Oscar Salvador <osalvador@suse.de>
Suggested-by: Michael Matz <matz@suse.com"
---
 arch/arm64/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -99,6 +99,7 @@ SECTIONS
 		*(.discard.*)
 		*(.interp .dynamic)
 		*(.dynsym .dynstr .hash .gnu.hash)
+		*(.note.GNU-stack)
 		*(.eh_frame)
 	}