GCC -gc sections and character dependency search

I am trying to reduce the size of the elf executable. I am compiling with -ffunction-sections -fdata-sectionsand linking to -gc-sections, but it seems that some of the characters that I think are not used are not discarded.

Is there any command in the GNU toolchain that I can run to find out which characters are used and where?

  • Tool Chain: GNU arm-none-eabi
  • Platform: Cortex-M4
  • Language: C ++

Here are my typical build flags:

Compilation: arm-none-eabi-g++.exe -Wall -O3 -mthumb -std=c++11 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -fsingle-precision-constant -ffunction-sections -fdata-sections

Link: arm-none-eabi-g++.exe -static -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Wl,-gc-sections -Wl,-T"LinkerScript.ld

Thanks for the help.

+3
source share
3 answers

I could not find a command that showed character dependencies. However, I was able to get the information I needed using the following technique:

  • /DISCARD/ script. , , . : <symbol0>' referenced in section '<symbol1>' of <lib0.a file path>(<object0 file path>): defined in discarded section '<symbol0>' of <lib1.a file path>(object1 file path>)
  • /DISCARD/, .

- , . , , .

: - ++, . GNU -fvtable-gc, , . .

+2

:

-Wl,-Map=output.map -Wl,--cref

+2

You can try the linker option -Wl,--trace-symbol=<symbol_name>. It will be displayed at the output where the symbol is indicated and where the symbol is used.

+2
source

All Articles