English Amiga Board


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

 
 
Thread Tools
Old 11 January 2020, 19:31   #1
adrianpbrown
Registered User

 
Join Date: Jan 2020
Location: Launceston
Posts: 3
VLINK / VBCC / VASM linking order issue

Hi, Ive setup a build system that uses vasm to assemble files, vc/vbcc to compile files and vlink to link them all in amiga hunk format. Im not including the startup.o / mstartup.o as i dont want to use the C code as the initial startup. I pass one of the asm->.o files as the first object code to the linker but still it insists on putting the .c->.o file as the startup even though it is literally just this

int SomeFunction()
{
int i = 10;
i++;
return i;
}

(Its just a test function for now). Everything suggests that amiga linking should use the first .o as the entry point? Am I doing something wrong? Also i couldnt find the source code to the startup.o/mstartup.o files so i cant alter these to my requirements either

Many Thanks
adrianpbrown is offline  
Old 12 January 2020, 02:24   #2
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,919
Quote:
Originally Posted by adrianpbrown View Post
Everything suggests that amiga linking should use the first .o as the entry point?
Correct. An Amiga executable is always started with the first instruction in the first section. A linker usually keeps the order of object files on the command line, when merging their sections into the output executable.

Quote:
Am I doing something wrong?
Probably. But hard see without an example, like the full commandline when calling vlink. Hint: You may call vlink with the -M option, which generates a map file. It shows the order of all files and sections in the output.

Quote:
Also i couldnt find the source code to the startup.o/mstartup.o files so i cant alter these to my requirements either
vclib is free, but not open source. Anything special you would need?
phx is offline  
Old 12 January 2020, 07:38   #3
adrianpbrown
Registered User

 
Join Date: Jan 2020
Location: Launceston
Posts: 3
Ahh, that starts to throw more information onto the issue

Code:
Assembling:     System.asm
l:\catfish\amiga\rubyfire\tools\bin\vasmm68k_mot.exe -m68000 -Fhunk -linedebug -spaces -phxass -opt-fconst -nowarn=62 -I"../Includes" -I"Includes" -I"Libs/Catfish/Includes" -o "Libs/Catfish/Build/System.o" Libs/Catfish/Src/System.asm
Compiling:      System.c
l:\catfish\amiga\rubyfire\tools\bin\vc.exe +aos68k_win -g -c -I"../../tools/bin/targets/m68k-amigaos/include" -I"../Includes" -I"Includes" -I"Libs/Catfish/Includes" -o "Libs/Catfish/Build/System_c.o" Libs/Catfish/Src/System.c
Assembling:     main.asm
l:\catfish\amiga\rubyfire\tools\bin\vasmm68k_mot.exe -m68000 -Fhunk -linedebug -spaces -phxass -opt-fconst -nowarn=62 -I"../Includes" -I"Includes" -I"Libs/Catfish/Includes" -o "Build/main.o" Src/main.asm
Linking:        blah.exe
l:\catfish\amiga\rubyfire\tools\bin\vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib -M "Build/main.o" "Libs/Catfish/Build/System.o" "Libs/Catfish/Build/System_c.o" -L"../../tools/bin/targets/m68k-amigaos/lib" -lvc -o blah.exe

Files:
  main.asm:  GameCode 0(38), Variables 0(18) hex
  System.asm:  Framework 0(dc), Variables 0(3c) hex
  Libs\Catfish\Src\System.c:  CODE 0(8) hex


Section mapping (numbers in hex):
------------------------------
  00000000 GameCode  (size 38)
           00000000 - 00000038 main.asm(GameCode)
------------------------------
  00000000 Framework  (size dc)
           00000000 - 000000dc System.asm(Framework)
------------------------------
  00000000 CODE  (size 8)
           00000000 - 00000008 Libs\Catfish\Src\System.c(CODE)
------------------------------
  00000000 Variables  (size 3c)
           00000000 - 0000003c System.asm(Variables)
------------------------------
  00000000 Variables  (size 18, allocated 0)
           00000000 - 00000018 main.asm(Variables)


Symbols of GameCode:
  Startup: local reloc, value 0x0, size 0

Symbols of Framework:
  SYS_Takeover: global reloc, value 0x0, size 0
  _SYS_ReleaseWBMessage: local reloc, value 0x6a, size 0
  SYS_DisplayGUIMessage: local reloc, value 0x30, size 0
  _SYS_AllocMemory: local reloc, value 0x86, size 0
  SYS_Release: global reloc, value 0x2a, size 0
  _SYS_GetWBMessage: local reloc, value 0x32, size 0

Symbols of CODE:
  l1: local reloc, value 0x4, size 0
  _SomeFunction: global reloc, value 0x0, size 0

