Page 2 of 2

Re: Cross Compiler use problem

Posted: Tue Apr 27, 2010 1:55 am
by pcmattman
And as I said, it worked with DJGPP
DJGPP auotmatically prepends an underscore to every C symbol. You don't need to do that anymore when you compile a cross compiler, so all those underscores you added before symbol names in your assembly code can be safely removed.

For example, instead of

Code: Select all

extern _kmain
<snip>
call _kmain
you'd have...

Code: Select all

extern kmain
<snip>
call kmain
EDIT: Perhaps a Wiki page with solutions to these DJGPP->cross-compiler transition problems (which are very common) is in order?

Re: Cross Compiler use problem

Posted: Tue Apr 27, 2010 2:04 am
by Solar
assainator wrote:and i'm not that stupid to not try and include the specific .o file.
That was the first thing I looked at, but no.
  • Which .o file should itoa() be defined in?
  • Is the symbol reported as missing actually in the expected .o file?
  • Why not?
Note that this is what I wrote last time, quoted verbatim.

I add the hint of 'objdump' to answer question #2.

The answer to #3 is most likely a leading underscore problem, effectively solved by deleting any object files you might have lying around from when you still used DJGPP. But I'm just guessing.

Re: Cross Compiler use problem

Posted: Tue Apr 27, 2010 5:28 am
by assainator
I have looked at the symboltables with objdump.

What I see is: The functions that should be in the object file ARE there.
I have itoa in printing.c AND I see itoa is there in the object dump file
But if I look at kernel.c (it calls itoa once) it is there, but in the file it is shown as UNDEFINED (*UND*)

Code: Select all


k.o:     file format elf32-i386

SYMBOL TABLE:
00000000 l    df *ABS*	00000000 kernel.c
00000000 l    d  .text	00000000 .text
00000000 l    d  .data	00000000 .data
00000000 l    d  .bss	00000000 .bss
00000000 l    d  .rodata	00000000 .rodata
00000000 l    d  .comment	00000000 .comment
00000000 g     F .text	00000387 kmain
00000000         *UND*	00000000 gdt_install
00000000         *UND*	00000000 idt_install
00000000         *UND*	00000000 isrs_install
00000000         *UND*	00000000 irq_install
00000000         *UND*	00000000 install_irq_keyboard
00000000         *UND*	00000000 timer_irq_install
00000000         *UND*	00000000 paging_install
00000000         *UND*	00000000 ClearScreen
00000000         *UND*	00000000 GotoXY
00000000         *UND*	00000000 SetMargin
00000000         *UND*	00000000 PrintString
000009e2 g     F .text	00000031 IsKey
00000387 g     F .text	0000062f CLI
00000000         *UND*	00000000 getchar
000009b6 g     F .text	0000002c WaitForQKey
00000000         *UND*	00000000 SetColor
00000000         *UND*	00000000 getstringw
00000000         *UND*	00000000 strlen
00000000         *UND*	00000000 itoa
00000000         *UND*	00000000 alloc
00000000         *UND*	00000000 memset
00000000         *UND*	00000000 GetY
00000000         *UND*	00000000 strequel
00000000         *UND*	00000000 printf
00000000         *UND*	00000000 GetFloppyConfigurationSimple
00000000         *UND*	00000000 GetTotalTicks
00000000         *UND*	00000000 GetSeconds
00000000         *UND*	00000000 GetMinutes
00000000         *UND*	00000000 GetHours
00000000         *UND*	00000000 GetTicks
00000000         *UND*	00000000 GetWaistedMemory
00000000         *UND*	00000000 GetCPUVendorString
00000000         *UND*	00000000 GetUsedMemory
00000000         *UND*	00000000 GetAllocatedPageTables



Code: Select all


prnt.o:     file format elf32-i386

SYMBOL TABLE:
00000000 l    df *ABS*	00000000 printing.c
00000000 l    d  .text	00000000 .text
00000000 l    d  .data	00000000 .data
00000000 l    d  .bss	00000000 .bss
00000000 l    d  .rodata	00000000 .rodata
00000000 l    d  .comment	00000000 .comment
00000000 g     O .bss	00000004 x
00000004 g     O .bss	00000004 y
00000000 g     O .data	00000004 VidMemPtr
00000004 g     O .data	00000002 color
00000008 g     O .bss	00000004 margin
00000000 g     F .text	0000000d GotoLine
0000000d g     F .text	0000000d SetMargin
0000001a g     F .text	0000001f SetColor
00000039 g     F .text	000000cf PrintChar
00000183 g     F .text	0000004d MoveRow
00000108 g     F .text	00000040 PrintString
00000000         *UND*	00000000 strlen
00000148 g     F .text	0000003b ClearScreen
00000000         *UND*	00000000 memcpy
00000000         *UND*	00000000 memset16
000001d0 g     F .text	00000015 GotoXY
000001e5 g     F .text	0000000a GetX
000001ef g     F .text	0000000a GetY
00000006 g     O .data	00000010 numberCharacters
00000020 g     O .bss	00000020 tmpItoaArray
000001f9 g     F .text	000000bc itoa
000002b5 g     F .text	00000088 short2bin
00000011       O *COM*	00000001 bufferBin16
0000033d g     F .text	00000079 int2bin
00000021       O *COM*	00000020 bufferBin32
000003b6 g     F .text	0000021f printf




Re: Cross Compiler use problem

