English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 21 July 2016, 17:01   #1
iliak
Registered User

 
Join Date: Jan 2008
Location: somewhere
Posts: 43
Reference to undefined symbol __ldivu / __lmodu

Hello

Here's the plan. I'm coding a custom kickstart with cross compiling on Ubuntu 16.04 x64 using this toolchain : https://github.com/cahirwpz/amigaos-cross-toolchain. This tool chain is ok, every test I made for amiga executables are fine.Now, I want to make a custom kickstart from scratch so I don't want to use any system library or std lib.


Below is a bare bones c source code I made to isolate my problem :
blink.c
Code:
int main(void)
{
  unsigned long i = 1;
  unsigned long base = 1;


  while (i != 0)
  {
    i %= base;
    i /= base;
  }

}
Makefile
Code:
# A = vasmm68k_mot -Fhunk -spaces -nosym -quiet
C = vc -c -c99 -O1 -sc -vv -S -vv
L = vlink -nostdlib -s -brawbin1 -Ttext 0xfc0000
D = rm

default:      blink.o
              $(L) -o rom.bin blink.o

clean:
              @$(D) *.o rom.bin


blink.o:      blink.c
              $(C) blink.c
The output of make :
Code:
vc -c -c99 -O1 -sc -vv -S -vv blink.c
vc frontend for vbcc (c) in 1995-2010 by Volker Barthelmann
flags=389 opt=991 len=1522
Argument 8:blink.c
File "blink.c"=2
add_name: "/tmp/fileyYNTuE.asm"
vbccm68k "blink.c" -o= "/tmp/fileyYNTuE.asm" -c99 -sc  -O=991 -I/opt/m68k-amigaos/vbcc-include -I/opt/m68k-amigaos/os-include
vbcc V0.9b (c) in 1995-2011 by Volker Barthelmann
vbcc code-generator for m68k/ColdFire V1.8 (c) in 1995-2010 by Volker Barthelmann
add_name: "blink.o"
vasmm68k_mot -Fhunk -phxass "/tmp/fileyYNTuE.asm" -o "blink.o" -I/opt/m68k-amigaos/os-include
vasm 1.6b (c) in 2002-2013 Volker Barthelmann
vasm M68k/CPU32/ColdFire cpu backend 1.3e (c) 2002-2013 Frank Wille
vasm motorola syntax module 3.4a (c) 2002-2013 Frank Wille
vasm hunk format output module 2.3 (c) 2002-2012 Frank Wille

CODE(acrx4):              48 bytes
rm -v "/tmp/fileyYNTuE.asm"
'/tmp/fileyYNTuE.asm' supprimé
free p->obj
"blink.o"
free p
free p->obj
"/tmp/fileyYNTuE.asm"
free p
vlink -nostdlib -s -brawbin1 -Ttext 0xfc0000 -o rom.bin blink.o
blink.o: In "l5":
Error 21: blink.o (CODE+0xc): Reference to undefined symbol __lmodu.
Error 21: blink.o (CODE+0x1e): Reference to undefined symbol __ldivu.
makefile:7 : la recette pour la cible « default » a échouée
make: *** [default] Erreur 1
If I do the following modification everything compiles and links fine :
Code:
int main(void)
{
  unsigned long i = 1;
  unsigned long base = 1;


  //while (i != 0)                        // <========= HERE ======
  {
    i %= base;
    i /= base;
  }

}
The attached itoa.c file show a real source code and the errors are at lines 27 (modulo) & 29 (div):
itoa.o: In "l12":
Error 21: itoa.o (CODE+0x32): Reference to undefined symbol __lmodu.
Error 21: itoa.o (CODE+0x58): Reference to undefined symbol __ldivu.

And the full project is 68kos.zip

