English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 24 January 2020, 22:47   #1
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 304
vlink always links all modules from library

In my utillity library, I put each function into a seperate source file, as I expected that at linktime, only the modules will be included which are actually referenced.

Now I noticed that always the whole library seems to be linked into the final executable, even if the code is never called, so I wonder what I am doing wrong?

An example can be found here: https://github.com/skeetor/amiga-uti.../from_decu16.s

All modules use
Code:
    section .text,code
So maybe this is the reason?
Should I put each module into a separate section?

The linker command is this:
Code:
/opt/amiga/bin//vlink -b amigahunk -Bstatic -nostdlib CMakeFiles/Choplifter.dir/main.s.o CMakeFiles/Choplifter.dir/intro/CopperAnimation.s.o -o ../bin/Choplifter.exe /opt/amiga/utils/lib/libAmigaUtils.a
All code is compiled with vasm and the sample project can be found here (just in case): https://github.com/skeetor/container/tree/cp_dev

I attached a sample binary where you can see that the symbols are included, like 'fromDecimalU32' but this function is nowhere called in my code. When I look in Monam I can see that not only the symbol is lsted, but the code is also there.
Attached Files
File Type: zip demo.zip (3.2 KB, 8 views)

Last edited by sparhawk; 24 January 2020 at 22:53.
sparhawk is offline  
Old 24 January 2020, 23:00   #2
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 348
Quote:
Originally Posted by sparhawk View Post
In my utillity library, I put each function into a seperate source file, as I expected that at linktime, only the modules will be included which are actually referenced.

Now I noticed that always the whole library seems to be linked into the final executable, even if the code is never called, so I wonder what I am doing wrong?

How do you build your library then? If just by linking the binaries, then the linker will put them into one hunk. You either need an object module librarian, such as the SAS/C "OML" utility, or a specialized linker for that which does not merge all the hunks.
Thomas Richter is offline  
Old 24 January 2020, 23:09   #3
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 304
The library itself is just linked with 'ar'
Code:
amiga-ar qc ../lib/libAmigaUtils.a snprintf.cpp.o vsnprintf.cpp.o SystemTakeover.s.o WaitRaster.s.o DebugPowerLED.s.o GFXLibrary.s.o MouseHelper.s.o dos/DOSLibrary.s.o dos/WriteString.s.o strlen.s.o from_decu16.s.o from_decu32.s.o from_decs.s.o to_decu16.s.o to_decs16.s.o to_decu32.s.o to_decs32.s.o mem/memcpyl.s.o mem/memcpyw.s.o mem/zcopyb.s.o mem/zcopyw.s.o mem/zcopyl.s.o copper/CreateCopperList.s.o copper/CreateCopperListC.s.o math/div32.s.o math/mult32.s.o
amiga-ranlib ../lib/libAmigaUtils.a
I stripped the paths to make it easier to read.

This library is then linked as I wrote above.
Code:
vlink -b amigahunk -Bstatic -nostdlib CMakeFiles/Choplifter.dir/main.s.o CMakeFiles/Choplifter.dir/intro/CopperAnimation.s.o -o ../bin/Choplifter.exe /opt/amiga/utils/lib/libAmigaUtils.a
So I can not use 'ar' for that? Or should I use gcc ld for linking?
sparhawk is offline  
Old 25 January 2020, 22:19   #4
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,600
Don't know what your amiga-ar is creating. Probably a Unix ar-library? Have a look into the map file (-M) to see what vlink has done with it.

Unix libraries are supported by vlink, but you have to specify it as a library (-l option). You added it as another object file to the command line, so it is regarded as an object file instead as a library. In your case, you may try:
vlink ... -L../lib -lAmigaUtils


BTW, making a real hunk-format linker-library for AmigaOS is really simple:
join obj1.o objN.o as mylib.lib
(or use 'cat' when under Unix)
Then link with:
vlink ... -Lpathtomylib -lmylib
phx is offline  
Old 25 January 2020, 22:26   #5
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 304
I checked the manual for vlink and found an option which seems to do what I wanted:

Code:
-gc-all
removes all the modules which are not referencedfrom the final binary.

My 'amiga-ar' ist just a wrapper for bebbos m68k tools, because on some of them I need to filter certain parameters which are not supported, but are used by CMake (That's mostly for gcc though).
sparhawk is offline  
Old 25 January 2020, 22:30   #6
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 304
Quote:
Originally Posted by phx View Post
Unix libraries are supported by vlink, but you have to specify it as a library (-l option). You added it as another object file to the command line, so it is regarded as an object file instead as a library. In your case, you may try:

Thanks for pointing that out. Since the linked binary always worked, I haven't noticed that. I wrote some CMake modules to support m68k-amigaos from bebbo, so it seems I have some of the compiler definition scripts wrong because if I had set it up correct, CMake should have created that library parameter.
sparhawk is offline  
Old 25 January 2020, 23:40   #7
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 304
After fixing the issue, that my library was not linked like a library, it turned out, that this was also the reason why it didn't throw away unreferenced modules. I didn't need the '-gc-all' switch after that fix and binaries are now as small as they should be.
sparhawk is offline  
Old 26 January 2020, 01:15   #8
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,600
phx 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
Preventing hunk merger with vlink Hedeon Coders. C/C++ 2 24 August 2018 14:40
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
Brain Killer Aminet links changed (and a question about Aminet links) Korodny HOL data problems 0 26 November 2009 21:21

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 21:10.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.08517 seconds with 16 queries