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: ld maps sections without consider memory region?


Hi Masaki,

I've not learn Dejagnu, so I attach small example.

Thanks - this was what I needed.


I expect section mappings like this:
| Section to Segment mapping:
|  Segment Sections...
|   00     .begin
|   01     .tail
But sections are combined actually.

This is because you have not defined the program headers for your executable, so the linker has created one. Since on the MIPS pages are 0x10000 in size the linker creates just one segment to contain both the .begin and the .tail sections.


The answer is to specify your own program headers in the linker script, so that you can be sure that you get the separation you want. So with the test case you supplied if you replace the script.ld file with this version:
---------------------------------------------------------
MEMORY {
REGION_ROM1 : ORIGIN = 0x0000, LENGTH = 0x080
REGION_ROM2 : ORIGIN = 0x0100, LENGTH = 0x800
REGION_OTHER : ORIGIN = 0x2000, LENGTH = 0x080
}


PHDRS {
      SEG_ROM1	PT_LOAD ;
      SEG_ROM2	PT_LOAD ;
      SEG_OTHER	PT_LOAD ;
}

SECTIONS {
        .begin : {
                begin.o(.text);
        } > REGION_ROM1 : SEG_ROM1
        .tail : {
                tail.o(.text);
        } > REGION_ROM2 : SEG_ROM2

	/* dummy */
        .data : { } > REGION_OTHER : SEG_OTHER
        .bss : { } > REGION_OTHER : SEG_OTHER
}
--------------------------------------------------------
Then when you run readelf on the linked executable you will see:

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000074 0x00000000 0x00000000 0x00004 0x00004 R E 0x4
  LOAD           0x000078 0x00000100 0x00000100 0x00004 0x00004 R E 0x4

 Section to Segment mapping:
  Segment Sections...
   00     .begin
   01     .tail


Cheers Nick


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