Re: [cc65] Startup magic

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2009-08-01 12:58:30
Hi!

On Sat, Aug 01, 2009 at 12:09:37PM +0200, Oliver Schmidt wrote:
> Hm, until now I thought that placing the startup object file on the
> linker command line was solely necessary to make sure it get's linked
> - acting like an anchor that pulls in everything else necessary.

That depends. In the early versions of cc65, the startup file had to be the
first module in the linker command line (up until yesterday, most startup
files contained such a note). The first reason was to have it linked in, the
second was to have the code placed at the start of the executable, which is
necessary for most platforms.

With the introduction of the STARTUP segment, only the first reason was still
valid. However, there are still platforms without a STARTUP segment. The Atari
for example places the startup code in the LOWCODE segment. If there is more
than one module with code in LOWCODE, linker placement depends on the order of
modules - so for the Atari, the startup module still had to be the first
module on the linker command line.

With the latest change, even the second reason is no longer valid, because the
compiler forces a dependency to a symbol named __STARTUP__ when it encounters
the main() function. This dependency is satisfyied by an export in the startup
module, so the linker will get it from the library. But in this case, the
order of modules in the final executable depends on the internals of the
linker, and for a specific placement of the startup code segments in
collaboration with the linker config i necessary.

> But regarding the placement of the startup code at the beginning of
> the binary I thought this was all the recent years managed in the
> linker config by declaring the STARTUP segment as the first one going
> into the RAM memory area.

Not for all platforms. I explicitly mentioned the Atari, which doesn't have
the STARTUP segment. There are other platforms without it, but as far as I can
say, they don't need it, because they don't have special placement needs for
the STARTUP code.

For most projects, the latest change shouldn't have any impacts on code or
whatever. It just simplifies handling, because there is no longer a separate
startup module that must be specified when linking with ld65. It does also
remove the chance to forget it and produce strange linking errors:-)

I hope this clear things up a bit.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
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 Aug 1 12:59:55 2009

This archive was generated by hypermail 2.1.8 : 2009-08-01 12:59:57 CEST