CC65: Local label overflow

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
Diskover
Posts: 213
Joined: Thu Nov 24, 2011 7:16 am
Contact:

CC65: Local label overflow

Post 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?
User avatar
koitsu
Posts: 4200
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: CC65: Local label overflow

Post 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.
User avatar
tokumaru
Posts: 12122
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: CC65: Local label overflow

Post 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.
User avatar
rainwarrior
Posts: 8067
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: CC65: Local label overflow

Post 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?
User avatar
Diskover
Posts: 213
Joined: Thu Nov 24, 2011 7:16 am
Contact:

Re: CC65: Local label overflow

Post 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.
User avatar
koitsu
Posts: 4200
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: CC65: Local label overflow

Post by koitsu »

What about exceeding 65535 labels? Is this C code you've written or pure assembly code?
User avatar
rainwarrior
Posts: 8067
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: CC65: Local label overflow

Post 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?)
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: CC65: Local label overflow

Post 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.
Last edited by thefox on Tue Dec 13, 2016 6:21 pm, edited 1 time in total.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
rainwarrior
Posts: 8067
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: CC65: Local label overflow

Post 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.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: CC65: Local label overflow

Post 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.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
OscarRichard
Posts: 27
Joined: Sun Jul 29, 2012 9:58 am
Location: Mexico
Contact:

Re: CC65: Local label overflow

Post 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?
calima
Posts: 1396
Joined: Tue Oct 06, 2015 10:16 am

Re: CC65: Local label overflow

Post by calima »

Stop putting everything in one file. It's ugly.
Post Reply