I've a big problem with my user space programs. The _init and _fini functions are only half compiled:
They only contain the code from crti.s and not the code from crtn.s (and neither the code from crtbegin/crtend) :S And of course, when I call the function all hell breaks loose. I never had any issue with this for the kernel itself.0000008000401f70 <_init>:
.section .init
.global _init
.type _init, @function
_init:
push rbp
8000401f70: 55 push %rbp
mov rbp, rsp
8000401f71: 48 89 e5 mov %rsp,%rbp
Disassembly of section .fini:
0000008000401f74 <_fini>:
.section .fini
.global _fini
.type _fini, @function
_fini:
push rbp
8000401f74: 55 push %rbp
mov rbp, rsp
8000401f75: 48 89 e5 mov %rsp,%rbp
Here is my link command for an executable:
Code: Select all
x86_64-elf-g++ -o debug/odin -masm=intel -I../../tstl/include/ -I../printf/include/ -I../tstl/include/ -I../tlib/include/ -Iinclude/ -nostdlib -g -Os -fno-stack-protector -fno-exceptions -funsigned-char -ffreestanding -fomit-frame-pointer -mno-red-zone -mno-3dnow -mno-mmx -fno-asynchronous-unwind-tables -isystem acpica/source/include -std=c++11 -fno-rtti -mpreferred-stack-boundary=4 -msse -msse2 -msse3 -msse4 -msse4.1 -msse4.2 -mno-avx -mno-avx2 -fstack-protector -Wall -Wextra -pedantic -Wold-style-cast -lgcc -static -L../../tlib/debug/ -mcmodel=small -fPIC -z max-page-size=0x1000 -T ../linker.ld -Wl,-gc-sections ../../tlib/debug/src/crti.s.o /home/wichtounet/opt/cross/lib/gcc/x86_64-elf/4.8.2/crtbegin.o debug/src/main.cpp.o -ltlib /home/wichtounet/opt/cross/lib/gcc/x86_64-elf/4.8.2/crtend.o ../../tlib/debug/src/crtn.s.o
If I decompile crtn.s.o, I get the code that should be concatenated:
Does anybody know what I'm doing wrong ?../../tlib/debug/src/crtn.s.o: file format elf64-x86-64
Disassembly of section .init:
0000000000000000 <.init>:
.intel_syntax noprefix
.section .init
pop rbp
0: 5d pop %rbp
ret
1: c3 retq
Disassembly of section .fini:
0000000000000000 <.fini>:
.intel_syntax noprefix
.section .init
pop rbp
0: 5d pop %rbp
ret
1: c3 retq
I don't seen anything wrong in the link command. The only think I thought of was to remove the gc-sections from the command line, but in that case, I get a huge load of relocation errors that I was unable to find a solution for. Could that be the issue ?
Thanks