arch/loongarch/kernel/vmlinux.lds.S | 36 +++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-)
With structure elf64_phdr, field p_paddr is physical address of the
segment. And it is convenient for qemu to calculate the physical
address when directly boot ELF kernel image.
Otherwise QEMU needs convert virtual address p_vaddr into physical
address, the conversion logic assumes that DMW method is used where
48 bit physical address is supported. However with direct MMU mapping
method with start address from 0xFFFF800000000000, only 47 bit physical
address is supported. QEMU cannot assume the kernel behavior at kernel
loading stage.
Here add physical address indication in ELF program header, it is
convenient to get physical kernel loading address.
Here is output with command readelf -l vmlinux with patch:
Elf file type is EXEC (Executable file)
Entry point 0x90000000015f5000
There are 2 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD 0x0000000000010000 0x9000000000200000 0x0000000000200000
0x000000000293b000 0x0000000002a79b98 RWE 0x10000
And output with command readelf -l vmlinux without the patch:
Elf file type is EXEC (Executable file)
Entry point 0x90000000015f5000
There are 2 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD 0x0000000000010000 0x9000000000200000 0x9000000000200000
0x000000000293b000 0x0000000002a79b98 RWE 0x10000
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
v1 ... v2:
1. Set LOAD_OFFSET with PAGE_OFFSET rather than CACHE_BASE, since it
is generic with PAGE_OFFSET.
2. Add AT information with missing edata_padding section.
---
arch/loongarch/kernel/vmlinux.lds.S | 36 +++++++++++++++++++----------
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/arch/loongarch/kernel/vmlinux.lds.S b/arch/loongarch/kernel/vmlinux.lds.S
index 08ea921cdec1..8ce6b0d948f4 100644
--- a/arch/loongarch/kernel/vmlinux.lds.S
+++ b/arch/loongarch/kernel/vmlinux.lds.S
@@ -3,10 +3,12 @@
#include <asm/asm-offsets.h>
#include <asm/thread_info.h>
#include <asm/orc_lookup.h>
+#include <asm/addrspace.h>
#define PAGE_SIZE _PAGE_SIZE
#define RO_EXCEPTION_TABLE_ALIGN 4
#define PHYSADDR_MASK 0xffffffffffff /* 48-bit */
+#define LOAD_OFFSET PAGE_OFFSET
/*
* Put .bss..swapper_pg_dir as the first thing in .bss. This will
@@ -42,7 +44,7 @@ SECTIONS
. = ALIGN(PECOFF_SEGMENT_ALIGN);
_stext = .;
- .text : {
+ .text : AT(ADDR(.text) - LOAD_OFFSET) {
TEXT_TEXT
SCHED_TEXT
LOCK_TEXT
@@ -60,7 +62,7 @@ SECTIONS
__inittext_begin = .;
INIT_TEXT_SECTION(PAGE_SIZE)
- .exit.text : {
+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
EXIT_TEXT
}
@@ -82,7 +84,7 @@ SECTIONS
}
INIT_DATA_SECTION(16)
- .exit.data : {
+ .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
EXIT_DATA
}
@@ -90,7 +92,7 @@ SECTIONS
PERCPU_SECTION(1 << CONFIG_L1_CACHE_SHIFT)
#endif
- .init.bss : {
+ .init.bss : AT(ADDR(.init.bss) - LOAD_OFFSET) {
*(.init.bss)
}
. = ALIGN(PECOFF_SEGMENT_ALIGN);
@@ -101,27 +103,34 @@ SECTIONS
_sdata = .;
RO_DATA(4096)
- .got : ALIGN(16) { *(.got) }
- .plt : ALIGN(16) { *(.plt) }
- .got.plt : ALIGN(16) { *(.got.plt) }
+ . = ALIGN(16);
+ .got : AT(ADDR(.got) - LOAD_OFFSET) { *(.got) }
+ . = ALIGN(16);
+ .plt : AT(ADDR(.plt) - LOAD_OFFSET) { *(.plt) }
+ . = ALIGN(16);
+ .got.plt : AT(ADDR(.got.plt) - LOAD_OFFSET) { *(.got.plt) }
RW_DATA(1 << CONFIG_L1_CACHE_SHIFT, PAGE_SIZE, THREAD_SIZE)
- .rela.dyn : ALIGN(8) {
+ . = ALIGN(8);
+ .rela.dyn : AT(ADDR(.rela.dyn) - LOAD_OFFSET) {
__rela_dyn_begin = .;
*(.rela.dyn) *(.rela*)
__rela_dyn_end = .;
}
#ifdef CONFIG_RELR
- .relr.dyn : ALIGN(8) {
+ . = ALIGN(8);
+ .relr.dyn : AT(ADDR(.relr.dyn) - LOAD_OFFSET) {
__relr_dyn_begin = .;
*(.relr.dyn)
__relr_dyn_end = .;
}
#endif
- .data.rel : { *(.data.rel*) }
+ .data.rel : AT(ADDR(.data.rel) - LOAD_OFFSET) {
+ *(.data.rel*)
+ }
#ifdef CONFIG_RELOCATABLE
. = ALIGN(8);
@@ -134,10 +143,13 @@ SECTIONS
ORC_UNWIND_TABLE
- .sdata : {
+ .sdata : AT(ADDR(.sdata) - LOAD_OFFSET) {
*(.sdata)
}
- .edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGN); }
+ .edata_padding : AT(ADDR(.edata_padding) - LOAD_OFFSET) {
+ BYTE(0);
+ . = ALIGN(PECOFF_FILE_ALIGN);
+ }
_edata = .;
BSS_SECTION(0, SZ_64K, 8)
base-commit: 89be9a83ccf1f88522317ce02f854f30d6115c41
--
2.39.3
Hi Bibo, kernel test robot noticed the following build errors: [auto build test ERROR on 89be9a83ccf1f88522317ce02f854f30d6115c41] url: https://github.com/intel-lab-lkp/linux/commits/Bibo-Mao/LoongArch-Implement-physical-address-with-ELF-program-header/20250721-171418 base: 89be9a83ccf1f88522317ce02f854f30d6115c41 patch link: https://lore.kernel.org/r/20250721091248.3896152-1-maobibo%40loongson.cn patch subject: [PATCH v2] LoongArch: Implement physical address with ELF program header config: loongarch-allnoconfig (https://download.01.org/0day-ci/archive/20250722/202507220309.mDl9W32Y-lkp@intel.com/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 853c343b45b3e83cc5eeef5a52fc8cc9d8a09252) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250722/202507220309.mDl9W32Y-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202507220309.mDl9W32Y-lkp@intel.com/ All errors (new ones prefixed by >>): >> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:15: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:18: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:33: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:34: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:41: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:46: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:47: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:50: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors) -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Oops, it is the obvious compile issue. And I am messed with parallel tasks and do not notice this, what I test is old kernel. Regards Bibo Mao On 2025/7/22 上午3:19, kernel test robot wrote: > Hi Bibo, > > kernel test robot noticed the following build errors: > > [auto build test ERROR on 89be9a83ccf1f88522317ce02f854f30d6115c41] > > url: https://github.com/intel-lab-lkp/linux/commits/Bibo-Mao/LoongArch-Implement-physical-address-with-ELF-program-header/20250721-171418 > base: 89be9a83ccf1f88522317ce02f854f30d6115c41 > patch link: https://lore.kernel.org/r/20250721091248.3896152-1-maobibo%40loongson.cn > patch subject: [PATCH v2] LoongArch: Implement physical address with ELF program header > config: loongarch-allnoconfig (https://download.01.org/0day-ci/archive/20250722/202507220309.mDl9W32Y-lkp@intel.com/config) > compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 853c343b45b3e83cc5eeef5a52fc8cc9d8a09252) > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250722/202507220309.mDl9W32Y-lkp@intel.com/reproduce) > > If you fix the issue in a separate patch/commit (i.e. not just a new version of > the same patch/commit), kindly add following tags > | Reported-by: kernel test robot <lkp@intel.com> > | Closes: https://lore.kernel.org/oe-kbuild-all/202507220309.mDl9W32Y-lkp@intel.com/ > > All errors (new ones prefixed by >>): > >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:15: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:18: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:33: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:34: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:41: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:46: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:47: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:50: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors) >
On Tue, Jul 22, 2025 at 9:33 AM Bibo Mao <maobibo@loongson.cn> wrote: > > Oops, it is the obvious compile issue. And I am messed with parallel > tasks and do not notice this, what I test is old kernel. > > Regards > Bibo Mao Add this part to the patch is enough. diff --git a/arch/loongarch/include/asm/addrspace.h b/arch/loongarch/include/asm/addrspace.h index fe198b473f84..babcc1c6c820 100644 --- a/arch/loongarch/include/asm/addrspace.h +++ b/arch/loongarch/include/asm/addrspace.h @@ -18,11 +18,20 @@ /* * This gives the physical RAM offset. */ -#ifndef __ASSEMBLER__ +#ifdef __ASSEMBLER__ + +#ifndef PHYS_OFFSET +#define PHYS_OFFSET 0 +#endif + +#else + #ifndef PHYS_OFFSET #define PHYS_OFFSET _UL(0) #endif + extern unsigned long vm_map_base; + #endif /* __ASSEMBLER__ */ #ifndef IO_BASE > > On 2025/7/22 上午3:19, kernel test robot wrote: > > Hi Bibo, > > > > kernel test robot noticed the following build errors: > > > > [auto build test ERROR on 89be9a83ccf1f88522317ce02f854f30d6115c41] > > > > url: https://github.com/intel-lab-lkp/linux/commits/Bibo-Mao/LoongArch-Implement-physical-address-with-ELF-program-header/20250721-171418 > > base: 89be9a83ccf1f88522317ce02f854f30d6115c41 > > patch link: https://lore.kernel.org/r/20250721091248.3896152-1-maobibo%40loongson.cn > > patch subject: [PATCH v2] LoongArch: Implement physical address with ELF program header > > config: loongarch-allnoconfig (https://download.01.org/0day-ci/archive/20250722/202507220309.mDl9W32Y-lkp@intel.com/config) > > compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 853c343b45b3e83cc5eeef5a52fc8cc9d8a09252) > > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250722/202507220309.mDl9W32Y-lkp@intel.com/reproduce) > > > > If you fix the issue in a separate patch/commit (i.e. not just a new version of > > the same patch/commit), kindly add following tags > > | Reported-by: kernel test robot <lkp@intel.com> > > | Closes: https://lore.kernel.org/oe-kbuild-all/202507220309.mDl9W32Y-lkp@intel.com/ > > > > All errors (new ones prefixed by >>): > > > >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:15: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:18: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:33: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:34: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:41: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:46: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:47: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:50: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > > ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET > > ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors) > > >
On 2025/7/22 下午12:58, Huacai Chen wrote: > On Tue, Jul 22, 2025 at 9:33 AM Bibo Mao <maobibo@loongson.cn> wrote: >> >> Oops, it is the obvious compile issue. And I am messed with parallel >> tasks and do not notice this, what I test is old kernel. >> >> Regards >> Bibo Mao > Add this part to the patch is enough. > > diff --git a/arch/loongarch/include/asm/addrspace.h > b/arch/loongarch/include/asm/addrspace.h > index fe198b473f84..babcc1c6c820 100644 > --- a/arch/loongarch/include/asm/addrspace.h > +++ b/arch/loongarch/include/asm/addrspace.h > @@ -18,11 +18,20 @@ > /* > * This gives the physical RAM offset. > */ > -#ifndef __ASSEMBLER__ > +#ifdef __ASSEMBLER__ > + > +#ifndef PHYS_OFFSET > +#define PHYS_OFFSET 0 > +#endif > + > +#else > + > #ifndef PHYS_OFFSET > #define PHYS_OFFSET _UL(0) > #endif > + > extern unsigned long vm_map_base; > + > #endif /* __ASSEMBLER__ */ > > #ifndef IO_BASE sure, will do in this way. Regards Bibo Mao > >> >> On 2025/7/22 上午3:19, kernel test robot wrote: >>> Hi Bibo, >>> >>> kernel test robot noticed the following build errors: >>> >>> [auto build test ERROR on 89be9a83ccf1f88522317ce02f854f30d6115c41] >>> >>> url: https://github.com/intel-lab-lkp/linux/commits/Bibo-Mao/LoongArch-Implement-physical-address-with-ELF-program-header/20250721-171418 >>> base: 89be9a83ccf1f88522317ce02f854f30d6115c41 >>> patch link: https://lore.kernel.org/r/20250721091248.3896152-1-maobibo%40loongson.cn >>> patch subject: [PATCH v2] LoongArch: Implement physical address with ELF program header >>> config: loongarch-allnoconfig (https://download.01.org/0day-ci/archive/20250722/202507220309.mDl9W32Y-lkp@intel.com/config) >>> compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 853c343b45b3e83cc5eeef5a52fc8cc9d8a09252) >>> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250722/202507220309.mDl9W32Y-lkp@intel.com/reproduce) >>> >>> If you fix the issue in a separate patch/commit (i.e. not just a new version of >>> the same patch/commit), kindly add following tags >>> | Reported-by: kernel test robot <lkp@intel.com> >>> | Closes: https://lore.kernel.org/oe-kbuild-all/202507220309.mDl9W32Y-lkp@intel.com/ >>> >>> All errors (new ones prefixed by >>): >>> >>>>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:15: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:18: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:33: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:34: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:41: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:46: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:47: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:50: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET >>> ld.lld: error: ./arch/loongarch/kernel/vmlinux.lds:57: symbol not found: PHYS_OFFSET >>> ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors) >>> >>
© 2016 - 2025 Red Hat, Inc.