Page 1 of 1

ld: section .data [n -> n] overlaps section .text [n -> ]

Posted: Sat Mar 26, 2011 10:14 pm
by casnix
I have been forced (due to the lack of a universal firmware) to write my own virtual firmware to best emulate what my OS needs on EVERY machine (excluding my IBM PS/1). My code (I hope) isn't causing the problem (in the title), I believe it's the linker script.

Anyway, here's the command line and error:

Code: Select all

root@##-systems$ ld link.ld -o vfirmA01.bin setup.o panic.o main.o VFxcns1s.o VFxcns1bs.o VFxcys1k.o
ld: section .data [00000000001001d5 -> 00000000001011d4] overlaps section .text [0000000000100000 -> 0000000000101fff]
ld: vfirmA01.bin: Not enough room for program headers (allocated 2, need 3)
ld: final link failed: Bad value
Linker script:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}
*scratches head and burns PC tower* I am stumped. I've searched google, and somehow the most related case was with a PERL script. PERL and LD...Now my brain's exploded.

Anyway, maybe I've missed something very, VERY obvious. Any suggestions?

Thanks,
Casnix

Re: ld: section .data [n -> n] overlaps section .text [n ->

Posted: Sun Mar 27, 2011 12:00 am
by Chandra
casnix wrote:Linker script:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}
Probably some problem with sections alignment. Not sure, though.
Replace ALIGN(4096) with ALIGN(8192) and see if it brings any improvement.

Re: ld: section .data [n -> n] overlaps section .text [n ->

Posted: Sun Mar 27, 2011 2:39 am
by xenos
It seems like ld is confused because you are using "data" before assigning a value. What happens if you do it like this?

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(4096);
  }
  data = .;
  .data : AT(phys + (data - code))
  {
    *(.data)
    . = ALIGN(4096);
  }
  bss = .;
  .bss : AT(phys + (bss - code))
  {
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}
But since you are using physical addresses which are identical to the virtual addresses, you probably don't need to specify a LMA at all, so the following should work as well:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(4096);
  }
  .data
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}

Re: ld: section .data [n -> n] overlaps section .text [n ->

Posted: Sun Mar 27, 2011 9:00 am
by casnix
@XenOS:
Your first suggestion removes the overlapping section error, but leaves the program header error.

Your second suggestion throws a "file format not recognized; treating as linker script" which is okay, but "parse error on line 6" is not (that's the .text phys line).
If I fix the parse errors, I get a whole trunk load of "undefined reference" errors, which apparently I can never evade.

@Chandra: Replacing ALIGN(4096) with ALIGN(8192) doesn't bring improvement.

[edit]

Maybe if I did the code declaration the same as data?
[edit again]
Nope, that causes the initial problem.

Aren't the program headers for elf binaries as opposed to flat binaries (which is my goal)?
So now I'm confused as to why ld is trying to produce elf out put instead of AOUT.

In case it matters, I'm using
GNU ld version 2.12.90.0.15
gcc 3.2
And all on SuSE 8.1

Re: ld: section .data [n -> n] overlaps section .text [n ->

Posted: Sun Mar 27, 2011 2:02 pm
by casnix
Oh, sorry. Got confused between articles about that (the program headers). I'm guessing that I should increase the size of phys?

Re: ld: section .data [n -> n] overlaps section .text [n ->

Posted: Mon Mar 28, 2011 12:48 am
by Combuster
Not necessary a direct cause to the problem at hand but...
GNU ld version 2.12.90.0.15
Ancient. Are you not using a crosscompiler?
gcc 3.2
Ancient, and known buggy.
And all on SuSE 8.1
Erm, upgrade? Maybe? :wink:

Re: ld: section .data [n -> n] overlaps section .text [n ->

Posted: Mon Mar 28, 2011 11:46 am
by casnix
Yeah, I deffinately need an upgrade, however both my laptop and PC are about 1year younger than me (they're 14 years old), and my laptop has a usb 2.0 port and a floppy drive, so I'm not sure how to do the upgrade :S And my mac doesnt have gnu ld.

Any way the ld -T option tells me about a whole bunch of undefined reference errors, so missing that option may have been the problem all along.

Thank you,
Casnix

[edit] Reading the ld documentation for -T explains the outpilut in elf format. So again,
Thank you