Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4829

SDK • Pico SDK binary size?

$
0
0
Friends,

I have a very basic mqtt ping-pong program written in C/C++. I'm compiling it using mostly SDK CMake with MinSizeRel. The code is here: https://github.com/jaguilar/pico_experi ... lo_mqtt.cc

The size of my bin file for this simple program is 350kB. I have some questions. Here is the header of the .dis file printed by the SDK:

Code:

/home/jaguilar/projects/pico_experiments/build/src/hello_mqtt/hello_mqtt.elf:     file format elf32-littlearmSections:Idx Name          Size      VMA       LMA       File off  Algn  0 .boot2        00000100  10000000  10000000  00001000  2**0                  CONTENTS, ALLOC, LOAD, READONLY, CODE  1 .text         00019b28  10000100  10000100  00001100  2**4                  CONTENTS, ALLOC, LOAD, READONLY, CODE  2 .rodata       0003a07c  10019c28  10019c28  0001ac28  2**3                  CONTENTS, ALLOC, LOAD, READONLY, DATA  3 .ARM.extab    000000f0  10053ca4  10053ca4  00054ca4  2**2                  CONTENTS, ALLOC, LOAD, READONLY, DATA  4 .ARM.exidx    000001d0  10053d94  10053d94  00054d94  2**2                  CONTENTS, ALLOC, LOAD, READONLY, DATA  5 .binary_info  00000020  10053f64  10053f64  00054f64  2**2                  CONTENTS, ALLOC, LOAD, READONLY, DATA  6 .ram_vector_table 000000c0  20000000  20000000  00058000  2**2                  ALLOC  7 .data         000022ac  200000c0  10053f84  000550c0  2**4                  CONTENTS, ALLOC, LOAD, READONLY, CODE  8 .uninitialized_data 00000020  20002370  10056230  00057370  2**3                  ALLOC  9 .scratch_x    00000000  20040000  20040000  0005736c  2**0                  CONTENTS 10 .scratch_y    00000000  20041000  20041000  0005736c  2**0                  CONTENTS 11 .bss          00022430  20002390  20002390  00057390  2**3                  ALLOC 12 .heap         00000800  200247c0  200247c0  0005736c  2**2                  CONTENTS, READONLY 13 .stack1_dummy 00000800  20040000  20040000  00058000  2**2                  ALLOC 14 .stack_dummy  00000800  20041000  20041000  00057b80  2**5                  CONTENTS, READONLY 15 .ARM.attributes 00000028  00000000  00000000  00058380  2**0                  CONTENTS, READONLY 16 .comment      00000059  00000000  00000000  000583a8  2**0                  CONTENTS, READONLY 17 .debug_info   0004a178  00000000  00000000  00058401  2**0                  CONTENTS, READONLY, DEBUGGING, OCTETS 18 .debug_abbrev 000098fd  00000000  00000000  000a2579  2**0                  CONTENTS, READONLY, DEBUGGING, OCTETS 19 .debug_loclists 00015ee6  00000000  00000000  000abe76  2**0                  CONTENTS, READONLY, DEBUGGING, OCTETS 20 .debug_aranges 00001170  00000000  00000000  000c1d60  2**3                  CONTENTS, READONLY, DEBUGGING, OCTETS 21 .debug_rnglists 000034f5  00000000  00000000  000c2ed0  2**0                  CONTENTS, READONLY, DEBUGGING, OCTETS 22 .debug_line   0001335b  00000000  00000000  000c63c5  2**0                  CONTENTS, READONLY, DEBUGGING, OCTETS 23 .debug_str    0000c138  00000000  00000000  000d9720  2**0                  CONTENTS, READONLY, DEBUGGING, OCTETS 24 .debug_frame  00002e70  00000000  00000000  000e5858  2**2                  CONTENTS, READONLY, DEBUGGING, OCTETS 25 .debug_line_str 000000a3  00000000  00000000  000e86c8  2**0                  CONTENTS, READONLY, DEBUGGING, OCTETS 26 .debug_loc    00003faa  00000000  00000000  000e876b  2**0                  CONTENTS, READONLY, DEBUGGING, OCTETS 27 .debug_ranges 000001c8  00000000  00000000  000ec715  2**0                  CONTENTS, READONLY, DEBUGGING, OCTETS
Question 1: Why, if I'm building with MinSizeRel, is there so much .debug stuff in the binary? Is it possible to reduce the amount of this stuff in my final release?

Question 2: For a program with lwip (DNS, MDNS, TCP, MQTT), FreeRTOS, the cyw43 driver, and my little program, is 350kB an expected amount of code?

Question 3: What's in .rodata? I did objdump -s -j .rodata build/src/hello_mqtt/hello_mqtt.elf and saw some stuff that makes sense to me:

Code:

 10019cf8 00657272 6f722063 6f6e6e65 6374696e  .error connectin 10019d08 6720746f 206d7174 743a2025 640a0077  g to mqtt: %d..w 10019d18 72697465 72002f70 696e6700 6572726f  riter./ping.erro 10019d28 72207375 62736372 6962696e 6720746f  r subscribing to 10019d38 206d7174 743a2025 730a0062 61736963   mqtt: %s..basic 10019d48 5f737472 696e673a 3a5f4d5f 7265706c  _string::_M_repl 10019d58 61636500 6d6f7265 20746861 6e207468  ace.more than th 10019d68 65206578 70656374 6564206e 756d6265  e expected numbe
But also a bunch of space that doesn't seem to have anything identifiable in it:

Code:

 1001d9a8 000a3268 354805f0 81d9a36c 21680093  ..2h5H.....l!h.. 1001d9b8 636c2246 0193a368 31480293 e3680027  cl"F...h1H...h.' 1001d9c8 0393e36c 05f072d9 e36904f1 10010093  ...l..r..i...... 1001d9d8 236a2c48 0193636a 4fea9a0a 0293a36a  #j,H..cjO......j 1001d9e8 b9460393 0ec905f0 61d9a36b 04f12c01  .F......a..k..,. 1001d9f8 0093e36b 24480193 236cb846 02930ec9  ...k$H..#l.F.... 1001da08 05f054d9 eb682148 009395e8 0e0005f0  ..T..h!H........ 1001da18 4dd9eb69 05f11001 00931d48 0ec905f0  M..i.......H.... 1001da28 45d918e0 7a59d307 0fd5ff2a 0dd9194b  E...zY.....*...K
How do I tell what's in .rodata and whether it's needed?

Question 4: Why does my program contain unwind functions even though my compile commands are disabling unwind and exceptions?

Code:

10017a40 <_ZL21base_of_encoded_valuehP15_Unwind_Context>:10017a40:0002      movsr2, r010017a42:b510      push{r4, lr}10017a44:0008      movsr0, r110017a46:2aff      cmpr2, #255@ 0xff10017a48:d010      beq.n10017a6c <_ZL21base_of_encoded_valuehP15_Unwind_Context+0x2c>10017a4a:2370      movsr3, #112@ 0x7010017a4c:4013      andsr3, r2
Here is my compile command for my only cc file:

Code:

/usr/bin/arm-none-eabi-g++ -DCFG_TUSB_MCU=OPT_MCU_RP2040 \ -DCFG_TUSB_OS=OPT_OS_PICO -DCYW43_LWIP=1 -DFREE_RTOS_KERNEL_SMP=1\  -DLIB_FREERTOS_KERNEL=1 -DLIB_PICO_ASYNC_CONTEXT_FREERTOS=1 \  -DLIB_PICO_BIT_OPS=1 -DLIB_PICO_BIT_OPS_PICO=1 -DLIB_PICO_CYW43_ARCH=1 \  -DLIB_PICO_DIVIDER=1 -DLIB_PICO_DIVIDER_HARDWARE=1 -DLIB_PICO_DOUBLE=1 \  -DLIB_PICO_DOUBLE_PICO=1 -DLIB_PICO_FIX_RP2040_USB_DEVICE_ENUMERATION=1 \  -DLIB_PICO_FLOAT=1 -DLIB_PICO_FLOAT_PICO=1 -DLIB_PICO_INT64_OPS=1 \  -DLIB_PICO_INT64_OPS_PICO=1 -DLIB_PICO_MALLOC=1 -DLIB_PICO_MEM_OPS=1 \  -DLIB_PICO_MEM_OPS_PICO=1 -DLIB_PICO_MULTICORE=1 -DLIB_PICO_PLATFORM=1 \  -DLIB_PICO_PRINTF=1 -DLIB_PICO_PRINTF_PICO=1 -DLIB_PICO_RAND=1 \  -DLIB_PICO_RUNTIME=1 -DLIB_PICO_STANDARD_LINK=1 -DLIB_PICO_STDIO=1\   -DLIB_PICO_STDIO_USB=1 -DLIB_PICO_STDLIB=1 -DLIB_PICO_SYNC=1 \   -DLIB_PICO_SYNC_CRITICAL_SECTION=1 -DLIB_PICO_SYNC_MUTEX=1 \   -DLIB_PICO_SYNC_SEM=1 -DLIB_PICO_TIME=1 -DLIB_PICO_UNIQUE_ID=1 \   -DLIB_PICO_UTIL=1 -DLWIP_PROVIDE_ERRNO=1 -DPICO_BOARD=\\\"pico_w\\\" \   -DPICO_BUILD=1 -DPICO_CMAKE_BUILD_TYPE=\\\"MinSizeRel\\\" -DPICO_CONFIG_RTOS_ADAPTER_HEADER=/home/jaguilar/projects/pico_experiments/lib/FreeRTOS/FreeRTOS/Source/portable/ThirdParty/GCC/RP2040/include/freertos_sdk_config.h \   -DPICO_COPY_TO_RAM=0 -DPICO_CXX_ENABLE_EXCEPTIONS=0 -DPICO_CYW43_ARCH_FREERTOS=1 \   -DPICO_NO_FLASH=0 -DPICO_NO_HARDWARE=0 -DPICO_ON_DEVICE=1 \   -DPICO_RP2040_USB_DEVICE_UFRAME_FIX=1 -DPICO_TARGET_NAME=\\\"hello_mqtt\\\" \   -DPICO_USE_BLOCKED_RAM=0 SNIP_INCLUDE_DIRECTORIES -mcpu=cortex-m0plus \   -mthumb -Os -DNDEBUG -Wall -Wno-format -Wno-unused-function -fdata-sections \   -ffunction-sections -DMQTT_HOST=\\\"rpi5.local\\\" -DMQTT_USER=\\\"jags_mqtt\\\" \   -DMQTT_PASSWORD=\\\"SECRET\\\" -fno-exceptions -fno-unwind-tables -fno-rtti \   -fno-use-cxa-atexit -std=gnu++20 -o CMakeFiles/hello_mqtt.dir/hello_mqtt.cc.obj\    -c /home/jaguilar/projects/pico_experiments/src/hello_mqtt/hello_mqtt.cc
Note -fno-exceptions and -fno-unwind-tables. Is there more that needs to be done to disable this code? It seems to be about 1/6th of the total code as printed in the .dis file, so it seems like it would be nice to get it out of the result.

Thank you in advance for sharing your expertise on these issues!

Statistics: Posted by jags84 — Fri Mar 29, 2024 2:02 pm



Viewing all articles
Browse latest Browse all 4829

Trending Articles