This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Unused labels in CA65?

Unused labels in CA65?
by on (#165109)
Is there a way to find labels that are not used in CA65? I'm trying to find code that may not be used, like dead code elimination in higher level languages. This would also help find ram storage that isn't being used.
Re: Unused labels in CA65?
by on (#165110)
I made a call graph tool as part of a code review of Thwaite in preparation for expanding the game past 16K PRG. You pass in a folder full of code, and it finds everywhere each symbol is used in order to make pretty boxes.

Call graph visualizer (using Python and GraphViz) and sample output
Re: Unused labels in CA65?
by on (#165117)
Nifty! I may have to incorporate this into my build process.

Thanks!
Re: Unused labels in CA65?
by on (#165138)
If you separate your code into multiple modules (think: 1 function defined in each .s file), and then combine them into a library, the ld65 linker is capable of identifying unused functions and automatically omitting them from the build.

The convenience of this is mitigated by having to create so many separate files, but it's available, at least. It's quite useful when linking with the CRT libraries.
Re: Unused labels in CA65?
by on (#165150)
rainwarrior wrote:
The convenience of this is mitigated by having to create so many separate files, but it's available, at least. It's quite useful when linking with the CRT libraries.

One trick that can be used to avoid having to create many files is to do something like this (example in C, but should be adaptable to assembly).
Code:
// my_funcs.c

#if defined FUNC_FOO

int foo(void) {
  return 123;
}

#elif defined FUNC_BAR

int bar(int xxx) {
  return xxx+1;
}

#endif

Then you'd simply compile the same file multiple times, defining FUNC_FOO or FUNC_BAR from the command line to decide which function should end up in the object file. Never did this myself, but I've seen it done elsewhere for libraries.

BTW, IIRC ld65 will only drop unused object files if they come from a library. If the object file is explicitly specified in the command line it will always be included.