All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] Make the segment base match pinned section address
@ 2025-09-05  3:22 Khem Raj
  2025-09-23 16:50 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: Khem Raj @ 2025-09-05  3:22 UTC (permalink / raw)
  To: kexec; +Cc: Khem Raj

ET_EXEC uses image base of 0x400000, but the build forces
section VMAs like .text = 0x10000. LLD now errors when any
section address is below the image base unless you explicitly
set the base. (Older LLD tolerated it.)

To fix this

use a tiny linker script to keep .text at 0x10000 and avoid .note overlap

With hardcoded -Ttext,0x10000 and newer toolchains emitting
.note.gnu.property before .text, the link can fail with an overlap.
Provide a minimal linker script that:
  - sets the image base to 0x10000,
  - places .text first at exactly 0x10000,
  - moves .note.gnu.property after .text,
  - optionally fixes .bss at 0x12000.

Works with both ld.bfd and LLD 21+.

Fixes
| x86_64-yoe-linux-ld.lld: error: section '.text' address (0x10000) is smaller than image base (0x400000); specify --image-base
| x86_64-yoe-linux-ld.lld: error: section '.bss' address (0x12000) is smaller than image base (0x400000); specify --image-base

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
v2: Use a tiny linker script instead of trying to use linker options like -Ttext
    to make it portable across BFD linker and LLD

 kexec_test/Makefile      |  4 ++--
 kexec_test/kexec_test.ld | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)
 create mode 100644 kexec_test/kexec_test.ld

diff --git a/kexec_test/Makefile b/kexec_test/Makefile
index fec6210..2ae66af 100644
--- a/kexec_test/Makefile
+++ b/kexec_test/Makefile
@@ -5,7 +5,7 @@ RELOC:=0x10000
 KEXEC_TEST_SRCS:= kexec_test/kexec_test16.S kexec_test/kexec_test.S
 
 dist += kexec_test/Makefile $(KEXEC_TEST_SRCS)				\
-	kexec_test/x86-setup-legacy-pic.S
+	kexec_test/x86-setup-legacy-pic.S kexec_test/kexec_test.ld
 
 BUILD_KEXEC_TEST = no
 ifeq ($(ARCH),i386)
@@ -31,7 +31,7 @@ $(KEXEC_TEST): CPPFLAGS+=-DRELOC=$(RELOC)
 $(KEXEC_TEST): ASFLAGS+=-m32
 #$(KEXEC_TEST): LDFLAGS=-m32 -Wl,-e -Wl,_start -Wl,-Ttext -Wl,$(RELOC) \
 #		       -nostartfiles
-$(KEXEC_TEST): LDFLAGS=-melf_i386 -e _start -Ttext $(RELOC)
+$(KEXEC_TEST): LDFLAGS=-melf_i386 -e _start -T $(srcdir)/kexec_test/kexec_test.ld
 
 $(KEXEC_TEST): $(KEXEC_TEST_OBJS)
 	mkdir -p $(@D)
diff --git a/kexec_test/kexec_test.ld b/kexec_test/kexec_test.ld
new file mode 100644
index 0000000..f68dcf8
--- /dev/null
+++ b/kexec_test/kexec_test.ld
@@ -0,0 +1,16 @@
+ENTRY(_start)
+SECTIONS
+{
+  . = 0x10000;
+  .text : { *(.text .text.*) }
+
+  /* Place the note after .text to avoid overlap */
+  . = ALIGN(16);
+  .note.gnu.property : { *(.note.gnu.property) }
+
+  .rodata : { *(.rodata .rodata.*) }
+
+  /* If you need bss fixed: */
+  . = 0x12000;
+  .bss : { *(.bss .bss.* COMMON) }
+}


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

* Re: [PATCH v2] Make the segment base match pinned section address
  2025-09-05  3:22 [PATCH v2] Make the segment base match pinned section address Khem Raj
@ 2025-09-23 16:50 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2025-09-23 16:50 UTC (permalink / raw)
  To: Khem Raj; +Cc: kexec

On Thu, Sep 04, 2025 at 08:22:52PM -0700, Khem Raj wrote:
> ET_EXEC uses image base of 0x400000, but the build forces
> section VMAs like .text = 0x10000. LLD now errors when any
> section address is below the image base unless you explicitly
> set the base. (Older LLD tolerated it.)
> 
> To fix this
> 
> use a tiny linker script to keep .text at 0x10000 and avoid .note overlap
> 
> With hardcoded -Ttext,0x10000 and newer toolchains emitting
> .note.gnu.property before .text, the link can fail with an overlap.
> Provide a minimal linker script that:
>   - sets the image base to 0x10000,
>   - places .text first at exactly 0x10000,
>   - moves .note.gnu.property after .text,
>   - optionally fixes .bss at 0x12000.
> 
> Works with both ld.bfd and LLD 21+.
> 
> Fixes
> | x86_64-yoe-linux-ld.lld: error: section '.text' address (0x10000) is smaller than image base (0x400000); specify --image-base
> | x86_64-yoe-linux-ld.lld: error: section '.bss' address (0x12000) is smaller than image base (0x400000); specify --image-base
> 
> Signed-off-by: Khem Raj <raj.khem@gmail.com>
> ---
> v2: Use a tiny linker script instead of trying to use linker options like -Ttext
>     to make it portable across BFD linker and LLD

Thanks, applied.

- Make the segment base match pinned section address
  https://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git/commit/?id=efb97b509b1a


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

end of thread, other threads:[~2025-09-23 16:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-05  3:22 [PATCH v2] Make the segment base match pinned section address Khem Raj
2025-09-23 16:50 ` Simon Horman

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.