Hi Thomas,

Thomas Schwinge wrote:
Here is a patch to fix a ``misunderstanding'' between the kernel (bflt
loader) and GDB; noticed on m68k / coldfire uClinux.

Lacking specific directives in the linker script, the linker *may* decide
to put .text and .data into the same segment:

     Section to Segment mapping:
      Segment Sections...
00 .text .data .eh_frame_hdr .eh_frame .bss 01 .eh_frame_hdr
The bflt loader in the kernel will, however, add a small extra data table
just before .data's content (cf. handling of MAX_SHARED_LIBS in
binfmt_flat.c:load_flat_file).

Now, if .text and .data are in the same segment, directly following each
other in the binary file, but have that extra data table added in the
run-time memory layout, GDB will get very confused when trying to access
items in the now-moved .data section.  Without any kernel (loader) / GDB
changes, the solution is to tell the linker to always put .text and .data
into separate segments, which GDB will handle gracefully then.

     Section to Segment mapping:
      Segment Sections...
00 .text 01 .data .eh_frame_hdr .eh_frame .bss
Tested on m68k-uclinux (where the problem occurred) and arm-uclinuxeabi
(no regressions).

Applied to the elf2flt CVS.

Thanks
Greg



2010-02-27  Thomas Schwinge  <tho...@codesourcery.com>

        * elf2flt.ld.in: Explicitly put .text and .data into separate segments.

Index: elf2flt.ld.in
===================================================================
RCS file: /var/cvs/elf2flt/elf2flt.ld.in,v
retrieving revision 1.3
diff -u -p -r1.3 elf2flt.ld.in
--- elf2flt.ld.in       7 May 2009 06:14:27 -0000       1.3
+++ elf2flt.ld.in       27 Feb 2010 17:17:05 -0000
@@ -5,6 +5,11 @@ MEMORY {
        flatmem : ORIGIN = 0x0, LENGTH = 0xfffffff
 }
+PHDRS {
+       text PT_LOAD ;
+       data PT_LOAD ;
+}
+
 SECTIONS {
.text 0x0 : {
@@ -38,7 +43,7 @@ W_RODAT               *(.gnu.linkonce.r*)
. = ALIGN(0x20) ;
                @symbol_pre...@_etext = . ;
-       } > flatmem
+       } > flatmem :text
.data : {
                . = ALIGN(0x4) ;
@@ -130,7 +135,7 @@ TOR:                @symbol_pre...@__dtor_end__ = .;
                KEEP (*(.fini_array))
                KEEP (*(SORT(.fini_array.*)))
                PROVIDE (@symbol_pre...@__fini_array_end = .);
-       } > flatmem
+       } > flatmem :data
.eh_frame_hdr : { *(.eh_frame_hdr) } > flatmem
        .eh_frame : { KEEP(*(.eh_frame)) } > flatmem


Regards,
 Thomas


------------------------------------------------------------------------

_______________________________________________
uClinux-dev mailing list
uClinux-dev@uclinux.org
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by uclinux-dev@uclinux.org
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev


--
------------------------------------------------------------------------
Greg Ungerer  --  Principal Engineer        EMAIL:     g...@snapgear.com
SnapGear Group, McAfee                      PHONE:       +61 7 3435 2888
8 Gardner Close                             FAX:         +61 7 3217 5323
Milton, QLD, 4064, Australia                WEB: http://www.SnapGear.com
_______________________________________________
uClinux-dev mailing list
uClinux-dev@uclinux.org
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by uclinux-dev@uclinux.org
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev

Reply via email to