This is the mail archive of the binutils@sources.redhat.com 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: how to specify absolute address for sections


Hi Feroz,
	You need not specify anything in the assembly file. All the
addresses are specified in the linker script. You can then link the .o
files using the linker script which will then produce a.out file with
all the correct addresses.

Example: (Note that I am using a mips toolchain crosscompiled on x86)

Consider the following sample mips32 assembly code: (rtn.s) 

.global _start
.set noat
.section .rdata
 temp: .word 1
 
 .section .text
 _start:
  li    $sp, 262144
  addiu $sp,$sp, -4
  nop

To assemble it do
bash-2.05b$ mips-elf-as rtn.s -o rtn.o

------------------------------------------------------------------------
----
Now write a simple linker script (mylink.lk)

SECTIONS
{
	. = 0x10000;   /*Start address of .text*/
	.text : { *(.text) }
	. = 0x8000000; /*Start address of .rdata*/
	.rdata : { *(.data) }
}

Link the code rtn.o file using the following
bash-2.05b$ mips-elf-ld -T mylink.lk rtn.o
------------------------------------------------------------------------
----

To see that the addresses generated are proper do an objdump of the
headers as follows:

bash-2.05b$ mips-elf-objdump -h a.out

a.out:     file format elf32-bigmips

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         0000000c  00010000  00010000  00001000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .rdata        00000000  08000000  08000000  00002000  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  08000000  08000000  00002000  2**0
                  ALLOC

 (Not complete listing)

If you see the VMA and the LMA columns we see that the addresses are
correct.

This should solve your problem. In case of any problems please refer to
the linker script documentation
http://www.sthoward.com/docs/ld_toc.html

-------------------------------------------------------------
Arun Vishwanathan 
Software Engineer
Nevis Networks Inc.      
-------------------------------------------------------------

> -----Original Message-----
> From: binutils-owner@sources.redhat.com [mailto:binutils-
> owner@sources.redhat.com] On Behalf Of K. Ahmed Feroz
> Sent: Monday, March 22, 2004 1:35 PM
> To: binutils@sources.redhat.com
> Subject: how to specify absolute address for sections
> 
> Hi,
> Please tell me how to specify the absolute address for assembly file
> sections?
> 
> Example:
> 
> 	----------
> 	----------
> 	.rdata
> 	 .word 1
>        .word 2
> 
> 	.text
> 	----------
> 	----------
> 	subu $sp,$sp, -4
> 	----------
> 	----------
> 
> In the above example, I need to assign absolute address for .rdata,
> .text sections.
> 
> Regards
> K.Feroz
> 


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