Question

I'm using avr-gcc for an atmega-328p micro controller. The code is built with:

avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000   -c -o heap.o heap.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000   -c -o kerneltimer.o kerneltimer.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000   -c -o message.o message.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000   -c -o driver.o driver.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000   -c -o watchdog.o watchdog.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000   -c -o mutex.o mutex.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000   -c -o semaphore.o semaphore.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000   -c -o kernelswi.o kernelswi.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000   -c -o task.o task.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000   -c -o kernelwdt.o kernelwdt.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000   -c -o myfirstapp.o myfirstapp.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000   -c -o taskport.o taskport.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000   -c -o timer.o timer.c

And linked with:

avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -Wl,-Map,myfirstapp.map -L/usr/avr/lib -Os -o myfirstapp.elf heap.o kerneltimer.o message.o driver.o watchdog.o mutex.o semaphore.o kernelswi.o task.o kernelwdt.o myfirstapp.o taskport.o timer.o 

Now- as it turns out for this particular program, nothing in heap.o is used. Yet the code is included in the final binary. Is there anyway I can get the linker to atleast elide complete .o files if nothing in them are used anywhere ?

And while this is just a fun project for learning purposes, I'd rather learn if the tools can figure this out than tracking down such things myself.

Was it helpful?

Solution

Yes, this is possible. Passing --gc-sections to the linker will direct it to omit sections which are not referenced. Additionally, passing the -ffunction-sections and -fdata-sections flags to the compiler will direct it to generate a section for each function and variable, allowing these to be left out on an individual basis, rather than just at a file level.

OTHER TIPS

Adding --gc-sections to the linker didn't help for me. However adding

-Wl,-gc-sections did work

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top