LD Creating Large Files in 64 bit mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

LD Creating Large Files in 64 bit mode

Post 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]
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

use the options '-nostdinc -nostdlib' with the linker
Author of COBOS
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post 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 :?
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

CXXFLAGS is for the g++ compiler you also need to use '-nostdinc -nostdlib' with ld. Atleast that solved it im my case.
Author of COBOS
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post 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
Post Reply