1. Please try to post your questions in the correct sub-forum [ in the future].
Edit: Continue using this sub-forum for now with this question; the people on this site do NOT like multiple threads for same question.
2. Please read and follow this site rules http://forums.codeblocks.org/index.php/topic,9996.0.html (http://forums.codeblocks.org/index.php/topic,9996.0.html)
If you know, the Compiler Option you need to add and needs help on how to add it; that is a valid question for this site.
If you have no idea what the compiler option is; that is NOT a valid question for this site.
Edit2: My guess is this line is wrong in your project file.
-Wl,-Map=$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).map,--cref
You might try this line instead.
-Wl,-Map=$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).map
But, I do NOT use your Compiler.
Tim S.
Try these two options:
-ffunction-sections
-fdata-sections
Read here for more info: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
If your compiler is recent enough you can try to use lto or whole-program optimizations.
Search the internet how to enable it.
You can search the arduino project for details why options to use to get minimal code.
well according your example project, there is only a main function. I don't know what the compiler should optimize there...
But still size of the unused function is added to the final object file.
From what do you conclude that?
[EDIT:] NOTE: The linker removes the excessive function, not the compiler. So they are still present in the object file!!! But not in the binary file...
Device: atmega328p
Program: 182 bytes (0.6% Full)
(.text + .data + .bootloader)
Data: 2 bytes (0.1% Full)
(.data + .bss + .noinit)
128 Bytes are not that much...
Also why .lss file is not getting generated any idea?
Because according your build log, you don't ask the compiler to generate a ls file:
add this line to post build steps:
cmd /c "avr-objdump -h -S $(TARGET_OUTPUT_FILE) > $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).lss"
If you work on linux you have to modify it for your environment...
greetings
Thanks for good response.
well according your example project, there is only a main function. I don't know what the compiler should optimize there...
Sorry that I did not give the complete code. I gave only project folder with main just to give the project settings to you people. Below is the main code (compilable, but does not do anything). Even if f1() is commented or uncommented, the final size remains the same except 4 byte variation for function call itself (182 or 186 bytes) .
The linker removes the excessive function, not the compiler. So they are still present in the object file!!! But not in the binary file.
Sorry, could you pl. elaborate this point? I am not clear. Did you mean to say the size 182 bytes displayed is not that of binary file to be written to the controller? When I burn the file, the same 182 byte is displayed as the size written to flash.
Because according your build log, you don't ask the compiler to generate a ls file
I added avr-objdump -h -S $(TARGET_OUTPUT_FILE) > $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).ls.
But the listing is getting displayed in build log itself (Causing inconvenience because log will be huge) and no .lss file is getting created. I see a warning message at the end saying "Warning: '>' is not an ordinary file". Also note that while creating new project, I had opted for creating list file. But CB is not generating automatically.
#include <avr/io.h>
#include <util/delay.h>
uint8_t a =12;
void f1 (void);
int main(void)
{
while (1)
{
PORTB=a;
//f1();
}
}
void f1 (void)
{
DDRD=0;
DDRC=0xff;
DDRD=0xff;
uint8_t m=0x50;
if(m>12)
{
PORTD=12;
PORTC=16;
}
}
Sorry that I did not give the complete code. I gave only project folder with main just to give the project settings to you people. Below is the main code (compilable, but does not do anything). Even if f1() is commented or uncommented, the final size remains the same except 4 byte variation for function call itself (182 or 186 bytes) .
yea, the output of avr-size is the amount of bytes that could be written on the controller
I added avr-objdump -h -S $(TARGET_OUTPUT_FILE) > $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).ls.But the listing is getting displayed in build log itself (Causing inconvenience because log will be huge) and no .lss file is getting created. I see a warning message at the end saying "Warning: '>' is not an ordinary file". Also note that while creating new project, I had opted for creating list file. But CB is not generating automatically.
i think the problem with this is, that the redirect/stream operator ">" does not work in the pre/post build steps in codeblocks. You have to use the line
cmd /c "avr-objdump -h -S $(TARGET_OUTPUT_FILE) > $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).lss"
or
xterm -e "avr-objdump -h -S $(TARGET_OUTPUT_FILE) > $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).lss"
on linux (i did not test this, and obviously you need xterm installed)
i think you need to add
-ffunction-sections -fdata-sections
to the compiler settings
and
or
to the linker settings. I am not quite sure if codeblocks calls the linker directly
the first command:
The options -ffunction-sections -fdata-sections are for linker right?
They are only compiler options. It tells the compiler to put every function in a separate section, this means that if the linker finds that a section is not used it can remove it.
So the functions are still present in the object file
then you call the linker with the second command and the linker will garbage collect your unused functions...
greetings