pgubook-readers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pgubook-readers] a question about linker script


From: lion 陳
Subject: [Pgubook-readers] a question about linker script
Date: Sat, 31 Jul 2004 08:15:07 +0800 (CST)

In order to understand what function the AT() keyword has in a linker
script, I write the following hello.s program, and a linker script
named ldscript. My assumption is that the .text section will be loaded
at "physical" address 0x40000, and .data section will be loaded right
after .text section,  so I should be able to copy the string in .data
section to the .bss section. but after running make, and using gdb to
execute the program until the break point and watch the contents at
virtual address 0x30000 (.bss section), I can't find the string !
Query, 1. the address that the AT keyword specifies to load is physical
          address ?
       2. I can't see the string in .bss section ,that's because the
          loader ignored the AT() keyword's request ? ( I use Red Hat
          Linux 7.1 on i586 )
The GNU ld manual says " the AT keyword specifies the load address of
the section ", but it also says " you can force the output section to
be loaded at a specified address by specifying start immediately
following the section name ". ( the syntax of a section definition is
like this :    SECTIONS{
                  secname start : AT(ldadr)
                  { contents }
                ...
               }                                                     )
(http://www.gnu.org/software/binutils/manual/ld-2.9.1/html_chapter/ld_3.html#SEC21)
Query, 3. what's the difference between these two statements ? In other
          words, what's the difference between the two "load addresses" ?
Thanks.
#---------hello.s---------
1    .global _start
2    .text
3       _start:
4            movl  $_etext,%eax   # eax == source pointer
5            movl  $len,%ecx
6            movl  $_bss,%ebx   # ebx == destination pointer
7           1:
8            movb  (%eax),%dl
9            movb  dl,(%ebx)   # copy string from .data to .bss
10           incl  %eax
11           incl  %ebx
12           decl  %ecx
13           cmpl  $0,%ecx
14           jne   1b   
15           
16           movl  $0,%ebx   
17           movl  $1,%eax
18           int   $0x80      #exit
 
     .data
        msg:
            .string "Hello Jonathan !\n"
            len = . - msg
     .bss
        .lcomm  buf, 0x100
#----------ldscript------------
      SECTIONS
      {
         .text 0x10000 : AT(0x40000)
             { *(.text)  _etext = . ;  }
         .data 0x20000  : AT(LOADADDR(.text) + SIZEOF(.text) )
            {  *(.data)  }
         .bss 0x30000 :
            {  _bss = . ;  *(.bss)   }
      }
#-----------Makefile------------------
   hello : hello.o
    ld -T ldscript hello.o -o hello
   hello.o : hello.s
    as --gsatbs hello.s -o hello.o
#------using gdb to watch the contents of .bss------------
  
   $ gdb -q hello
   (gdb)  break 16
   (gdb)  run
   (gdb)  x/8xb 0x30000   -> failure to copy to .bss
    



信箱搭配即時通,溝通樂趣無窮!
Yahoo!奇摩Messenger6.0
reply via email to

[Prev in Thread] Current Thread [Next in Thread]