Re: [cc65] Specifying segment for library code?

From: Ullrich von Bassewitz <>
Date: 2012-06-03 13:08:22
On Sun, Jun 03, 2012 at 01:15:46AM +0200, Oliver Schmidt wrote:
> Okay, the original question was:
> "For example,  if I have an overlay that uses strncmp, but the main
> program doesn't, it would be nice to be able to tell the linker to
> link strncmp to the overlay and not to the main program."
> Why does one need any special "magic" to do that? I don't see so. Just
> linking the overlay against the C library.

If one understands the question literally, then you're right. But then the
answer doesn't really help anybody. If you know in advance that your main
program doesn't contain strncmp but the overlay needs it, then just linking
both against the library will do what you want.

But in real life, you want the overlay to use *all* library functions from the
main program, if they are already there. And you want all others to be linked
to the overlay. And finally, you want to make this process automatic: If the
code of the main program changes, and - as an example - two additional library
functions are now in main, while a third one has been removed, then you want
your overlays to use the two library functions in main and have the third one
linked to the overlays if needed instead.

Linking all binaries separately will duplicate library functions. Linking them
in one step - as in your suggestion - will include library functions only
once, regardless of the actual output target. Which means that code in one
overlay will try to call the instance of strncmp() that lives in another
overlay. Which in turn will make your program crash. So what you need is a way
to have the overlays call code in main, but not in each other. And this is
accomplished by the solution I described in my email.

> Because you added the "%o.ovl" feature to the linker I asked you for
> and I commited to create generic overlay linker configs for the CBMs,
> Apple and Atatri using it instead of the "fixed" example. But I didn't
> do so by now :-(

Ok, thanks. I feared that it would be a problem on my side, and I'm really
relieved now :-)



Ullrich von Bassewitz                        
To unsubscribe from the list send mail to with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sun Jun 3 13:09:24 2012

This archive was generated by hypermail 2.1.8 : 2012-06-03 13:09:28 CEST