N00b Question :
When compiling a main program and linking into libraries. Does the entire library get compiled with the program, or only the routines which are used within that library ?
REMINDER - Stay logged in for at least 2 hours a week to get whitelisted.
Also it helps build a picture where our "good traffic" is coming from for detection scripts.
:o)
Also it helps build a picture where our "good traffic" is coming from for detection scripts.
:o)
Assembly compiling unused routines ?
-
exxos
- Site Admin

- Posts: 28555
- Joined: 16 Aug 2017 23:19
- Location: UK
-
stephen_usher
- Site sponsor

- Posts: 7427
- Joined: 13 Nov 2017 19:19
- Location: Oxford, UK.
Re: Assembly compiling unused routines ?
Usually the whole library gets pulled in.
Intro retro computers since before they were retro...
ZX81->Spectrum->Memotech MTX->Sinclair QL->520STM->BBC Micro->TT030->PCs & Sun Workstations.
Added code to the MiNT kernel (still there the last time I checked) + put together MiNTOS.
Collection now with added Macs, Amigas, Suns and Acorns.
ZX81->Spectrum->Memotech MTX->Sinclair QL->520STM->BBC Micro->TT030->PCs & Sun Workstations.
Added code to the MiNT kernel (still there the last time I checked) + put together MiNTOS.
Collection now with added Macs, Amigas, Suns and Acorns.
-
mikro
- Posts: 825
- Joined: 28 Aug 2017 23:22
- Location: Kosice, Slovakia
Re: Assembly compiling unused routines ?
That's a very simplified answer.
It depends on the linker and on the format of the object files. For instance, gcc + a.out format works that way that if some function is not referenced, it is discarded. HOWEVER, many functions internally reference others so even a simple hello world takes tens of kilobytes.
IIRC PureC has a similar concept (i.e. linking only those TOS calls which are used) but not sure about Devpac.
-
amimjf
- Posts: 87
- Joined: 22 Mar 2020 08:25
Re: Assembly compiling unused routines ?
Hi,
Similar to the above, it's all about what linker you use. Basically the linker's job is to resolve all symbols (functions) so if you call printf it will go find that in libc (for example), of course printf internally calls malloc/scanf, etc so you get a dependency list. The linker goes and pulls in the functions till all is resolved. Historically some took the simple approach and just included everything in the library.
Normally you can tell by looking in a hex editor for what happens when you call a library routine.
GAS/LD was pretty smart even in old 2.x versions from the 90's.
Similar to the above, it's all about what linker you use. Basically the linker's job is to resolve all symbols (functions) so if you call printf it will go find that in libc (for example), of course printf internally calls malloc/scanf, etc so you get a dependency list. The linker goes and pulls in the functions till all is resolved. Historically some took the simple approach and just included everything in the library.
Normally you can tell by looking in a hex editor for what happens when you call a library routine.
GAS/LD was pretty smart even in old 2.x versions from the 90's.
-
mfro
- Posts: 125
- Joined: 13 Dec 2018 07:32
Re: Assembly compiling unused routines ?
While generally correct for most other platforms, unfortunately, that's not the whole truth for the m68k a.out linker.mikro wrote: 29 Apr 2022 15:29 That's a very simplified answer.
It depends on the linker and on the format of the object files. For instance, gcc + a.out format works that way that if some function is not referenced, it is discarded. HOWEVER, many functions internally reference others so even a simple hello world takes tens of kilobytes.
This is not capable to pull individual functions from an archive but only individual objects.
If you have several functions in a single object file in a library and the linker needs only one single function from it, it will always pull the whole object (i.e. all the functions in it, even if they are not calling each other).
On other platforms sporting the ELF object format, you can use the -ffunction-sections -Wl,--gc-sections switches that will put every function object in a separate section allowing the linker to only pull what it needs. This option is of no use with the a.out object format, so the only solution is "only one cross each", i.e. only one function per source file.
And remember: Beethoven wrote his first symphony in C.
-
ijor
- Posts: 832
- Joined: 30 Nov 2018 20:45
Re: Assembly compiling unused routines ?
I have been using linkers and libraries since the 80's and I don't remember a linker that was dumb enough to pull an entire library. Alcyon, the very first compiler for the ST that was used to compile TOS itself, a rather primitive compiler btw, was already smart enough to extract only the modules that were required (directly or indirectly). I didn't try the very first PC compiler, but the very early ones I used were even smarter and more optimized than Alcyon.
The whole concept of library is that it is a collection of modules that are meant to be extracted. As a matter of fact the earlier tools for managing libraries were called "archiver" and not "librarian".
The whole concept of library is that it is a collection of modules that are meant to be extracted. As a matter of fact the earlier tools for managing libraries were called "archiver" and not "librarian".
http://github.com/ijor/fx68k 68000 cycle exact FPGA core
FX CAST Cycle Accurate Atari ST core
http://pasti.fxatari.com
FX CAST Cycle Accurate Atari ST core
http://pasti.fxatari.com
Who is online
Users browsing this forum: ClaudeBot and 5 guests