Can someone can help me on this ?
Attached Files
File Type: c itoa.c (553 Bytes, 133 views)
File Type: zip 68kos.zip (59.1 KB, 107 views)
iliak is offline  
Old 21 July 2016, 17:35   #2
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,318
Your C source does 32 bit modulo and division with a 32 bit result and it is compiled for a 68000 target CPU. But there is no native 68000 instruction for this task (only 68020+ has it), so the compiler calls _lmodu() and _ldivu() from vclib for these operations.

Solution: Either write _lmodu and _ldivu yourself or link with vc.lib.
phx is offline  
Old 21 July 2016, 21:29   #3
iliak
Registered User

 
Join Date: Jan 2008
Location: somewhere
Posts: 43
Hello,

You are right, using 68020 target (vc [...] -cpu=68020) and everything is now fine... Thank you !

But some questions remain unanswered :

- Why if the 'while' loop is present, the error rises, and not when there is no loop ? Does the compiler detects this case and adjust accordingly ?

- If I want to stick to 68000 target, you said I have to write my own version of those functions. Where can I get the source from ?

Thank you !
iliak is offline  
Old 22 July 2016, 12:59   #4
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,318
Quote:
Originally Posted by iliak View Post
- Why if the 'while' loop is present, the error rises, and not when there is no loop ? Does the compiler detects this case and adjust accordingly ?
Without the while-loop the compiler can easily see that the function isn't doing anything which has a side effect. So the operations in main() are optimized to nothing. The while-loop seems to make it more difficult for the optimizer to detect, so the code remains.

Quote:
- If I want to stick to 68000 target, you said I have to write my own version of those functions. Where can I get the source from ?
32/32=32 bit operations on the 68000 are no rocket science. You find plenty of examples on the net. But to make it easy for you, here is the source which is used in vclib:
Code:
;   32bit Division/Modulo for 68000/68010

* Functions:
*  long           __divu(register long d0, register long d1)
*  long           __divs(register long d0, register long d1)
*  long           __modu(register long d0, register long d1)
*  long           __mods(register long d0, register long d1)
*  __ldivs etc. expect parameters on the stack

        mc68000

        code

        xdef    __divu
        xdef    __divs
        xdef    __modu
        xdef    __mods
        xdef    __ldivs
        xdef    __ldivu
        xdef    __lmods
        xdef    __lmodu


__lmods
        movem.l 4(sp),d0/d1
__mods:
        tst.l   d1
        bmi     1$
        tst.l   d0
        bmi     2$
        bsr     __divu
        move.l  d1,d0
        rts
1$:     neg.l   d1
        tst.l   d0
        bmi     3$
        bsr     __divu
        move.l  d1,d0
        rts
2$:     neg.l   d0
        bsr     __divu
        neg.l   d1
        move.l  d1,d0
        rts
3$:     neg.l   d0
        bsr     __divu
        neg.l   d1
        move.l  d1,d0
        rts


__lmodu
        movem.l 4(sp),d0/d1
__modu:
        bsr     __divu
        move.l  d1,d0
        rts


__ldivs
        movem.l 4(sp),d0/d1
__divs:
        tst.l   d0
        bpl     2$
        neg.l   d0
        tst.l   d1
        bpl     1$
        neg.l   d1
        bsr     __divu
        neg.l   d1
        rts
1$:     bsr     __divu
        neg.l   d0
        neg.l   d1
        rts
2$:     tst.l   d1
        bpl     __divu
        neg.l   d1
        bsr     __divu
        neg.l   d0
        rts


__ldivu
        movem.l 4(sp),d0/d1
__divu:
        move.l  d2,-(sp)
        swap    d1
        move.w  d1,d2
        bne     2$
        swap    d0
        swap    d1
        swap    d2
        move.w  d0,d2
        beq     1$
        divu    d1,d2
        move.w  d2,d0
1$:     swap    d0
        move.w  d0,d2
        divu    d1,d2
        move.w  d2,d0
        swap    d2
        move.w  d2,d1
        move.l  (sp)+,d2
        rts
2$:     move.l  d3,-(sp)
        moveq   #16,d3
        cmp.w   #$80,d1
        bhs     3$
        rol.l   #8,d1
        subq.w  #8,d3
