Page 1 of 1

CC65: Local label overflow

Posted: Tue Dec 13, 2016 12:42 pm
by Diskover
Hello everyone:

There is a time in the development of my game that despite having plenty of space to use (it is a 128Kb rom), the cc65 compiler gives me the error "Local label overflow" as soon as I try to add some more code, or chr data , Or nametables, etc. . .

It's like I'm on top of it despite having space.

Does anyone know what happens?

Re: CC65: Local label overflow

Posted: Tue Dec 13, 2016 1:00 pm
by koitsu
Do you have any local labelling structures that exceed 65535 generated labels? You really need to post code, I'm sorry to say.

Re: CC65: Local label overflow

Posted: Tue Dec 13, 2016 1:43 pm
by tokumaru
I'm always worrying that I'm gonna reach some kind of limit because I often use labels in unconventional ways in ca65, so I have to say this is pretty scary.

Re: CC65: Local label overflow

Posted: Tue Dec 13, 2016 1:49 pm
by rainwarrior
That's a new one, for me.

https://github.com/cc65/cc65/blob/maste ... asmlabel.c
So... you've made 65,000 local labels? Are you using some kind of macro library that generates hundreds of labels in a single statement?

Re: CC65: Local label overflow

Posted: Tue Dec 13, 2016 2:11 pm
by Diskover
tokumaru wrote:I'm always worrying that I'm gonna reach some kind of limit because I often use labels in unconventional ways in ca65, so I have to say this is pretty scary.
I have been with this project for months and the truth is that I am already used to this kind of thing.

Luckily I already have a first version of the game finished. . . But without music.

Let's see where I put the music now

:roll:
rainwarrior wrote:That's a new one, for me.

https://github.com/cc65/cc65/blob/maste ... asmlabel.c
So... you've made 65,000 local labels? Are you using some kind of macro library that generates hundreds of labels in a single statement?
With the few knowledge I have. . . No, I have not used macros.

Could it be that I've gotten to write 65,000 lines of code? Not really how many lines I wrote because I have everything separated in several files and the truth is that it would take me quite a while to get the count.

I have just written the program like any other that a junior writes: variables, arrays to store position data, functions with their if, some for, etc. . .

The overflow also happens if I modify some screen graphically to the point of exceeding a few kb the previous space.

Re: CC65: Local label overflow

Posted: Tue Dec 13, 2016 3:32 pm
by koitsu
What about exceeding 65535 labels? Is this C code you've written or pure assembly code?

Re: CC65: Local label overflow

Posted: Tue Dec 13, 2016 4:40 pm
by rainwarrior
Diskover wrote:Let's see where I put the music now

...

I have everything separated in several files
The error you're getting should be an assembly-time error, not a link-time error. It should be specific to assembling one .s file, and anything you put in other files is unrelated.

So... you should be able to put music in its own translation unit, unrelated to this problem.

Are you properly combining objects together at link time, or are you building everything in a single assembly? (i.e. is everything .included into a single file that you assemble?)

Re: CC65: Local label overflow

Posted: Tue Dec 13, 2016 6:02 pm
by thefox
I'm guessing it's C code (asmlabel.c is part of the C compiler), and a huge amount of code all in one compilation unit ("C file").

The "local label" in this case refers to the throwaway assembly labels generated by the C compiler. The label is local to the compilation unit. For example:

Code: Select all

int main(void) {
  static char i, sum;
  for(i = 0; i < 10; ++i)
    sum += i;
  return sum;
}
(cl65 -Oirs -c --listing loclab.lst loclab.c) =>

Code: Select all

000000r 1               .proc	_main: near
000000r 1               
000000r 1               .segment	"BSS"
000000r 1               
000000r 1               L0002:
000000r 1  00           	.res	1,$00
000001r 1               L0003:
000001r 1  00           	.res	1,$00
000002r 1               
000002r 1               .segment	"CODE"
000000r 1               
000000r 1  A9 00        	lda     #$00
000002r 1  8D rr rr     	sta     L0002
000005r 1  AD rr rr     L000F:	lda     L0002
000008r 1  C9 0A        	cmp     #$0A
00000Ar 1  B0 0D        	bcs     L0010
00000Cr 1  18           	clc
00000Dr 1  6D rr rr     	adc     L0003
000010r 1  8D rr rr     	sta     L0003
000013r 1  EE rr rr     	inc     L0002
000016r 1  4C rr rr     	jmp     L000F
000019r 1  AD rr rr     L0010:	lda     L0003
00001Cr 1  A2 00        	ldx     #$00
00001Er 1  60           	rts
00001Fr 1               
00001Fr 1               .endproc
(Some of the labels like L0004 have been removed in the optimization passes.)

The fix is to split your project into more than one compilation unit ("C file"), compile them separately and link. Whether this is easy or hard depends on how your project is structured.

The limit of 65536 labels is probably an artificial one, intended to catch compilations gone awry, so another option would be to persuade the cc65 devs to increase the limit.

EDIT: Changed "file" to "C file" to try to drive home the point that it's not enough to have multiple files and just #include them from one file, that'd still be a single compilation unit.

Re: CC65: Local label overflow

Posted: Tue Dec 13, 2016 6:11 pm
by rainwarrior
thefox wrote:I'm guessing it's C code (asmlabel.c is part of the C compiler)
Ah, right, sorry. I should have been saying "compile" instead of "assemble".
thefox wrote:The limit of 65536 labels is probably an artificial one, intended to catch compilations gone awry, so another option would be to persuade the cc65 devs to increase the limit.
I think it would be better to check for broken code generation before trying to increase the limit. This might be a symptom of a different problem, rather than simply "running out".

Again, if you can, post the files being built by the step that fails, or share them privately with someone you can help.

Re: CC65: Local label overflow

Posted: Tue Dec 13, 2016 6:29 pm
by thefox
rainwarrior wrote:I think it would be better to check for broken code generation before trying to increase the limit. This might be a symptom of a different problem, rather than simply "running out".
Yeah, it could be a code generation problem, depends on how many lines of code there actually are in the op's files. The simple example I made has about 4 lines, but already generates 16 local labels. It's not out of the question that you might run out with a lot of code in one file. The listing file will have the answer.

Re: CC65: Local label overflow

Posted: Wed Jan 05, 2022 7:51 pm
by OscarRichard
In my case I'm doing several arrays for my level, but I already got the message Local Label Overflow when compiling.

My game got the UNROM mapping with 16 prg banks (got the half so far) and also uses C code.

Any way/tool about increasing the limit in my project or do I must go back to 8 banks and make 2 roms with that?

Re: CC65: Local label overflow

Posted: Thu Jan 06, 2022 12:50 am
by calima
Stop putting everything in one file. It's ugly.