Help regarding CPP kernel
Posted: Sat Feb 26, 2011 6:31 am
Hi,
I have some startup C code that is able to do booting and initialization of pages. Now i tried to add some CPP support to it so that from now on i'll be able to code with CPP and link my existing thing to the newer things in CPP i'm developing.
Ok so here's the problem, i get this weird error
Ok now i've this as my common Makefile.
And I've this as as linker script
Any help on this? I tried to google couldn't find anything that would suit my needs. Here is the link to the section for ctors and dtors, http://docs.redhat.com/docs/en-US/Red_H ... tions.html.
I have some startup C code that is able to do booting and initialization of pages. Now i tried to add some CPP support to it so that from now on i'll be able to code with CPP and link my existing thing to the newer things in CPP i'm developing.
Ok so here's the problem, i get this weird error
Code: Select all
cppinit.o: In function `__static_initialization_and_destruction_0(int, int)':
cppinit.cpp:(.text+0x120): undefined reference to `__dso_handle'
cppinit.cpp:(.text+0x130): undefined reference to `__cxa_atexit'
Code: Select all
CC = gcc
CPP= g++
NASMFLAGS = -f elf
NASM = nasm
INCLUDE_DIR = ../include
SRC_DIR := ../src ../src/asm ../src/x86 ../src/kmm ../src/cpp
LIBDIR = ../lib
BINARY_DIR = ../binary
CFLAGS = -c -nostartfiles -nostdlib -nodefaultlibs -fno-builtin -Wall -ffreestanding
CPPFLAGS= -c -nostartfiles -nostdlib -nodefaultlibs -fno-builtin -Wall -ffreestanding -fno-rtti -fno-exceptions -nostdinc++
PROGNAME := kernel.bin
DISK_IMAGE=../test_disks
.SUFFIXES: .s .c .o .cpp
.c.o:
$(CC) $(CFLAGS) -I $(INCLUDE_DIR) $< -o $@;
@echo "Copied $@ to $(LIBDIR)/$@";
cp $@ $(LIBDIR)/$@;
.s.o:
$(NASM) $(NASMFLAGS) $< -o $@;
@echo "Copying $@ to $(LIBDIR)/$@";
cp $@ $(LIBDIR)/$@;
.cpp.o:
$(CPP) $(CPPFLAGS) -I $(INCLUDE_DIR) $< -o $@;
@echo "Copying $@ to $(LIBDIR)/$@";
cp $@ $(LIBDIR)/$@;
Code: Select all
OUTPUT_FORMAT("binary");
ENTRY(_boot_entry);
codestart = 0x100000;
/*codestart = 0xC0000000;*/
virtual = 0xC0000000;
. = codestart; /* you need to set this up to the kernel text. */
SECTIONS
{
.text : {
code = . ;
*(.text);
/*I took this section straight from Red Hat documentation for the ld. Added SORT as mentioned on url*/
__CTOR_LIST__ = .;
LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
*(SORT(.ctors));
LONG(0)
__CTOR_END__ = .;
__DTOR_LIST__ = .;
LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
*(SORT(.dtors));
LONG(0)
__DTOR_END__ = .;
/**(.rodata);*/
. = ALIGN(4096);
codeend = ABSOLUTE(.); /* make sure you use absolute otherwise it'll be relative to current section which is text section */
}
/*. = codeend ; you need to set the current location couter to the absolute value of location counter where the code ended */
.data :{ /* ADDR returns the absolute Virtual Memory Address (VMA) of a named section*/
data = ABSOLUTE(.);
*(.data);
. = ALIGN(4096);
dataend = ABSOLUTE(.);
_dataend = dataend;
}
/*. = dataend ; same way setup location counter for the bss segment */
.bss :
{
*(.COMMON*);
bss = ABSOLUTE(.);
*(.bss);
. = ALIGN(4096);
bssend = ABSOLUTE(.);
}
end = ABSOLUTE(.);
}
Another thing is, if i add rodata section separately that is not along with .text section then due to the size, it exceeds into more than 16KB. The problem being my data section goes back beyond 8kb and thus it no longer is bootable by grub. So I was wondering any solution to that before i start with disk driver?Also see below issue please,although not such a big issue but i would be glad to have it resolved