Linking error - undefined references

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.
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Re: Linking error - undefined references

Post by Techel »

Did you mean me?
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Linking error - undefined references

Post by abcdef4bfd »

If Combuster meaned me, i'm using the cross-compiler.
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

Re: Linking error - undefined references

Post by BASICFreak »

catnikita255 wrote:If Combuster meaned me, i'm using the cross-compiler.
And that's where the problem is.
Bran's Tutorial is written for DJGPP and NASM on windows.

DJGPP adds a leading underscore to all external ASM names.

GCC (or a cross compiler) does not.

EXAMPLE (Directly from Bran's Kernel)

under the original is:

Code: Select all

; This will set up our new segment registers. We need to do
; something special in order to set CS. We do what is called a
; far jump. A jump that includes a segment as well as an offset.
; This is declared in C as 'extern void gdt_flush();'
global _gdt_flush     ; Allows the C code to link to this
extern _gp            ; Says that '_gp' is in another file
_gdt_flush:
    lgdt [_gp]        ; Load the GDT with our '_gp' which is a special pointer
    mov ax, 0x10      ; 0x10 is the offset in the GDT to our data segment
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov ss, ax
    jmp 0x08:flush2   ; 0x08 is the offset to our code segment: Far jump!
flush2:
    ret               ; Returns back to the C code!
...---...
/* This will be a function in start.asm. We use this to properly
*  reload the new segment registers */
extern void gdt_flush();
and with a cross compiler it should be:

Code: Select all

; This will set up our new segment registers. We need to do
; something special in order to set CS. We do what is called a
; far jump. A jump that includes a segment as well as an offset.
; This is declared in C as 'extern void gdt_flush();'
global gdt_flush     ; Allows the C code to link to this
extern gp            ; Says that '_gp' is in another file
gdt_flush:
    lgdt [gp]        ; Load the GDT with our '_gp' which is a special pointer
    mov ax, 0x10      ; 0x10 is the offset in the GDT to our data segment
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov ss, ax
    jmp 0x08:flush2   ; 0x08 is the offset to our code segment: Far jump!
flush2:
    ret               ; Returns back to the C code!
...---...
/* This will be a function in start.asm. We use this to properly
*  reload the new segment registers */
extern void gdt_flush();
Notice the lack of the leading underscore in the ASM (this does not affect the C code)
So effectively ALL the ASM in Bran's Tutorial is DEAD - unless you really want DJGPP, which is not worth it I have tried.

I am curious why this is not mentioned under Bran's Known Bugs... http://wiki.osdev.org/Bran's_Known_Bugs

EDIT: No longer curious as I have added the section "Does not use Cross-Compiler".
Woot, first WiKi Edit 8)
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Linking error - undefined references

Post by abcdef4bfd »

BASICFreak wrote:
catnikita255 wrote:If Combuster meaned me, i'm using the cross-compiler.
And that's where the problem is.
Bran's Tutorial is written for DJGPP and NASM on windows.

DJGPP adds a leading underscore to all external ASM names.

GCC (or a cross compiler) does not.

EXAMPLE (Directly from Bran's Kernel)

under the original is:

Code: Select all

; This will set up our new segment registers. We need to do
; something special in order to set CS. We do what is called a
; far jump. A jump that includes a segment as well as an offset.
; This is declared in C as 'extern void gdt_flush();'
global _gdt_flush     ; Allows the C code to link to this
extern _gp            ; Says that '_gp' is in another file
_gdt_flush:
    lgdt [_gp]        ; Load the GDT with our '_gp' which is a special pointer
    mov ax, 0x10      ; 0x10 is the offset in the GDT to our data segment
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov ss, ax
    jmp 0x08:flush2   ; 0x08 is the offset to our code segment: Far jump!
flush2:
    ret               ; Returns back to the C code!
...---...
/* This will be a function in start.asm. We use this to properly
*  reload the new segment registers */
extern void gdt_flush();
and with a cross compiler it should be:

Code: Select all

; This will set up our new segment registers. We need to do
; something special in order to set CS. We do what is called a
; far jump. A jump that includes a segment as well as an offset.
; This is declared in C as 'extern void gdt_flush();'
global gdt_flush     ; Allows the C code to link to this
extern gp            ; Says that '_gp' is in another file
gdt_flush:
    lgdt [gp]        ; Load the GDT with our '_gp' which is a special pointer
    mov ax, 0x10      ; 0x10 is the offset in the GDT to our data segment
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov ss, ax
    jmp 0x08:flush2   ; 0x08 is the offset to our code segment: Far jump!
flush2:
    ret               ; Returns back to the C code!
...---...
/* This will be a function in start.asm. We use this to properly
*  reload the new segment registers */
extern void gdt_flush();
Notice the lack of the leading underscore in the ASM (this does not affect the C code)
So effectively ALL the ASM in Bran's Tutorial is DEAD - unless you really want DJGPP, which is not worth it I have tried.

I am curious why this is not mentioned under Bran's Known Bugs... http://wiki.osdev.org/Bran's_Known_Bugs

EDIT: No longer curious as I have added the section "Does not use Cross-Compiler".
Woot, first WiKi Edit 8)
Thanks, now code is linking fine. *goed creating vm86*
Post Reply