Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
How to exclude unused functions
joneewheelock:
I am using Code::Blocks with avr8-gnu-toolchain. Everything is smooth except that code size is not optimized even after I opted for optimize size. I am not an expert. So in my final object file how to exclude the functions that are not called.
Secondly, I opted for generate list file. But CB is not generating that. Attached is the work space template.
stahta01:
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
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.
--- Code: ----Wl,-Map=$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).map,--cref
--- End code ---
You might try this line instead.
--- Code: ----Wl,-Map=$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).map
--- End code ---
But, I do NOT use your Compiler.
Tim S.
oBFusCATed:
Try these two options:
--- Code: ----ffunction-sections
-fdata-sections
--- End code ---
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.
joneewheelock:
The options -ffunction-sections -fdata-sections are for linker right? I tried for both compiler and linker. But still size of the unused function is added to the final object file.
Also why .lss file is not getting generated any idea? I am new to CB so need some help to set this up. My log is given below.
avr-gcc.exe -Os -Wextra -Wall -mmcu=atmega328p -std=gnu99 -fshort-enums -ffunction-sections -fdata-sections -DF_CPU=16000000UL -g -Os -Wmain -Wextra -Wall -c main.c -o Debug\main.o
avr-g++.exe -o Debug\AVR_Project.elf Debug\main.o -mmcu=atmega328p -Wl,-Map=Debug\AVR_Project.map -ffunction-sections -fdata-sections
Output file is Debug\AVR_Project.elf with size 7.41 KB
Running project post-build steps
avr-objcopy -O ihex -j .text -j .data Debug\AVR_Project.elf Debug\AVR_Project.elf.hex
avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex Debug\AVR_Project.elf Debug\AVR_Project.elf.eep.hex
avr-size --mcu=atmega328p --format=avr Debug\AVR_Project.elf
AVR Memory Usage
----------------
Device: atmega328p
Program: 182 bytes (0.6% Full)
(.text + .data + .bootloader)
Data: 2 bytes (0.1% Full)
(.data + .bss + .noinit)
BlueHazzard:
well according your example project, there is only a main function. I don't know what the compiler should optimize there...
--- Quote ---But still size of the unused function is added to the final object file.
--- End quote ---
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...
--- Quote ---Device: atmega328p
Program: 182 bytes (0.6% Full)
(.text + .data + .bootloader)
Data: 2 bytes (0.1% Full)
(.data + .bss + .noinit)
--- End quote ---
128 Bytes are not that much...
--- Quote ---Also why .lss file is not getting generated any idea?
--- End quote ---
Because according your build log, you don't ask the compiler to generate a ls file:
add this line to post build steps:
--- Code: ---cmd /c "avr-objdump -h -S $(TARGET_OUTPUT_FILE) > $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).lss"
--- End code ---
If you work on linux you have to modify it for your environment...
greetings
Navigation
[0] Message Index
[#] Next page
Go to full version