Page 1 of 1
string literals break kernel
Posted: Fri Mar 26, 2004 4:33 am
by Sages
Hi everyone, I apologize for the total newb question I'm about to ask but for someone reason my kernel doesn't print text correctly when I use a string literal. Here is a sample.
Code: Select all
void KernelEntry()
{
...
// This version works fine
char strMe[3] = { 'M', 'e', 0 };
// but if I use this instead...
char strMe[] = "Me"; // this causes nothing to print
PrintString(strMe);
...
}
I'm new to all of this and would like to thank you all in advance for any help you may be able to give me. Oh, and I am using a linker script which places my text segment above .data and .bss. my tools are gcc, nasm and ld.
Re:string literals break kernel
Posted: Fri Mar 26, 2004 4:50 am
by Candy
default guess: the string is recognised as read-only and thus put with the code.
Solutions: configure the rodata to end up properly, fix your pointers, use -fwritable-strings or put .rodata in .data in your linker script.
Re:string literals break kernel
Posted: Fri Mar 26, 2004 4:59 am
by Sages
I am using the -fwritable-strings option but I'm not too sure what that .rodata stuff is about. could you please expand on that? This is my current linker script.
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(_start)
SECTIONS
{
.text 0x10000 : {
*(.text)
}
.data : {
*(.data)
}
.bss : {
*(.bss)
}
}
Re:string literals break kernel
Posted: Fri Mar 26, 2004 5:18 am
by Sages
well, the problem was... I'm retarded. Unfortunately that's do to a genetic defect that I can't change. However, I did manage to get the code to work.
kernel.lnk...
Code: Select all
...
.text 0x10000 # << I'm only off by a power of 2
.text 0x100000 # << amazing what a missing zero can do
...
but if anyone could please explain what that .rodata segment was I'd appreciate it. Or I suppose I could just google for it. Well thanks for you help.
Re:string literals break kernel
Posted: Fri Mar 26, 2004 6:06 am
by Candy
.rodata == read only data
what your strings are put in if you don't put them in .data (with -fwritable-strings). That part is data but can be put in the .text section to save overhead with program texts being multiply mapped.
Re:string literals break kernel
Posted: Fri Mar 26, 2004 7:45 pm
by Dragon88
I have this problem too. I'm not using a linker script though, what can I do? If I use -fwritable-strings it puts the strings directly in front of the code and it doesn't work right.
Re:string literals break kernel
Posted: Sat Mar 27, 2004 5:32 am
by Tim
Use a linker script and put the .rodata section in with the .text section. Then you don't have to use -fwriteable-strings.
Re:string literals break kernel
Posted: Sun Mar 28, 2004 3:01 am
by bubach
char strMe[] = "Me"; // this causes nothing to print
where is the zero in that? u need to have a zero in the end just like u had in :
char strMe[3] = { 'M', 'e', 0 };
/ Christoffer
Re:string literals break kernel
Posted: Sun Mar 28, 2004 5:19 am
by Tim
The zero is added automatically by the compiler. All "quoted strings" are nul-terminated; otherwise no quoted strings would work.
Re:string literals break kernel
Posted: Mon Mar 29, 2004 2:18 am
by bubach
Ok, stupid me..