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

Exporting the addresses/values of all labels in CC65

Exporting the addresses/values of all labels in CC65
by on (#159331)
Is it possible to compile a CC65 project and let the compiler create a file with the addresses and values of every label?
I.e. no matter if I write Label: or Constant = $1234, I want these names to be listed in a file with their actual value.

I checked the documentation:
http://www.cc65.org/doc/cl65-2.html
but I didn't find anything.
The -m <file> command only lists the offsets and sizes of each segment per file as well as exports and imports.

But I need an option where every label is shown with its actual value, even if it's just some local constant in a single file.
Re: Exporting the addresses/values of all labels in CC65
by on (#159332)
The debug files (--dbgfile switch for ld65) contain that information, but you might have to dig for it.

BTW, that documentation is outdated, the up-to-date docs are at http://cc65.github.io/doc/
Re: Exporting the addresses/values of all labels in CC65
by on (#159333)
Is there any specific way to use it? Because in the moment, it doesn't list any constants from my own files:

Example:
Code:
file   "GameLoop.s",size=5006,mtime=0x564CEC72
file   "General.s",size=2736,mtime=0x563EC30E
file   "CommonConstants.inc",size=201,mtime=0x564CEC72
[...]
file   "zeropage.s",size=898,mtime=0x4F3267B9
sym   ".size",value=0x00000006,addrsize=zeropage,type=equate
sym   ".size",value=0x00000004,addrsize=zeropage,type=equate
sym   "regbank",value=0x0000006B,addrsize=zeropage,type=label
sym   "tmp4",value=0x0000006A,addrsize=zeropage,type=label
sym   "tmp3",value=0x00000069,addrsize=zeropage,type=label
Re: Exporting the addresses/values of all labels in CC65
by on (#159336)
I use the -Ln command line option to dump a "label file" containing the values of every label at link time. To get local symbols (ones that aren't exported) to appear here, you need to use the -g command line option in ca65/cc65 to make these available to the linker; otherwise you'll get very few labels to appear. (This probably applies to using --dbgfile as well.)

The main problem I have with -Ln is that it just gives addresses for every label. It does not tell me the original segment or memory block, which is a bit of a pain if you're doing banking. This is one reason why I tend to do each bank in a separate link; that way I don't have overlapping labels.
Re: Exporting the addresses/values of all labels in CC65
by on (#159338)
There's a .bank function that returns the bank= attribute of a segment's memory area. Would it be worthwhile to file an enhancement request against cc65 to provide this information in the label file that ld65 produces if the config file contains bank= attributes?
Re: Exporting the addresses/values of all labels in CC65
by on (#159340)
DRW wrote:
Is there any specific way to use it? Because in the moment, it doesn't list any constants from my own files:

Yeah, like rainwarrior said you have to compile with debug information (-g).

There's a C library available at https://github.com/cc65/cc65/tree/master/src/dbginfo that can be used to parse the data, if it's too much work manually for whatever you might be using it. dbgsh.c is an example of how it could be used.

tepples wrote:
There's a .bank function that returns the bank= attribute of a segment's memory area. Would it be worthwhile to file an enhancement request against cc65 to provide this information in the label file that ld65 produces if the config file contains bank= attributes?

First thing to remember here is that the label file is primarily/originally meant to be consumed by the VICE emulator, so unless such change can be incorporated in a way that still works with VICE, I don't see that happening.
Re: Exporting the addresses/values of all labels in CC65
by on (#159342)
thefox wrote:
tepples wrote:
Would it be worthwhile to file an enhancement request against cc65 to provide this information in the label file that ld65 produces if the config file contains bank= attributes?

First thing to remember here is that the label file is primarily/originally meant to be consumed by the VICE emulator, so unless such change can be incorporated in a way that still works with VICE, I don't see that happening.

The idea was that the linker would use presence of the bank= attribute to determine whether to include extended information. Do linker configs targeting images for use with VICE use the bank= attribute?
Re: Exporting the addresses/values of all labels in CC65
by on (#159514)
Thanks for the information. I resolved my issue without having to use this, but I'll get back to it if the addresses become an issue again.