Subject: Re: Adding Multiboot support (or not)
To: None <tech-kern@netbsd.org>
From: Pavel Cahyna <pavel.cahyna@st.mff.cuni.cz>
List: port-i386
Date: 02/11/2006 11:22:39
On Fri, Feb 10, 2006 at 08:08:46PM -0800, Jason Thorpe wrote:
> >As doing this with a linker script seems unfortunately impossible, I have
> >written a small program to change physical adresses of an ELF32 binary.
> >Beware, it currently would not work on a big-endian machine.
> 
> Nonsense!  Consider the following (note the LOADADDR() and AT() directives):
> 
> ENTRY(KERNEL_BASE_phys)
> SECTIONS
> {
>   KERNEL_BASE_phys = 0x00100000;
>   KERNEL_BASE_virt = 0xc0100000;
> 
>   /* Read-only sections, merged into text segment: */
>   .text (KERNEL_BASE_virt) :
>   AT (KERNEL_BASE_phys)
>   {
>     *(.text)
>     *(.text.*)
>     *(.stub)
>     *(.rodata)
>   } =0
>   PROVIDE (__etext = .);
>   PROVIDE (_etext = .);
>   PROVIDE (etext = .);
> 
>   /* Align the data segment to start on a page boundary. */
>   . = ALIGN(0x1000);
>   .data :
>   AT (LOADADDR(.text) + (ADDR(.data) - ADDR(.text)))
>   {
>     __data_start = . ;
>     *(.data)
>     *(.data.*)
>   }
>   PROVIDE (_edata = .);
>   PROVIDE (edata = .);
>   __bss_start = . ;
>   .bss :
>   {
>     *(.bss)
>     *(.bss.*)
>     *(COMMON)
>     . = ALIGN(32 / 8);
>   }
>   . = ALIGN(32 / 8);
>   PROVIDE (_end) = . ;
>   PROVIDE (end) = . ;
> }

Your script fixes some problems of my earlier attempts, I tried AT but
wasn't aware of LOADADDR. Thanks. 
(The last lines must be changed to
  PROVIDE (_end = .) ;
  PROVIDE (end = .) ;
).

Unfortunately it does not deal with the main problem. The output is still
incorrect.

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x001000 0xc0100000 0x00100000 0x5bc539 0x5bc539 R E 0x1000
  LOAD           0x5be000 0xc06bd000 0x006bd000 0x43610 0x43610 RW  0x1000
  LOAD           0x600620 0xc0700620 0xc0700620 0x00000 0x4e554 RW  0x1000
  LOAD           0x601b74 0xc074eb74 0xc074eb74 0x85ebf 0x85ebf R   0x1000

 Section to Segment mapping:
  Segment Sections...
   00     .text 
   01     .data 
   02     .bss 
   03     .rodata.str1.1 .rodata.str1.32 link_set_malloc_types link_set_ieee80211_funcs link_set_sysctl_funcs link_set_domains link_set_pools link_set_vfsops link_set_vfs_hooks link_set_evcnts link_set_dkwedge_methods link_set_bufq_strats .rodata.str1.4

How would you handle all the sections which went to the segment 03,
without knowing the names of all the link sets?

Bye	Pavel