Linker script

Programming, for all ages and all languages.
Post Reply
nevar
Posts: 12
Joined: Fri Feb 02, 2007 8:04 am

Linker script

Post by nevar »

Hi,
I just created my OS with support for loading ELF64 files to run. In Debian 64 i try to compile sample "hello world" programm writen in C. I have writen linker script like this:

Code: Select all

SECTIONS {
         . = 0xFFFFFFFC00000000;
         .text : {* (.text); }
}
but it gives me error:

Code: Select all

task_elf.c:(.text+0x55): relocation truncated to fit: R_X86_64_32S against `.rodata'
It is first time i use linux linker so i dont know how to solve this. In my system i run programms from this address 0xFFFFFFFC00000000.
User avatar
beyondsociety
Member
Member
Posts: 39
Joined: Tue Oct 17, 2006 10:35 pm
Location: Eagle, ID (USA)
Contact:

Re: Linker script

Post by beyondsociety »

Did a quick google search for the error and it brings up numerous posts for the osdev forum, people have solved the problem by compiling with "-mcmodel=size" depending on where you've relocated your kernel too, hope this helps.

Code: Select all

-mcmodel=small
    Generate code for the small code model: the program and its symbols must be linked in the lower 2 GB of the address space. Pointers are 64 bits. Programs can be statically or dynamically linked. This is the default code model.
-mcmodel=kernel
    Generate code for the kernel code model. The kernel runs in the negative 2 GB of the address space. This model has to be used for Linux kernel code.
-mcmodel=medium
    Generate code for the medium model: The program is linked in the lower 2 GB of the address space but symbols can be located anywhere in the address space. Programs can be statically or dynamically linked, but building of shared libraries are not supported with the medium model.
-mcmodel=large
    Generate code for the large model: This model makes no assumptions about addresses and sizes of sections. Currently GCC does not implement this model.
"I think it may be time for some guru meditation"
"Barbarians don't do advanced wizardry"
User avatar
Velko
Member
Member
Posts: 153
Joined: Fri Oct 03, 2008 4:13 am
Location: Ogre, Latvia, EU

Re: Linker script

Post by Velko »

beyondsociety wrote:

Code: Select all

-mcmodel=large
    Generate code for the large model: This model makes no assumptions about addresses and sizes of sections. Currently GCC does not implement this model.
Those must be old news. GCC implements -mcmodel=large for quite some time.
If something looks overcomplicated, most likely it is.
Post Reply