0

I'm trying to generate a static library from a compiled ELF file. Previously, I've been able to generate the library by compiling my source code to object files, then passing those objects to avr-ar to successfully create my library. In order to reduce code space of the project, I've switched over to using link-time optimisations so save ~1.5 kB of space - however, in order to do so I end up passing all my source and header files to avr-gcc in one invocation and it spits out a .elf file.

I can't seem to get the -flto option working with the linker (I'm using a custom linker script) and compiler driver, otherwise I'd have the object files I need.

Is it possible to take this generated .elf and push it through ar to generate a library?

Problem Context:

Memory layout This is related to this problem. I've written the shared libraries and bootloader section, and am using this linker script to set out my flash space. Here's the Makefile that drives all this - it's very hacked together.

Ideally, what I'd like to happen is to be able to compile my src/ director to separate object files in obj/, all with link time optimisation enabled to cut down on code space as much as possible but still leaving unused functions in the output (the shared library that is stored in flash is not fully utilised by the bootloader application, but may be linked against by the loaded applications). I'd then like to be able link those objects together to create a .elf and libbootloader.a. The elf is then used to generate a binary to flash to my AVR and the bootloader library is referenced when building user applications that refer to the stored library in flash space already. (Perhaps I want to just link against a list of symbols referencing the shared library section?)

Community
  • 1
  • 1
lberezy
  • 450
  • 5
  • 19
  • Your question is unclear, you don't show any command. Notice that LTO works by *compiling and linking* with `CC=gcc -fto -Os` -you need to pass the flags *both* when compiling and when linking... – Basile Starynkevitch Oct 19 '15 at 04:43
  • Could you, umm, possibly post your linker script compiler driver? And the gcc/ld commands you're using? – Craig Estey Oct 19 '15 at 10:41
  • I've added some more context to the problem. @BasileStarynkevitch, do you mean `-flto`? I'm aware of how it's meant to be used (compile each object file with `-flto -Os` and then pass the same command to the linker, but I recall not being able to get it working and becoming frustrated. – lberezy Oct 19 '15 at 11:13
  • Yes I meant `make CC='gcc -flto -Os'` – Basile Starynkevitch Oct 19 '15 at 11:17

0 Answers0