3$:     cmp.w   #$800,d1
        bhs     4$
        rol.l   #4,d1
        subq.w  #4,d3
4$:     cmp.w   #$2000,d1
        bhs     5$
        rol.l   #2,d1
        subq.w  #2,d3
5$:     tst.w   d1
        bmi     6$
        rol.l   #1,d1
        subq.w  #1,d3
6$:     move.w  d0,d2
        lsr.l   d3,d0
        swap    d2
        clr.w   d2
        lsr.l   d3,d2
        swap    d3
        divu    d1,d0
        move.w  d0,d3
        move.w  d2,d0
        move.w  d3,d2
        swap    d1
        mulu    d1,d2
        sub.l   d2,d0
        bhs     8$
        subq.w  #1,d3
        add.l   d1,d0
7$:     bhs.s   7$
8$:     moveq   #0,d1
        move.w  d3,d1
        swap    d3
        rol.l   d3,d0
        swap    d0
        exg     d0,d1
        move.l  (sp)+,d3
        move.l  (sp)+,d2
        rts

        
        end
But when you use this code anyway, why not simply linking with vc.lib?
phx is offline  
Old 22 July 2016, 13:32   #5
iliak
Registered User

 
Join Date: Jan 2008
Location: somewhere
Posts: 43
Quote:
Originally Posted by phx View Post
Without the while-loop the compiler can easily see that the function isn't doing anything which has a side effect. So the operations in main() are optimized to nothing. The while-loop seems to make it more difficult for the optimizer to detect, so the code remains.
That 's what I thought.

Quote:
32/32=32 bit operations on the 68000 are no rocket science. You find plenty of examples on the net. But to make it easy for you, here is the source which is used in vclib:
Code:
...snip...
But when you use this code anyway, why not simply linking with vc.lib?
Thank you for the source !
I want to make a custom kickstart from scratch, so I can't use any external library. I have to build "mine" (http://wiki.osdev.org/Why_do_I_need_a_Cross_Compiler)
iliak is offline  
Old 22 July 2016, 18:22   #6
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,318
Quote:
Originally Posted by iliak View Post
I want to make a custom kickstart from scratch, so I can't use any external library.
There is no difference between linking mykickstart.o mydivmod.o and mykickstart.o -lvc. Both will generate exactly the same output. Don't confuse a statically linked linker library with an OS shared library, which is called or linked at runtime. A linker library is just a collection of object files, and the linker pulls in only those objects which are needed.

Many functions from the C-library can be used without problems (e.g. all string operations, ctype, 64-bit arithmetics). You only have to make sure to avoid functions which do OS-calls, like stdio, stdlib, time.

When building a ROM you have to be careful with static variables. And it may be useful to write a proper linker script.
phx is offline  
Old 23 July 2016, 15:24   #7
iliak
Registered User

 
Join Date: Jan 2008
Location: somewhere
Posts: 43
Ok, understood.

Where can I download the source code of vclib ?
iliak is offline  
Old 24 July 2016, 23:57   #8
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,318
Quote:
Originally Posted by iliak View Post
Where can I download the source code of vclib ?
Not at all (I hope). It is not open source.
phx is offline  
Old 25 July 2016, 00:01   #9
iliak
Registered User

 
Join Date: Jan 2008
Location: somewhere
Posts: 43
Ok

Any way, thank you !
iliak is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
AmiDevCpp asm - undefined reference Sephnroth Coders. C/C++ 14 27 December 2022 16:51
SAS/C: Undefined symbols Yesideez Coders. C/C++ 14 13 February 2014 16:36
AsmOne: Undefined symbol copse Coders. Asm / Hardware 2 02 April 2012 01:41
Undefined symbol bsr.b init_bitmaps VoltureX Coders. General 12 13 November 2011 16:11
using the '*'-symbol in assembler - what do you expect? phx Coders. General 11 02 December 2009 12:56

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 00:59.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Page generated in 0.07735 seconds with 14 queries