x86-64: LD default ELF section file offset == LMA ?

H.J. Lu hjl.tools@gmail.com
Fri Apr 3 16:54:00 GMT 2009


On Fri, Apr 3, 2009 at 9:39 AM, Etienne Lorrain
<etienne_lorrain@yahoo.fr> wrote:
>
> H.J. wrote:
>> If you tell us what you are trying to do, we may be able to help you.
>
>  Well, I was just trying to generate a very simple ELF64 file as an
> example of what the Gujin bootloader can load from power-on.
>  It would also be a Gujin regression test, i.e. check that I load
> each of the segment at their right address. Gujin do not switch
> to 64 bits mode, but can still understand ELF64.
>
>  Unlike for ELF32, it seems that I cannot use the standard linker
> command file to generate a valid ELF64 - i.e. something not loaded
> at physical address 0 but just after the real mode address space
> at 0x110000. The physical load address should be lower than the
> amount of RAM a standard PC has.
>  So either I need another file for the ELF64 linker, or I build
> a relocatable ELF64, Gujin was able to relocate but I did not test
> that for some time.
>
>  Etienne.
>

I got

[hjl@gnu-6 tmp]$ cat f.s
       .file   "hello_64bits.c"
#APP
               .text
       .code32
       .global _start
_start:
       mov     $0xB8000,%edi
       add     $640,%edi
       mov     $msg1,%esi
       mov     $0x17,%ah
       1:
       lodsb   %ds:(%esi),%al
       cmpb    $0,%al
       je      2f
       stosw   %ax,%es:(%edi)
       jmp     1b
       2:
       mov     $msg2,%esi
       1:
       lodsb   %ds:(%esi),%al
       cmpb    $0,%al
       je              .
       stosw   %ax,%es:(%edi)
       jmp     1b

#NO_APP
.globl msg1
       .section        .rodata
       .align 32
       .type   msg1, @object
       .size   msg1, 34
msg1:
       .string "Hello protected-mode text world! "
.globl msg2
       .data
       .align 32
       .type   msg2, @object
       .size   msg2, 35
msg2:
       .string "(ELF64 file) ... please reboot ..."
       .ident  "GCC: (Debian 4.3.3-3) 4.3.3"
       .section        .note.GNU-stack,"",@progbits
[hjl@gnu-6 tmp]$ gcc -c f.s
[hjl@gnu-6 tmp]$ ld  -z max-page-size=0x1000 -Ttext=0x110000  f.o
[hjl@gnu-6 tmp]$ readelf -Sl a.out
There are 8 section headers, starting at offset 0x10f8:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .text             PROGBITS         0000000000110000  00001000
       0000000000000029  0000000000000000  AX       0     0     4
  [ 2] .rodata           PROGBITS         0000000000110040  00001040
       0000000000000022  0000000000000000   A       0     0     32
  [ 3] .data             PROGBITS         0000000000111080  00001080
       0000000000000023  0000000000000000  WA       0     0     32
  [ 4] .comment          PROGBITS         0000000000000000  000010a3
       000000000000001d  0000000000000000           0     0     1
  [ 5] .shstrtab         STRTAB           0000000000000000  000010c0
       0000000000000038  0000000000000000           0     0     1
  [ 6] .symtab           SYMTAB           0000000000000000  000012f8
       0000000000000120  0000000000000018           7     6     8
  [ 7] .strtab           STRTAB           0000000000000000  00001418
       0000000000000039  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

Elf file type is EXEC (Executable file)
Entry point 0x110000
There are 3 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000001000 0x0000000000110000 0x0000000000110000
                 0x0000000000000062 0x0000000000000062  R E    1000
  LOAD           0x0000000000001080 0x0000000000111080 0x0000000000111080
                 0x0000000000000023 0x0000000000000023  RW     1000
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     8

 Section to Segment mapping:
  Segment Sections...
   00     .text .rodata
   01     .data
   02


Does it do what you wanted?


-- 
H.J.



More information about the Binutils mailing list