Page 1 of 1

LD Creating Large Files in 64 bit mode

Posted: Tue Oct 16, 2007 2:23 am
by AJ
Hi,

As you probably know given some of my recent questions, I am trying to convert to a 64 bit kernel. I have the cross-compiled version of ld.

When I link at my 'old' kernel's address of 0xC0000000, for some reason I get 2MB added to my output file. An objdump shows the following program and section headers:

Code: Select all

Program Header:
    LOAD off    0x0000000000200000 vaddr 0x00000000c0000000 paddr 0x00000000c0000000 align 2**21
         filesz 0x0000000000002000 memsz 0x0000000000002000 flags rwx

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         00001000  00000000c0000000  00000000c0000000  00200000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .eh_frame     00000030  00000000c0001000  00000000c0001000  00201000  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  2 .data         00000fd0  00000000c0001030  00000000c0001030  00201030  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  3 .comment      00000012  0000000000000000  0000000000000000  00202000  2**0
                  CONTENTS, READONLY#
As you can see, the program alignment is at 0x200000 (2^21), but as 0xC0000000 is already 2mb aligned, this shouldn't make a difference. Why should LD use the offset 0x200000 when this is not specified at link time? Looking at the symbol table, everything is at 0x00000000 except the entry point which is at 0x00000002.

I have attempted using the following linker script, but have tried without too. If I do not specify the load address, everything is fine (the file size is a few hundred bytes), but the load address is 0x400000, which I don't really want.

Linker script follows:

Code: Select all

ENTRY(runtime);
OUTPUT_FORMAT(x86_64-pc-elf);
phys = 0xC0000000;

SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    *(.rodata)
    start_ctors = .;
    *(.ctor*)
    end_ctors = .;
    start_dtors = .;
    *(.dtor*)
    end_dtors = .;
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  . = ALIGN(4096);
  end = .;
}
If you need any more detail, please let me know (oh, I have googled the problem but have not been able to construct search terms that give me anything near an answer :roll: ).

Cheers,
Adam[/code]

Posted: Tue Oct 16, 2007 2:30 am
by os64dev
use the options '-nostdinc -nostdlib' with the linker

Posted: Tue Oct 16, 2007 2:38 am
by AJ
I use:

Code: Select all

CXXFLAGS= -Wall -O -fstrength-reduce -nostdlib -nostdinc -nostartfiles -fno-exceptions -fno-rtti
...and if you look at the program header, the filesz and memsz is only 0x2000 bytes. Also, look at the 'File Off' column of the section headers - there is *nothing* before 0x200000 - even code inserted by the compiler. It is purely the offset in to the file that seems padded. Even if I had standard includes, would they really be exactly 2MiB?

I'm still stumped :?

Posted: Tue Oct 16, 2007 8:01 am
by os64dev
CXXFLAGS is for the g++ compiler you also need to use '-nostdinc -nostdlib' with ld. Atleast that solved it im my case.

Posted: Tue Oct 16, 2007 9:12 am
by AJ
:oops:

Thank you and sorry I misunderstood your first answer - I had come across those parameters in G++ but not with LD. And yes - it solved it here too.

Many thanks,
Adam