[bitlug] Re: ELF??

  • From: Peeyush Prasad <peeyush@xxxxxxxxxx>
  • To: bitlug@xxxxxxxxxxxxx
  • Date: Tue, 15 Nov 2005 09:46:57 +0530 (IST)

One better way to do it is to use a mapfile for the linker.

Hi all,
This is precisely what I dont want to get into: learning Linkder Command Language!

Ok, So I have done it, am now using an lcl file like I was asked to... actually, it is not that painful, and the ld info file has quite a lot of info.

gcc -fno-builtin -ffreestanding -nostdinc -c blink.c
gcc -fno-builtin -ffreestanding -nostdinc -c main.c
ld -Bstatic -Ttext 0xffa08000 -o bld blink.o main.o -Map blink.map

blink.map?? So you finally had to go for it, huh?

How difficult was it to put things into the mapfile? Can you post it? Hope the file size isnt too much.

Weeell, the -Map option is just asking the linker to generate a memory map of the layout he created, so the mapfile is just an output from the linker... If you need to specify section addresses, you have to create a linker command language file (lcl)... else the linker uses an lcl which is built into it by default... remember the 0x8048244 ?? :^)
The Map file it generated by default (only the -Ttext 0xffa08000 and --entry=0xffa08000 options) is attached... ppl can go through it and then we can dissect it...

   Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
   LOAD           0x001000 0xffa08000 0xffa08000 0x00048 0x00048 R E 0x1000
   LOAD           0x001048 0xffa09048 0xffa09048 0x00000 0x00000 RW  0x1000
   ^^^^^^^^^^^^^^ // What is this second load address??

The first is clearly text and the second is data (In the table above, you can see that .data,.sbss (dont know what that is) and .bss start at 0xffa09048). Am I missing something grossly here?

No, *I* was, I thought that a single load specifies the program load address... this is actually specifying that the .text and .data segments have to be loaded at the addresses specified.No confusion.

If your dilemma is 'why two loads when everything is static?', I feel that you need separate setup for pages (sections) with different permissions. I am only guessing. We need to better understand the LOAD linker command.

Remember, the c library has not been linked in and also none of the startup files. (crtn.o etc).

-- P
Allocating common symbols
Common symbol       size              file

SysInfo             0x10              main.o

Memory Configuration

Name             Origin             Length             Attributes
*default*        0x00000000         0xffffffff

Linker script and memory map

Address of section .text set to 0xffa08000
LOAD main.o
LOAD serial.o
LOAD hkeep.o
                0x00000000                PROVIDE (__executable_start, 0x0)
                0x00000000                . = 0x0








 *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
 *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
 *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
 *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)
 *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)
 *(.rel.sdata .rel.sdata.* .rel.gnu.linkonce.s.*)
 *(.rel.sbss .rel.sbss.* .rel.gnu.linkonce.sb.*)
 *(.rel.sdata2 .rel.sdata2.* .rel.gnu.linkonce.s2.*)
 *(.rel.sbss2 .rel.sbss2.* .rel.gnu.linkonce.sb2.*)
 *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)

 *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
 *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
 *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
 *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
 *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
 *(.rela.sdata .rela.sdata.* .rela.gnu.linkonce.s.*)
 *(.rela.sbss .rela.sbss.* .rela.gnu.linkonce.sb.*)
 *(.rela.sdata2 .rela.sdata2.* .rela.gnu.linkonce.s2.*)
 *(.rela.sbss2 .rela.sbss2.* .rela.gnu.linkonce.sb2.*)
 *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)





.text           0xffa08000      0x2e0
 *(.text .stub .text.* .gnu.linkonce.t.*)
 .text          0xffa08000       0x60 main.o
                0xffa08010                SPtest
                0xffa08000                main
 .text          0xffa08060      0x10c serial.o
                0xffa080f0                readSP
                0xffa08100                writeSP
                0xffa0815c                DMAwriteSP
                0xffa08060                initSP
 .text          0xffa0816c      0x174 hkeep.o
                0xffa081d4                panic
                0xffa08228                init_sys
                0xffa0816c                memset
                0xffa081a8                delay

                0xffa082e0                PROVIDE (__etext, .)
                0xffa082e0                PROVIDE (_etext, .)
                0xffa082e0                PROVIDE (etext, .)

.rodata         0xffa082e0       0x50
 *(.rodata .rodata.* .gnu.linkonce.r.*)
 .rodata        0xffa082e0       0x50 main.o


 *(.sdata2 .sdata2.* .gnu.linkonce.s2.*)

 *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*)



                0xffa09330                . = (ALIGN (0x1000) + (. & 0xfff))



 *(.tdata .tdata.* .gnu.linkonce.td.*)

 *(.tbss .tbss.* .gnu.linkonce.tb.*)
                0xffa09330                . = ALIGN (0x4)
                0xffa09330                PROVIDE (__preinit_array_start, .)

                0xffa09330                PROVIDE (__preinit_array_end, .)
                0xffa09330                PROVIDE (__init_array_start, .)

                0xffa09330                PROVIDE (__init_array_end, .)
                0xffa09330                PROVIDE (__fini_array_start, .)

                0xffa09330                PROVIDE (__fini_array_end, .)

 *(EXCLUDE_FILE(*crtend*.o) .ctors)

 *(EXCLUDE_FILE(*crtend*.o) .dtors)




.data           0xffa09330        0x0
 *(.data .data.* .gnu.linkonce.d.*)



 *(.sdata .sdata.* .gnu.linkonce.s.*)
                0xffa09330                _edata = .
                0xffa09330                PROVIDE (edata, .)
                0xffa09330                __bss_start = .

.sbss           0xffa09330        0x0
                0xffa09330                PROVIDE (__sbss_start, .)
                0xffa09330                PROVIDE (___sbss_start, .)
 *(.sbss .sbss.* .gnu.linkonce.sb.*)
                0xffa09330                PROVIDE (__sbss_end, .)
                0xffa09330                PROVIDE (___sbss_end, .)

.bss            0xffa09330       0x10
 *(.bss .bss.* .gnu.linkonce.b.*)
 COMMON         0xffa09330       0x10 main.o
                0xffa09330                SysInfo
                0xffa09340                . = ALIGN (0x4)
                0xffa09340                . = ALIGN (0x4)
                0xffa09340                _end = .
                0xffa09340                PROVIDE (end, .)







.comment        0x00000000       0x36
 .comment       0x00000000       0x12 main.o
 .comment       0x00000012       0x12 serial.o
 .comment       0x00000024       0x12 hkeep.o







 *(.debug_info .gnu.linkonce.wi.*)











OUTPUT(bfinsatt elf32-bfin)

Other related posts: