Re: [cc65] ca65 for stand-alone asm projects

From: Oliver Schmidt <ol.sc1web.de>
Date: 2010-11-02 12:19:11
Hi,

> So, I see in source\libsrc\c64\crt0.s that the BASIC stub is placed
> in segment "EXEHDR", but I don't see anything in the way you invoke
> ld65 or anything in the .cfg file that would cause that segment to
> be linked.

Maybe the crt0.s and the .cfg you are looking at just don't match. If
you are seeing a EXEHDR in the C64 crt0.s then you are looking at a
recent snapshot. If you don't find EXEHDR in the ld65 built-in C64
.cfg then you are most likely looking at the last release. The .cfg of
the current snapshot contains this:

MEMORY {
...
    HEADER: file = %O,               start = $07FF, size = $000E;
...
}
SEGMENTS {
    EXEHDR:   load = HEADER, type = ro;
...
}

> Perhaps the "one symbol is referenced" rule means is
> forcing the entire crt0 module to be linked;

That's in fact how it works.

> but in my recent
> experience, putting code into a segment that is not listed in the
> SEGMENTS statement of the config file normally causes an error (or
> at least a warning) when I try to build/link it.

That's in fact true.

> But this is not
> what we see when compiling for a C64 target.

See my guess above.

> So I'm left to guess that the linker is performing some amount of
> hidden "magic" to make it work, although I don't see why it couldn't
> just as well be accomplished explicitly.  For example, if I wanted
> to replicate this behavior on my own "target", would it be sufficient
> to place an "EXEHDR" entry (or other name I've chosen for the stub)
> as the the first item in the segments clause?

Yes.

There is however one piece of magic you might want to know about:

All .o file mentioned on the ld65 cmdline are always linked. So if you
put the stub in a .o file you mention on the cmdline the stub is
there. If you however place the .o file with the stub in a library and
don't reference anything from the .o file, it won't be linked - so the
stub will be missing. To circumvent this, the crt0.s file (which *IS*
placed in a library) contains the line

        .export         __STARTUP__ : absolute = 1      ; Mark as startup

This __STARTUP__ symbol is "implicitly" referenced, so the .o file
containing it is linked causing the stub to be there.

> Which leads me to the next question...  Are the segments linked into
> the final binary in the same order they are listed in the .cfg file?

Yes.

> I'd like to help improve the documentation in this respect...

Seems a great idea to me - which unfortunately about nobody has who -
correctly - points out weaknesses in the cc65 documentation!

Regards,
Oliver
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Tue Nov 2 12:19:17 2010

This archive was generated by hypermail 2.1.8 : 2010-11-02 12:19:19 CET