Page 1 of 1

Linker script

Posted: Sat Jan 28, 2012 11:25 am
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.

Re: Linker script

Posted: Sat Jan 28, 2012 12:00 pm
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.

Re: Linker script

Posted: Sat Jan 28, 2012 5:27 pm
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.