Symbols of Variables:
  _SYSERROR_UnableAllocChip: local reloc, value 0x0, size 0
  _SYSERROR_UnableAllocFast: local reloc, value 0x1e, size 0

Symbols of Variables:
  SYS_Details: local reloc, value 0x0, size 0
It looks like it doesnt recognise the section details of the .asm file as code (Although that could just be the actual name).

The start of the main.asm is

Code:
							SECTION		GameCode, CODE_F

Startup:
							jsr			_SomeFunction
As to the startup file, hard to say other than i like to know exactly whats going on. Im not too fussed about using the standard libraries, its more just using C for functions to try and speed up development a bit (although most will likely be in asm).

Cheers
adrianpbrown is offline  
Old 12 January 2020, 15:03   #4
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,919
Quote:
Originally Posted by adrianpbrown View Post
Code:
l:\catfish\amiga\rubyfire\tools\bin\vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib -M "Build/main.o" "Libs/Catfish/Build/System.o" "Libs/Catfish/Build/System_c.o" -L"../../tools/bin/targets/m68k-amigaos/lib" -lvc -o blah.exe

Files:
  main.asm:  GameCode 0(38), Variables 0(18) hex
  System.asm:  Framework 0(dc), Variables 0(3c) hex
  Libs\Catfish\Src\System.c:  CODE 0(8) hex
Your code has no reference to vclib at all. Otherwise you would read on top of the map file something like "vclib (path/file.c) needed due to _xyz". So you could also choose to drop -L.. and -lvc at this point.


Quote:
Code:
Section mapping (numbers in hex):
------------------------------
  00000000 GameCode  (size 38)
           00000000 - 00000038 main.asm(GameCode)
Looking good. This is your first section in the executable, so the first instruction from main.asm(GameCode) starts it.

Quote:
It looks like it doesnt recognise the section details of the .asm file as code (Although that could just be the actual name).
It's just the section name. The C-compiler calls the code-section "CODE", while you called it "GameCode" and "Framework".

Note, that the linker will not merge sections with different names and/or types (unless specifying the -sc option to merge all code, or -sd to merge all data/bss). This might be important if you want to use PC-relative references between your code parts.

Quote:
The start of the main.asm is

Code:
                            SECTION        GameCode, CODE_F

Startup:
                            jsr            _SomeFunction
As to the startup file, hard to say other than i like to know exactly whats going on.
Is this not the first instructon executed in your executable? It should, according to the map file. I'm not sure whether I understand what your actual problem is.

(Side note: There is never a reason to use code_f instead of code, except you don't want anybody to run your code on a Chip-RAM-only system.)

Quote:
Originally Posted by adrianpbrown View Post
I pass one of the asm->.o files as the first object code to the linker but still it insists on putting the .c->.o file as the startup
What is a ".c->.o" file? Did you mean that System_c.o is the first code in your executable? I cannot believe that.

Quote:
Im not too fussed about using the standard libraries, its more just using C for functions to try and speed up development a bit (although most will likely be in asm).
This should work fine.
phx is offline  
Old 13 January 2020, 13:57   #5
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 52
Posts: 392
Quote:
Originally Posted by adrianpbrown View Post
As to the startup file, hard to say other than i like to know exactly whats going on. Im not too fussed about using the standard libraries, its more just using C for functions to try and speed up development a bit (although most will likely be in asm).

If you plan to call C functions from your asm code, you may still need to write a regular "main()" module as your entrypoint and call your asm from there, as the compiler startup does some additional stuff in the background before it calls main, like initializing static variables etc..
sparhawk is offline  
Old 13 January 2020, 18:10   #6
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,919
Quote:
Originally Posted by sparhawk View Post
If you plan to call C functions from your asm code, you may still need to write a regular "main()" module as your entrypoint
To be more precise: if you plan to call clib (vclib in this case) functions...

Initialising the clib, or running constructors, would be the main reason for a startup code. And not even all clib functions would need it. The string functions or ctype could still be used.
phx is offline  
Old 14 January 2020, 07:10   #7
adrianpbrown
Registered User

 
Join Date: Jan 2020
Location: Launceston
Posts: 3
Thanks everyone. Ive sorted my issues, mostly it was a case of red herring where the debugger wasnt stopping on the breakpoint so it looked like it wasnt doing what it was supposed to.
adrianpbrown 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
vasm / vlink undefined symbol zeGouky Coders. General 2 02 January 2019 08:49
Vasm/Vlink odd issue linking roondar Coders. Asm / Hardware 7 10 December 2017 20:19
Trying out vlink and vasm cla Coders. General 2 30 September 2016 20:30
VLINK multiple VASM objects roondar Coders. Asm / Hardware 2 24 April 2016 01:03
Help linking VASM object code clenched Coders. Asm / Hardware 2 24 May 2013 22:32

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 05:37.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Page generated in 0.08182 seconds with 13 queries