[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

.interp
 *(.interp)

.hash
 *(.hash)

.dynsym
 *(.dynsym)

.dynstr
 *(.dynstr)

.gnu.version
 *(.gnu.version)

.gnu.version_d
 *(.gnu.version_d)

.gnu.version_r
 *(.gnu.version_r)

.rel.dyn
 *(.rel.init)
 *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
 *(.rel.fini)
 *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
 *(.rel.data.rel.ro*)
 *(.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.ctors)
 *(.rel.dtors)
 *(.rel.got)
 *(.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.dyn
 *(.rela.init)
 *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
 *(.rela.fini)
 *(.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.ctors)
 *(.rela.dtors)
 *(.rela.got)
 *(.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.*)

.rel.plt
 *(.rel.plt)

.rela.plt
 *(.rela.plt)

.init
 *(.init)

.plt
 *(.plt)

.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
 *(.text.*personality*)
 *(.gnu.warning)

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

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

.rodata1
 *(.rodata1)

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

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

.eh_frame_hdr
 *(.eh_frame_hdr)

.eh_frame
 *(.eh_frame)

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

.eh_frame
 *(.eh_frame)

.gcc_except_table
 *(.gcc_except_table)
 *(.gcc_except_table.*)

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

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

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

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

.fini_array
 *(.fini_array)
                0xffa09330                PROVIDE (__fini_array_end, .)

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

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

.jcr
 *(.jcr)

.data.rel.ro
 *(.data.rel.ro.local)
 *(.data.rel.ro*)

.dynamic
 *(.dynamic)

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

.data1
 *(.data1)

.got
 *(.got.plt)
 *(.got)

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

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

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

.stab
 *(.stab)

.stabstr
 *(.stabstr)

.stab.excl
 *(.stab.excl)

.stab.exclstr
 *(.stab.exclstr)

.stab.index
 *(.stab.index)

.stab.indexstr
 *(.stab.indexstr)

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

.debug
 *(.debug)

.line
 *(.line)

.debug_srcinfo
 *(.debug_srcinfo)

.debug_sfnames
 *(.debug_sfnames)

.debug_aranges
 *(.debug_aranges)

.debug_pubnames
 *(.debug_pubnames)

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

.debug_abbrev
 *(.debug_abbrev)

.debug_line
 *(.debug_line)

.debug_frame
 *(.debug_frame)

.debug_str
 *(.debug_str)

.debug_loc
 *(.debug_loc)

.debug_macinfo
 *(.debug_macinfo)

.debug_weaknames
 *(.debug_weaknames)

.debug_funcnames
 *(.debug_funcnames)

.debug_typenames
 *(.debug_typenames)

.debug_varnames
 *(.debug_varnames)

/DISCARD/
 *(.note.GNU-stack)
OUTPUT(bfinsatt elf32-bfin)

Other related posts: