Reduce size of C++ binaries in Stand-alone project

Sysprogs forums Forums VisualGDB Reduce size of C++ binaries in Stand-alone project

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #11399
    janulo
    Participant

    Hi everyone!

    I’m working on project on STM32 using VisualGDB. Our project was converted to Stand-alone year ago. I would like to reduce size of output binaries using “Reduce size of C++ binaries” feature described here at the end of page :

    The solution in this case would be to replace __cxa_pure_virtual() with something more compact that will for example just trigger a breakpoint. The “Reduce size of C++ binaries” option does exactly that…

    Unfortunately, I didn’t find any option like this in our project settings. Is there any way to do such a size reduction in case of Stand-alone project?

    Our output from Embedded Memory Explorer looks similar to output from tutorial mentioned above.

     

    #11400
    support
    Keymaster

    Hi,

    Yes, please try adding “compactcpp” to the list of library names in VisualGDB Project Properties. This should be equivalent to checking the “reduce size of C++ binaries” checkbox.

    • This reply was modified 7 years, 5 months ago by support.
    #11489
    janulo
    Participant

    Hi,

     

    thanks for your response. I tried your recommendation, but no change in flash memory used. We are not using any pure virtual methods, but still a lot of classes and std::arrays, it may be related?

    I will try to insert screenshot from memory explorer:

     

    memory explorer

    • This reply was modified 7 years, 5 months ago by janulo. Reason: screenshot edit
    #11496
    support
    Keymaster

    Hi,

    If you are using a 3rd-party toolchain, it may be configured slightly differently and the compactcpp library won’t override the necessary symbols. Please try switching to our ARM toolchain.

    #11497
    janulo
    Participant

    Hi,

    If I’m not wrong, we are already using arm toolchain: VisualGDB properties – Makefile settings – Toolchain: ARM in c:\SysGCC\arm-eabi.

    During compilation, I can see in Output window instructions starting with following (so this should not be the case of 3rd-party toolchain):

    c:\SysGCC\arm-eabi/bin/arm-eabi-gcc.exe
    c:\SysGCC\arm-eabi/bin/arm-eabi-g++.exe
    c:\SysGCC\arm-eabi/bin/arm-eabi-objcopy.exe
    
    
    
    #11499
    support
    Keymaster

    Hi,

    That does indeed look like our toolchain. Please try enabling the map file generation via Linker Properties and ensure that the _ZSt9terminatev (std::terminate) function is coming from the libcompactcpp.a:

     .text          0x08000188       0xa4 e:/sysgcc/arm-eabi/bin/../lib/gcc/arm-eabi/6.2.0/thumb/cortex_m4/crtbegin.o
     .text          0x0800022c        0xc e:/sysgcc/arm-eabi/bin/../lib/gcc/arm-eabi/6.2.0/../../../../arm-eabi/lib/thumb/cortex_m4\libcompactcpp.a(libcompactcpp.o)
                    0x0800022c                __cxa_pure_virtual
                    0x08000232                _ZSt9terminatev
    #11530
    janulo
    Participant

    Hi,

     

    It looks like this _ZSt9terminatev is comming from libstdc++.a:

     .text._ZN10__cxxabiv111__terminateEPFvvE
     0x0804bfc0 0x28 c:/sysgcc/arm-eabi/bin/../lib/gcc/arm-eabi/6.2.0/../../../../arm-eabi/lib/thumb/fpu/cortex_m4\libstdc++.a(eh_terminate.o)
     0x0804bfc0 _ZN10__cxxabiv111__terminateEPFvvE
     .text._ZSt9terminatev
     0x0804bfe8 0x14 c:/sysgcc/arm-eabi/bin/../lib/gcc/arm-eabi/6.2.0/../../../../arm-eabi/lib/thumb/fpu/cortex_m4\libstdc++.a(eh_terminate.o)
     0x0804bfe8 _ZSt9terminatev
    #11532
    support
    Keymaster

    Hi,

    OK, this looks like the libcompactcpp.a is actually not being compiled in. Please check the verbose link log (if you are using MSBuild, simply check the .link.rsp file) for the linker command line and ensure it contains the “-lcompactcpp” argument. If you are not sure, please post the linker command line here and we will help you resolve this.

    #11537
    janulo
    Participant

    Hi, thanks for trying to help me 🙂

    I’m not using MSBuild, but when I check output window, the almost last line is quite long (I skipped the .o file and left only some to make this shorter, my comments are inside { }. Also I put this on multiple lines to make it more readable ):

    c:\SysGCC\arm-eabi/bin/arm-eabi-g++.exe -o Release/BCR-G2_demo.elf -Wl,-gc-sections -Wl,-q -Wl,  -TSTM32L471VG_flash_wCRC.lds  -mcpu=cortex-m4 -mthumb -mfloat-abi=hard   -Wl,-Map=Release/BCR-G2_demo.map -Wl,--start-group 
    Release/system_stm32l4xx.o Release/stm32l4xx_hal.o {lot of other .o files}
    -lcompactcpp  
    {local path}STemWin528_CM4_GCC.a  -Wl,--end-group

     

    • This reply was modified 7 years, 5 months ago by janulo.
    • This reply was modified 7 years, 5 months ago by janulo.
    #11540
    janulo
    Participant

    I’m fighting with text editor 🙂 Using <> for my comments was not good idea, so one more try with { }.

    c:\SysGCC\arm-eabi/bin/arm-eabi-g++.exe -o Release/BCR-G2_demo.elf -Wl,-gc-sections -Wl,-q -Wl,  -TSTM32L471VG_flash_wCRC.lds  -mcpu=cortex-m4 -mthumb -mfloat-abi=hard   -Wl,-Map=Release/BCR-G2_demo.map -Wl,--start-group Release/system_stm32l4xx.o Release/stm32l4xx_hal.o
    {skipped .o files here}
    -lcompactcpp  {local path}STemWin528_CM4_GCC.a  -Wl,--end-group

     

    #11548
    support
    Keymaster

    Hi,

    Strange, it looks like the libcompactcpp library is specified in the command line, but is not linked.

    In order to troubleshoot this, please try creating a new project from scratch with the following code:

    #include <exception>
    
    int main(void)
    {
        std::terminate();
    }

    Then link it with libcompactcpp. If the map file shows that the _ZSt9terminatev function is taken from libcompactcpp.a, please try understanding the differences between your main project and the test project. If not, please try re-downloading our latest toolchain.

    If nothing helps, please add “-Wl,-verbose” to LDFLAGS and post the following:

    • The full Map file
    • The full verbose link log

    This should help understand why libcompactcpp.a is not included.

    #11583
    janulo
    Participant

    Hi,

    I’m sorry for my delayed response.

    I’ve tried this simple project and _ZSt9terminatev function is linked correctly from libcompactcpp.a. Unfortunately, priorities on project have changed and I have to postpone this downsizing task. I’ll compare main project with the test project and I will come with results, or with full Map and verbose log, ASAP. Thanks for understanding.

    Jan

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.