parallaxinc / Simple-Libraries

Contents of the SimpleIDE workspace folder and its Parallax Learn Simple Libraries subfolder.
http://learn.parallax.com/propeller-c-set-simpleide/update-your-learn-folder
21 stars 20 forks source link

Allow cogc file to be linked via static archive #14

Closed DavidZemon closed 8 years ago

DavidZemon commented 8 years ago

First, sorry about the whitespace changes - my editor automatically removes trailing whitespace. I can fix that and overwrite this commit if it matters to you.

This change comes from a recommendation by Eric Smith from Nov 2014.

As I think David Betz has already mentioned, the issue is that no symbols from cogcB.cog are being used, so it's not being pulled out of the library for linking. The __load_start_XXX symbol is not part of the .cog file, it's created by the linker only after the .cog file is added to the link, so that symbol cannot be used to force the link -- it's a chicken and egg problem. We actually need to reference something from the .cog file itself.

Any symbol in the .cog file that's used in the main program will force the link. A simple way to do this is to declare a variable in the .cogc file like:

extern unsigned int _load_start_toggle_fw_cog[];
const unsigned int *toggle_fw_code = _load_start_toggle_fw_cog;

Then have the cognew function use toggle_fw_code instead of _load_start_toggle_fw_code.

This works because toggle_fw_code will be a symbol defined in the .cog file itself (not linker created) and so any reference to it will cause the .cog file to be linked.

I've updated the cog_c_toggle demo in the default branch to demonstrate this approach.

I've checked and adcACpropab.cogc is the only cogc file in the Learn folder. This change opens up the door to allow all of the Learn folder to be 100% compatible with PropWare's build system, instead of only SimpleIDE's internal build system.

I do not myself have an Activity Board to test the changes. I therefore provided a binary to forums users and requested that the community test it for me. I'm unable to determine whether the code still operates correctly based the responses and therefore request your observations as well. http://forums.parallax.com/discussion/163202/activity-board-testing-request

AndyLindsay commented 8 years ago

Changes merged, thanks for pitching in to the propsideworkspace project David!