All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: Discard .note.gnu.property sections
@ 2021-06-17 16:12 Bin Meng
  2021-06-17 22:07 ` Tom Rini
  0 siblings, 1 reply; 3+ messages in thread
From: Bin Meng @ 2021-06-17 16:12 UTC (permalink / raw)
  To: Simon Glass, Tom Rini, u-boot; +Cc: Bin Meng

When switching to kernel.org x86_64 gcc 11.1.0 toolchain, u-boot.rom
built from qemu-x86_defconfig no longer boots anymore. Investigation
shows that U-Boot fails at a very early stage during the boot process,
in fdtdec_prepare_fdt() where fdt_check_header() complains that there
is not a valid device tree found at gd->fdt_blob which points to _end.
Now _end points to an allocated section .note.gnu.property which of
course is wrong.

This issue is however not seen when using the default Ubuntu 20.04 gnu
toolchain (gcc 9.3.0 with binutils 2.34). Further investigation shows
that it is caused by a behavior change of binutils v2.36 which is part
of the kernel.org gcc 11.1.0 toolchain, via the following commit:

  939b95c77bf2 ("Linux/x86: Configure gas with --enable-x86-used-note by default")

In fact, there was already a regression bug report [1] for binutils two
months ago, but the binutils folks did not think it is a bug :(

To resolve this, there are several options:

* pass -Wa,-mx86-used-note=no to gas
* pass -R .note.gnu.property to objcopy
* discard the section in the linker script

Linux kernel uses the discard way [2], so let's do the same for U-Boot.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=27753
[2] commit 4caffe6a28d3 ("x86/vdso: Discard .note.gnu.property sections in vDSO")

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 arch/x86/cpu/u-boot.lds | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/cpu/u-boot.lds b/arch/x86/cpu/u-boot.lds
index a283c290ee..22fde01e74 100644
--- a/arch/x86/cpu/u-boot.lds
+++ b/arch/x86/cpu/u-boot.lds
@@ -105,6 +105,7 @@ SECTIONS
 	/DISCARD/ : { *(.plt*) }
 	/DISCARD/ : { *(.interp*) }
 	/DISCARD/ : { *(.gnu*) }
+	/DISCARD/ : { *(.note.gnu.property) }
 
 #ifdef CONFIG_X86_16BIT_INIT
 	/*
-- 
2.25.1


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

* Re: [PATCH] x86: Discard .note.gnu.property sections
  2021-06-17 16:12 [PATCH] x86: Discard .note.gnu.property sections Bin Meng
@ 2021-06-17 22:07 ` Tom Rini
  0 siblings, 0 replies; 3+ messages in thread
From: Tom Rini @ 2021-06-17 22:07 UTC (permalink / raw)
  To: Bin Meng; +Cc: Simon Glass, u-boot

[-- Attachment #1: Type: text/plain, Size: 1570 bytes --]

On Fri, Jun 18, 2021 at 12:12:28AM +0800, Bin Meng wrote:

> When switching to kernel.org x86_64 gcc 11.1.0 toolchain, u-boot.rom
> built from qemu-x86_defconfig no longer boots anymore. Investigation
> shows that U-Boot fails at a very early stage during the boot process,
> in fdtdec_prepare_fdt() where fdt_check_header() complains that there
> is not a valid device tree found at gd->fdt_blob which points to _end.
> Now _end points to an allocated section .note.gnu.property which of
> course is wrong.
> 
> This issue is however not seen when using the default Ubuntu 20.04 gnu
> toolchain (gcc 9.3.0 with binutils 2.34). Further investigation shows
> that it is caused by a behavior change of binutils v2.36 which is part
> of the kernel.org gcc 11.1.0 toolchain, via the following commit:
> 
>   939b95c77bf2 ("Linux/x86: Configure gas with --enable-x86-used-note by default")
> 
> In fact, there was already a regression bug report [1] for binutils two
> months ago, but the binutils folks did not think it is a bug :(
> 
> To resolve this, there are several options:
> 
> * pass -Wa,-mx86-used-note=no to gas
> * pass -R .note.gnu.property to objcopy
> * discard the section in the linker script
> 
> Linux kernel uses the discard way [2], so let's do the same for U-Boot.
> 
> [1] https://sourceware.org/bugzilla/show_bug.cgi?id=27753
> [2] commit 4caffe6a28d3 ("x86/vdso: Discard .note.gnu.property sections in vDSO")
> 
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

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

* [PATCH] x86: Discard .note.gnu.property sections
@ 2018-09-24 20:14 H.J. Lu
  0 siblings, 0 replies; 3+ messages in thread
From: H.J. Lu @ 2018-09-24 20:14 UTC (permalink / raw)
  To: linux-kernel; +Cc: Yu-cheng Yu

With the command-line option, -mx86-used-note=yes, the x86 assembler
in binutils 2.32 and above generates a program property note in a note
section, .note.gnu.property, to encode used x86 ISAs and features.
To exclude .note.gnu.property sections from NOTE segment in x86 kernel
linker script:

PHDRS {
 text PT_LOAD FLAGS(5);
 data PT_LOAD FLAGS(6);
 percpu PT_LOAD FLAGS(6);
 init PT_LOAD FLAGS(7);
 note PT_NOTE FLAGS(0);
}
SECTIONS
{
...
 .notes : AT(ADDR(.notes) - 0xffffffff80000000) { __start_notes = .; KEEP(*(.not
e.*)) __stop_notes = .; } :text :note
...
}

this patch discards .note.gnu.property sections in kernel linker script
by adding

 /DISCARD/ : {
  *(.note.gnu.property)
 }

before .notes sections.  Since .exit.text and .exit.data sections are
discarded at runtime, it undefines EXIT_TEXT and EXIT_DATA to exclude
.exit.text and .exit.data sections from default discarded sections.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
 arch/x86/kernel/vmlinux.lds.S | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 8bde0a419f86..7e1e0ef1578a 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -138,6 +138,10 @@ SECTIONS
 		_etext = .;
 	} :text = 0x9090
 
+	/* .note.gnu.property sections should be discarded */
+	/DISCARD/ : {
+		*(.note.gnu.property)
+	}
 	NOTES :text :note
 
 	EXCEPTION_TABLE(16) :text = 0x9090
@@ -373,7 +377,12 @@ SECTIONS
 	STABS_DEBUG
 	DWARF_DEBUG
 
-	/* Sections to be discarded */
+	/* Sections to be discarded.  EXIT_TEXT and EXIT_DATA discard at runtime.
+	 * not link time.  */
+#undef EXIT_TEXT
+#define EXIT_TEXT
+#undef EXIT_DATA
+#define EXIT_DATA
 	DISCARDS
 	/DISCARD/ : {
 		*(.eh_frame)
-- 
2.17.1


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

end of thread, other threads:[~2021-06-17 22:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-17 16:12 [PATCH] x86: Discard .note.gnu.property sections Bin Meng
2021-06-17 22:07 ` Tom Rini
  -- strict thread matches above, loose matches on Subject: below --
2018-09-24 20:14 H.J. Lu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.