Posted: Sat May 01, 2010 1:50 am
by assainator
I have still not been able to find the error.
Therefor I have decided to restart building my kernel (I wasn't that far anyway) but his time in C++.

I have only one problem. The linker cannot find my 'loader' symbol.
I have used objdump to find this:

Code: Select all

00000000         *UND*  00000000 loader
my start.asm file

Code: Select all


[BITS 32]
global loader
loader:
    mov esp, _sys_stack     ; This points the stack to the stack area
    jmp stublet

; This part MUST be 4byte aligned
ALIGN 4
mboot:
    ; Multiboot macros to make a few lines later more readable
    MULTIBOOT_PAGE_ALIGN	equ 1<<0
    MULTIBOOT_MEMORY_INFO	equ 1<<1
    MULTIBOOT_AOUT_KLUDGE	equ 1<<16
    MULTIBOOT_HEADER_MAGIC	equ 0x1BADB002
    MULTIBOOT_HEADER_FLAGS	equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
    MULTIBOOT_CHECKSUM	equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
    EXTERN code, bss, end

    ; This is the GRUB Multiboot header. A boot signature
    dd MULTIBOOT_HEADER_MAGIC
    dd MULTIBOOT_HEADER_FLAGS
    dd MULTIBOOT_CHECKSUM
    

;this will call all constructors, call main and destroy everything
stublet:
    extern __atstart
    extern kmain
    extern __atexit

    call __atstart
    call kmain
    call __atexit
    jmp $



SECTION .bss
    resb 8192               ; This reserves 8KBytes of memory here
_sys_stack:
And my linker file:

Code: Select all

ENTRY("loader")
OUTPUT_FORMAT("elf32-i386")
OUTPUT(kernel.bin)
STARTUP("start.o")


SECTIONS{
    . = 0x00100000;

    .text :{
        *(.text)
        code = .;        
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
        rodata = .;        
    }

    .data ALIGN (0x1000) : {
        *(.data)
        data = .;        
    
        __CTOR_LIST__ = .;
        LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)*.ctors
        LONG(0)__CTOR_END__ = .;
        
        __DTOR_LIST__ = .;
        LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) *(.dtors)
        LONG(0)__DTOR_END__ = .;
    }

    .bss : {
        sbss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
        bss = .;
    }
    
    end = .;
}

Re: Cross Compiler use problem

Posted: Sat May 01, 2010 3:34 pm
by Combuster
In what section did you put the asm code? probably in ""

Re: Cross Compiler use problem

Posted: Sun May 02, 2010 5:06 am
by assainator
This is why I hate assembly coding....
But there is one problem though. Once I link, LD says that it is already defined in the same file.
I have dumped the symbol table and it says that is is only defined once.

the linkerscript

Code: Select all

ENTRY(loader)
OUTPUT_FORMAT("elf32-i386")
OUTPUT(kernel.bin)
STARTUP("start.o")


SECTIONS{
    . = 0x00100000;

    .text :{
        *(.text)
        code = .;        
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
        rodata = .;        
    }

    .data ALIGN (0x1000) : {
        *(.data)
        data = .;        
    
        __CTOR_LIST__ = .;
        LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)*.ctors
        LONG(0)__CTOR_END__ = .;
        
        __DTOR_LIST__ = .;
        LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) *(.dtors)
        LONG(0)__DTOR_END__ = .;
    }

    .bss : {
        sbss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
        bss = .;
    }
    
    end = .;
}
the asm code

Code: Select all


[BITS 32]
[global loader]
section .text
loader:
  mov esp, _sys_stack
  jmp stublet

; This part MUST be 4byte aligned
ALIGN 4
mboot:
    ; Multiboot macros to make a few lines later more readable
    MULTIBOOT_PAGE_ALIGN	equ 1<<0
    MULTIBOOT_MEMORY_INFO	equ 1<<1
    MULTIBOOT_AOUT_KLUDGE	equ 1<<16
    MULTIBOOT_HEADER_MAGIC	equ 0x1BADB002
    MULTIBOOT_HEADER_FLAGS	equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
    MULTIBOOT_CHECKSUM	equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
    EXTERN code, bss, end


    ; This is the GRUB Multiboot header. A boot signature
    dd MULTIBOOT_HEADER_MAGIC
    dd MULTIBOOT_HEADER_FLAGS
    dd MULTIBOOT_CHECKSUM

stublet:
  
  push eax                        ; Multiboot magic number
  push ebx                        ; Multiboot info structure
  
  extern __atstart
  call __atstart
 
  extern kmain
  call kmain                       ; call kernel proper
  
  extern __atexit
  call __atexit
 
  cli
  hlt




SECTION .bss
    resb 8192               ; This reserves 8KBytes of memory here
_sys_stack:
the output from objdump

Code: Select all


start.o:     file format elf32-i386

SYMBOL TABLE:
00000000 l    df *ABS*	00000000 start.asm
00000000 l    d  .text	00000000 .text
00000000 l    d  .bss	00000000 .bss
0000000c l       .text	00000000 mboot
00000001 l       *ABS*	00000000 MULTIBOOT_PAGE_ALIGN
00000002 l       *ABS*	00000000 MULTIBOOT_MEMORY_INFO
00010000 l       *ABS*	00000000 MULTIBOOT_AOUT_KLUDGE
1badb002 l       *ABS*	00000000 MULTIBOOT_HEADER_MAGIC
00010003 l       *ABS*	00000000 MULTIBOOT_HEADER_FLAGS
e4514ffb l       *ABS*	00000000 MULTIBOOT_CHECKSUM
00000018 l       .text	00000000 stublet
00002000 l       .bss	00000000 _sys_stack
00000000         *UND*	00000000 code
00000000         *UND*	00000000 bss
00000000         *UND*	00000000 end
00000000         *UND*	00000000 __atstart
00000000         *UND*	00000000 kmain
00000000         *UND*	00000000 __atexit
00000000 g       .text	00000000 loader