Re: [cc65] .global vs .export vs what i really need :)

From: Groepaz <groepaz1gmx.net>
Date: 2009-10-24 23:22:25
On Samstag 24 Oktober 2009, Ullrich von Bassewitz wrote:
> On Fri, Oct 23, 2009 at 09:42:27PM +0200, Groepaz wrote:
> > the optimizer moves around small pieces of code, which means that often
> > labels will be referenced from a totally different place as before. the
> > consequence is that i need to tell the assembler somehow that this symbol
> > exists, ie i need to add the equivalent of a c prototype kindof.
>
> Why? For code labels, forwards should work without a problem.
>
> > mmh, since .global is already used, maybe you can add something
> > like .proto / .protozp that does this? or is there infact a way to achive
> > this with the existing stuff and i am just too dumb to read the docs? :)
>
> Maybe you can explain why there is a problem. If a label isn't know when it
> is encountered, the assembler assumes absolute addressing and fixes the
> correct value once it gets known.

ok well then.... its probably a bug in the assembler =)

i have uploaded two files: http://hitmen.c02.at/temp/easyprog.all.s ... this 
is the full code in one file, this file assembles and links (and works) fine.

http://hitmen.c02.at/temp/easyprog.opt.s is the optimized version, which gives 
the following errors:

Unresolved external `X00XL00F4X00X' referenced in:
  obj/easyprog.opt.s(483)
Unresolved external `X01XL00B6X01X' referenced in:
  obj/easyprog.opt.s(982)
Unresolved external `X03XL00DAX03X' referenced in:
  obj/easyprog.opt.s(722)
Unresolved external `X03XL00F6X03X' referenced in:
  obj/easyprog.opt.s(403)
  obj/easyprog.opt.s(502)
Unresolved external `X03XL0143X03X' referenced in:
  obj/easyprog.opt.s(582)
Unresolved external `X03XL0145X03X' referenced in:
  obj/easyprog.opt.s(868)
  obj/easyprog.opt.s(944)
Unresolved external `X03XL0199X03X' referenced in:
  obj/easyprog.opt.s(330)
  obj/easyprog.opt.s(606)
Unresolved external `X03XL019AX03X' referenced in:
  obj/easyprog.opt.s(785)
Unresolved external `X03XL019EX03X' referenced in:
  obj/easyprog.opt.s(1309)
Unresolved external `X03XL019FX03X' referenced in:
  obj/easyprog.opt.s(1311)
Unresolved external `X03XL01A1X03X' referenced in:
  obj/easyprog.opt.s(858)
Unresolved external `X06XL002CX06X' referenced in:
  obj/easyprog.opt.s(754)
  obj/easyprog.opt.s(1278)
Unresolved external `X06XL002DX06X' referenced in:
  obj/easyprog.opt.s(799)
Unresolved external `X06XL002EX06X' referenced in:
  obj/easyprog.opt.s(672)
Unresolved external `X06XL008EX06X' referenced in:
  obj/easyprog.opt.s(747)
  obj/easyprog.opt.s(1161)
  obj/easyprog.opt.s(1324)
Unresolved external `X06XL010BX06X' referenced in:
  obj/easyprog.opt.s(467)
Unresolved external `X06XL0146X06X' referenced in:
  obj/easyprog.opt.s(350)
Unresolved external `X06XL0149X06X' referenced in:
  obj/easyprog.opt.s(1015)
Unresolved external `X07XL0007X07X' referenced in:
  obj/easyprog.opt.s(1171)
Unresolved external `X09XL002BX09X' referenced in:
  obj/easyprog.opt.s(1242)
Unresolved external `X09XL002CX09X' referenced in:
  obj/easyprog.opt.s(1244)
Unresolved external `X10XL002AX10X' referenced in:
  obj/easyprog.opt.s(629)
Unresolved external `X10XL00CFX10X' referenced in:
  obj/easyprog.opt.s(1183)
Unresolved external `X10XL00D0X10X' referenced in:
  obj/easyprog.opt.s(1185)
Unresolved external `X10XL00D2X10X' referenced in:
  obj/easyprog.opt.s(1190)
Unresolved external `X10XL0111X10X' referenced in:
  obj/easyprog.opt.s(732)
ld65: Error: 26 unresolved external(s) found - cannot create output file

(this file assembles and works fine when adding .exports as "prototypes" for 
those labels manually)

the fact that in this source those labels are all in a bss section (i think) 
is a bit misleading, it also happens with labels in code (i have worked 
around this in this test by prefixing some of them). to me it looks like 
segments have to do with the problem though. here is a stripped down snippet 
that still gives an error:

	.proc	easyprog_opt_s0139
	sta	X00XL00F4X00X
	stx	X00XL00F4X00X+$01
	rts
	.endproc


	.proc	X00X_loadEAPIX00X 
	.segment	"BSS"
X00XL00F3X00X:
	.res	$01,$00
X00XL00F4X00X:
	.res	$02,$00
	.segment	"CODE"
	lda	#$01
	.endproc

$ cl65 -o bugtest bugtest.s
bugtest.s(5): Error: Symbol `X00XL00F4X00X' is undefined

now odd enough, when i add the .export X00XL00F4X00X at the top of the file, i 
do still get an error:

$ cl65 -o bugtest bugtest.s
bugtest.s(2): Error: Exported symbol `X00XL00F4X00X' was never defined

now i change the .export to .global ... and i get a similar error, but now 
from the linker

$ cl65 -o bugtest bugtest.s
ld65: Warning: [builtin config](6): Segment `STARTUP' does not exist
ld65: Warning: [builtin config](12): Segment `ZPSAVE' does not exist
Unresolved external `X00XL00F4X00X' referenced in:
  bugtest.s(2)
ld65: Error: 1 unresolved external(s) found - cannot create output file

and when i also put another .global directly before the label, THEN it finally 
compiles - but now the symbol is exported from the resulting object file, 
which it shouldnt:

$ od65 --dump-exports bugtest.o
bugtest.o:
  Exports:
    Count:                          1
    Index:                          0
      Type:                      0x30  (EXP_EXPR)
      Address size:              0x02  (absolute)
      Name:           "X00XL00F4X00X"


i am really confused now =) the whole import/export stuff seems to be mangled 
with the namespaces of procs (and possibly other things) if i interpret this 
test correctly. however, even this:

	.import X00XL00F4X00X

	.proc	easyprog_opt_s0139
	sta	X00XL00F4X00X
	stx	X00XL00F4X00X+$01
	rts
	.endproc


	.proc	X00X_loadEAPIX00X 
	.segment	"BSS"
X00XL00F3X00X:
	.res	$01,$00
	.export X00XL00F4X00X
X00XL00F4X00X:
	.res	$02,$00
	.segment	"CODE"
	lda	#$01
	.endproc

doesnt give the wanted result (the symbol is still exported from the object 
file).

.... help :)


-- 

http://www.hitmen-console.org    http://magicdisk.untergrund.net
http://www.pokefinder.org        http://ftp.pokefinder.org

Unser Schorf soll Döner werden!

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sat Oct 24 23:21:42 2009

This archive was generated by hypermail 2.1.8 : 2009-10-24 23:21:45 CEST