This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


 First, thanks to you and Daniel Jacobowitz for pointing to my (friday
afternoon) stupid error in the other thread - the "RX" segment load
address is really 0.

 I do understand the alignment - so if the first segment is not aligned,
the user will get the ELF header (file offset 0) at the beginning of
the page - but it is not important.

You write:
> You can avoid this by using -n, -N, -z max-page-size, or by
> using gold which uses a default page size of 0x1000.

 But -n and -N seems to be related to data and not code, and -z does not
seem to work in this context. I still did not try Gold.
 Screen dump:

######################################################
etienne@cygne:~/projet/gujin$ cat hello_64bits.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
etienne@cygne:~/projet/gujin$ gcc -m64 -Wl,-n,-z,max-page-size=0x1000,-Ttext=0x110000 hello_64bits.s hello_64bits.elf -nostartfiles -node
faultlibs
etienne@cygne:~/projet/gujin$ ls -l hello_64bits.elf
-rwxr-xr-x 1 etienne etienne 1114728 2009-04-03 13:13 hello_64bits.elf
etienne@cygne:~/projet/gujin$ readelf -l hello_64bits.elf

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           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000110062 0x0000000000110062  R E    200000
  LOAD           0x0000000000110080 0x0000000000310080 0x0000000000310080
                 0x0000000000000023 0x0000000000000023  RW     200000
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     8

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


To be sure for the options, add -v to gcc:
etienne@cygne:~/projet/gujin$ gcc -v -m64 -Wl,-n,-z,max-page-size=0x1000,-Ttext=0x110000 hello_64bits.s hello_64bits.elf -nostartfiles -n
odefaultlibs
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.3-3' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-
languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --
enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdc
xx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-cld --with-tune=generic --enable-checking=release --build=i486-linu
x-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.3.3 (Debian 4.3.3-3)
COLLECT_GCC_OPTIONS='-v' '-m64' '-nostartfiles' '-nodefaultlibs' '-mtune=generic'
 as -V -Qy --64 -o /tmp/cc0iaCDx.o hello_64bits.s
GNU assembler version 2.19.1 (i486-linux-gnu) using BFD version (GNU Binutils for Debian) 2.19.1
COMPILER_PATH=/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-
gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/4.3.3/:/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../:/lib/:/usr
/lib/
COLLECT_GCC_OPTIONS='-v' '-m64' '-nostartfiles' '-nodefaultlibs' '-mtune=generic'
 /usr/lib/gcc/i486-linux-gnu/4.3.3/collect2 --eh-frame-hdr -m elf_x86_64 --hash-style=both -dynamic-linker /lib64/ld-linux-x86-64.so.2 -L
/usr/lib/gcc/i486-linux-gnu/4.3.3 -L/usr/lib/gcc/i486-linux-gnu/4.3.3 -L/usr/lib/gcc/i486-linux-gnu/4.3.3/../../.. -n -z max-page-size=0x
1000 -Ttext=0x110000 /tmp/cc0iaCDx.o hello_64bits.elf
etienne@cygne:~/projet/gujin$ ls -l hello_64bits.elf
-rwxr-xr-x 1 etienne etienne 1114728 2009-04-03 13:13 hello_64bits.elf

######################################################

Note also that the entry point seems to be fixed, even when I do not
define it, and do not set -Ttext=0x110000, I get:
etienne@cygne:~/projet/gujin$ gcc -m64 hello_64bits.s hello_64bits.elf -nostartfiles -nodefaultlibs -static
etienne@cygne:~/projet/gujin$ ls -l hello_64bits.elf
-rwxr-xr-x 1 etienne etienne 1114728 2009-04-03 13:13 hello_64bits.elf
etienne@cygne:~/projet/gujin$ readelf -l hello_64bits.elf

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           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000110062 0x0000000000110062  R E    200000
  LOAD           0x0000000000110080 0x0000000000310080 0x0000000000310080
                 0x0000000000000023 0x0000000000000023  RW     200000
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     8

 Section to Segment mapping:
  Segment Sections...
   00     .text .rodata
   01     .data
   02
etienne@cygne:~/projet/gujin$

 The "-Wl,-Ttext=0x200000" seems to be ignored, probably the linker command file...

 I am a bit confused, but thanks a lot for the info.
 Etienne.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]