-ffunction-sections -fdata-sections don't work with cogc
Kye
Posts: 2,200
I've been compiling my own cogc code with -ffunction-sections -fdata-sections. However, when you define static _COGMEM variables they get put into their own .bss section using this versus being put into the .text section. Thus when you link these variables end up in the hub even though they are supposed to be in a cog. Non-cog mem variables are put into the hub .data/.bss like you would expect and are optimized out if they are unused with the -ffunction-sections -fdata-sections and -Wl,--gc-sections trick.
I'd like to have the garbage collection feature working for cogc code. However, it looks like this can't be because code using "static _COGMEM" won't compile. I'm pretty sure this is a bug in the compiler. I'm fully linking the cogc code when I compile. There's probably an unhandled case with _COGMEM and -fdata-sections.
To reproduce just compile any cogc file into an CMM/LMM application that has "static _COGMEM" vars using -fdata-sections.
I'd like to have the garbage collection feature working for cogc code. However, it looks like this can't be because code using "static _COGMEM" won't compile. I'm pretty sure this is a bug in the compiler. I'm fully linking the cogc code when I compile. There's probably an unhandled case with _COGMEM and -fdata-sections.
To reproduce just compile any cogc file into an CMM/LMM application that has "static _COGMEM" vars using -fdata-sections.
Comments
I compile all SimpleLibraries and link with them all, where all the SimpleLibraries are put into archives. One of the SimpleLibraries has a .cogc module. I compile this and link it fully and then archive it. I've noticed that even though it is unused it still shows up in all .elf images. There's nothing referencing it and I've already passed the -Wl,--gc-sections option. But, yet, it still ends up in the final executable. Does this have anything to do with a fix for .cog sections not being pulled out of a library unless they define a symbol different from the __load_start_***? The linker just seems to pull this in if it finds it in a library.
I can't just not compile and link against the library if it's unused because I have no way of determining what libraries are used. The linker should really not include the file if it's unused.