COGC, ECOGC, & _load_start_XXX_cog and Friends
sbr
Posts: 2
I am checking out COGC and EGOGC coding, and I run into issues with the compiler-generated symbols _load_start_XXX_cog etc. when trying to build the elf file, which I do using makefiles.
I use:
Main C file:
COGC file:
ECOGC File (basically same as COGC, for easy comparison):
Now, when I build my elf file flat directly in the directory with the source files, all is fine and well. However, when I try to build the elf file in a subdirectory 'builddir' of the source directory, I get linker errors. The makefiles show the process and set-up, but the essence of what I see is this.
When I create the elf flat directly in the source, the linker does:
However, when building in a subdirectory, the linker attempts (correctly, IMHO), but with errors:
I would appreciate any help or hint how to resolve this!
Thanks, Stefan
I use:
Main C file:
// file: ctog.c #include <stdio.h> #include <propeller.h> #include <cogload.h> #include "cogworks.h" typedef struct { unsigned int stack[16]; Combox combox; } Exchange; Exchange ex[8]; extern unsigned char _load_start_cog1_cog[]; extern unsigned char _load_start_cog2_ecog[]; extern unsigned char _load_stop_cog2_ecog[]; int start_cog_from_ram(void *ppar) { return (cognew(_load_start_cog1_cog, ppar)); } int start_cog_from_eeprom(void *ppar) { return (cognewFromBootEeprom(_load_start_cog2_ecog, _load_stop_cog2_ecog - _load_start_cog2_ecog, ppar)); } int main (int argc, char* argv[]) { for (int i = 0; i < 8; i++) { ex[i].combox.wait_interval = CLKFREQ >>1; ex[i].combox.base_pin = BASEPIN; // specify via make file/cmd line, like -DBASEPIN=0 } for (int i = 0; i < 2; i++) { printf("cog ram %d\n", start_cog_from_ram(&(ex[i].combox))); // start_cog_from_ram(&(ex[i].combox)); } for (int i = 2; i < 4; i++) { printf("cog eeprom %d\n", start_cog_from_eeprom(&(ex[i].combox))); // start_cog_from_eeprom(&(ex[i].combox)); } while(1); return 0; }
COGC file:
// File: cog1.cogc #include <propeller.h> #include "cogworks.h" static _COGMEM unsigned int next_cnt; static _COGMEM int me; _NATIVE void main (volatile Combox *cb) { next_cnt = CNT + cb->wait_interval; me = cogid(); DIRA = 1 << (me); \ while(1) { OUTA ^= 1 << (me); next_cnt = waitcnt2(next_cnt, cb->wait_interval); } }
ECOGC File (basically same as COGC, for easy comparison):
// File: cog2.ecogc #include <propeller.h> #include "cogworks.h" static _COGMEM unsigned int next_cnt; static _COGMEM int me; _NATIVE void main (volatile Combox *cb) { next_cnt = CNT + cb->wait_interval; me = cogid(); DIRA = 1 << (me); \ while(1) { OUTA ^= 1 << (me); next_cnt = waitcnt2(next_cnt, cb->wait_interval); } }I attach the makefiles for your reference. Note that they are work in progress. (I had to add an extension ".txt" to make the uploadable, which you'd need to remove. Sorry for this inconvenience).
Now, when I build my elf file flat directly in the directory with the source files, all is fine and well. However, when I try to build the elf file in a subdirectory 'builddir' of the source directory, I get linker errors. The makefiles show the process and set-up, but the essence of what I see is this.
When I create the elf flat directly in the source, the linker does:
/opt/parallax/bin/propeller-elf-gcc -o toggle.elf ctog.o cog1.cog cog2.ecog -sThe created elf file works properly.
However, when building in a subdirectory, the linker attempts (correctly, IMHO), but with errors:
/opt/parallax/bin/propeller-elf-gcc -o buildir/toggle.elf buildir/ctog.o buildir/cog1.cog buildir/cog2.ecog -s buildir/ctog.o: In function `_start_cog_from_ram': (.text.start_cog_from_ram+0x4): undefined reference to `__load_start_cog1_cog' buildir/ctog.o: In function `_start_cog_from_eeprom': (.text.start_cog_from_eeprom+0xc): undefined reference to `__load_start_cog2_ecog' buildir/ctog.o: In function `_start_cog_from_eeprom': (.text.start_cog_from_eeprom+0x14): undefined reference to `__load_stop_cog2_ecog'I now fail to see how I can make these undefined compiler-created symbols visible to the linker.
I would appreciate any help or hint how to resolve this!
Thanks, Stefan
Comments
If you're using GNU make it's pretty easy to fix this by changing the rules to run objcopy so that they look like: The "$(@F)" construct is like $@ but uses only the filename portion, leaving off any directory.
Eric
Thanks!
-- Stefan