Bug 10634 - ld -r leaves gaps in output / overlapping sections
Summary: ld -r leaves gaps in output / overlapping sections
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.21
: P2 normal
Target Milestone: ---
Assignee: Dave Korn
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-12 00:47 UTC by Dave Korn
Modified: 2009-10-01 02:38 UTC (History)
1 user (show)

See Also:
Host: i686-pc-cygwin
Target: i686-pc-cygwin
Build: i686-pc-cygwin
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Korn 2009-09-12 00:47:39 UTC
Reported at http://cygwin.com/ml/cygwin/2009-09/msg00264.html

Testcase:

$ cat segm.c
void text() { __asm__(".space 104"); }
char       data[256] = "DATA";
const char rdata[16] = "RDATA";


$ gcc -c segm.c


cygwin-1.5:
$ cygcheck -f /bin/ld
binutils-20080624-2


$ ld -r -o segm-r5.o segm.o


cygwin-1.7:
$ cygcheck -f /bin/ld
binutils-2.19.51-1


$ ld -r -o segm-r7.o segm.o


$ size segm.o segm-*.o
  text    data     bss     dec     hex filename
   128     256       0     384     180 segm.o
   128     256       0     384     180 segm-r5.o
   512     384     400    1296     510 segm-r7.o



$ objdump -s segm-r*.o

segm-r5.o: file format pe-i386

Contents of section .text:
0000 5589e500 00000000 00000000 00000000  U...............
...
0060 00000000 00000000 0000005d c3909090  ...........]....
Contents of section .data:
0080 44415441 00000000 00000000 00000000  DATA............
...
0170 00000000 00000000 00000000 00000000  ................
Contents of section .rdata:
0180 52444154 41000000 00000000 00000000  RDATA...........


segm-r7.o: file format pe-i386

Contents of section .text:
0000 5589e500 00000000 00000000 00000000  U...............
...
0060 00000000 00000000 0000005d c3909090  ...........]....
Contents of section .data:
0000 00000000 00000000 00000000 00000000  ................
...
0080 44415441 00000000 00000000 00000000  DATA............
...
0170 00000000 00000000 00000000 00000000  ................
Contents of section .rdata:
0000 00000000 00000000 00000000 00000000  ................
...
0180 52444154 41000000 00000000 00000000  RDATA...........
Comment 1 Dave Korn 2009-09-12 00:54:23 UTC
Looking at the map files is also informative:

-------- with 20080624 binutils:

Memory Configuration

Name             Origin             Length             Attributes
*default*        0x00000000         0xffffffff

Linker script and memory map

LOAD segm.o

.text           0x00000000       0x70
 *(.text)
 .text          0x00000000       0x70 segm.o
                0x00000000                text
 *(.glue_7t)
 *(.glue_7)

.data           0x00000080      0x100
 *(.data)
 .data          0x00000080      0x100 segm.o
                0x00000080                data
 *(.data2)
 *(.jcr)

.rdata          0x00000180       0x10
 *(.rdata)
 .rdata         0x00000180       0x10 segm.o
                0x00000180                rdata
 *(.rdata_runtime_pseudo_reloc)

.pdata
 *(.pdata)

.bss            0x00000190        0x0
 *(.bss)
 .bss           0x00000190        0x0 segm.o
 *(COMMON)

-------- with current binutils:

Memory Configuration

Name             Origin             Length             Attributes
*default*        0x00000000         0xffffffff

Linker script and memory map

LOAD segm.o

.text           0x00000000       0x70
 *(.text)
 .text          0x00000000       0x70 segm.o
                0x00000000                text
 *(.glue_7t)
 *(.glue_7)

.data           0x00000000      0x180
 *(.data)
 .data          0x00000080      0x100 segm.o
                0x00000080                data
 *(.data2)
 *(.jcr)

.rdata          0x00000000      0x190
 *(.rdata)
 .rdata         0x00000180       0x10 segm.o
                0x00000180                rdata
 *(.rdata_runtime_pseudo_reloc)

.eh_frame
 *(.eh_frame)

.pdata
 *(.pdata)

.bss            0x00000000      0x190
 *(.bss)
 .bss           0x00000190        0x0 segm.o
 *(COMMON)

-------- 

With current binutils it looks like the location counter is resetting to zero at
the start of each section and then padding to the address where the contents are
supposed to start.
Comment 2 Dave Korn 2009-09-12 14:28:13 UTC
Seems to be caused by the fix for bug 6945.