C char array always empty

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
naper01
Posts: 2
Joined: Tue Jun 30, 2015 11:09 pm
Libera.chat IRC: naper

C char array always empty

Post by naper01 »

I'm coding a 32/64 bit kernel. I'm having a strange issue that when I try to pass a const char* , char * or char [] to a function, the array is always empty.

For example,

I have a kmain that do gdt, idt, isrs, irq, video and timer initialization then when I write :

Code: Select all

test_func("test");
test_func(char * string) code for debugging :

Code: Select all

void test_func(char * string)
{
    if(string[0] == '\0'){
        putch('n');
    }else{
        putch('o');
    }
}
I'm always having 'n' on the screen .

and if I test :

Code: Select all

if (string == NULL){
       putch('n');
 }else{
       putch('o');
       putch(string[0]);
 }
I'm getting o without the first char of string

for linking and compiling , I'm using

Code: Select all

ld -m i386linux -T linker/link.ld  -nostdlib  -o kern.my ../obj/start.o \
                      ../obj/main.o \
                      ../obj/scrn.o \
                       ../obj/gdt.o \
                       ../obj/idt.o \
                      ../obj/isrs.o \
                       ../obj/irq.o \
                     ../obj/timer.o \
                        ../obj/io.o \
                     ../obj/yshell.o \
                        ../obj/kb.o
I'm testing out kern.my using Qemu i386

[Linker script]

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}
I used Qemu along with GDB , my info registers :

Code: Select all

eax            0x1  1
ecx            0x0  0
edx            0x3d5    981
ebx            0x9500   38144
esp            0x104fe0 0x104fe0
ebp            0x0  0x0
esi            0x0  0
edi            0x108000 1081344
eip            0x100356 0x100356
eflags         0x6  [ PF ]
cs             0x8  8
ss             0x10 16
ds             0x10 16
es             0x10 16
fs             0x10 16
gs             0x10 16
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: C char array always empty

Post by Antti »

I am almost sure that your "const char strings" are not included in the binary image. At first please verify this.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: C char array always empty

Post by Candy »

Try replacing *(.rodata) with *(.rodata*)
naper01
Posts: 2
Joined: Tue Jun 30, 2015 11:09 pm
Libera.chat IRC: naper

Re: C char array always empty

Post by naper01 »

Thank you *(.rodata*) fixed the issue
Post Reply