"Dead code" removal works with SDCC at compile-time, but not during the link phase: if some functions are defined but never called, they still get linked. Is there any way to avoid this?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is usually called "smart linking" and works at function level.
That is: if a function is defined but never called, then the linker removes it from the final object.
It is very similar to what happens when you link libraries: you don't get the whole library, only the function you use.
With my great surprise, I just discovered, like you did, that the sdcc linker doesn't perform the smart linking.
Introducing it would be a great enhancement, IMHO.
I was then thinking to convert my files to library modules, but I'm unable to find the documentation for sdar.exe and, furthermore, the Win 32 bit version of sdar included in sdcc-4.5.0 can't work because the zlib1.dll is missing...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You might want to try current SDCC 4.6.0 (though the linking feature you want is not there yet, so you'll still have to use modules for 4.6.0) as the zlib1.dll issue should be fixed now.
AFAIR, @janko-5 was considering looking into this feature for 4.7.0, but I haven't heard from him in a while.
Last edit: Philipp Klaus Krause 3 days ago
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"Dead code" removal works with SDCC at compile-time, but not during the link phase: if some functions are defined but never called, they still get linked. Is there any way to avoid this?
This is usually called "smart linking" and works at function level.
That is: if a function is defined but never called, then the linker removes it from the final object.
It is very similar to what happens when you link libraries: you don't get the whole library, only the function you use.
With my great surprise, I just discovered, like you did, that the sdcc linker doesn't perform the smart linking.
Introducing it would be a great enhancement, IMHO.
I was then thinking to convert my files to library modules, but I'm unable to find the documentation for sdar.exe and, furthermore, the Win 32 bit version of sdar included in sdcc-4.5.0 can't work because the zlib1.dll is missing...
You might want to try current SDCC 4.6.0 (though the linking feature you want is not there yet, so you'll still have to use modules for 4.6.0) as the zlib1.dll issue should be fixed now.
AFAIR, @janko-5 was considering looking into this feature for 4.7.0, but I haven't heard from him in a while.
Last edit: Philipp Klaus Krause 3 days ago
Sorry, but I can't find any SDCC 4.6.0. for win 32.
The latest seems to be 4.5.0 (2025-01-28) here.