tock / elf2tab

Tool to create Tock Application Bundles from ELF files.
MIT License
15 stars 33 forks source link

Increase the max padding size between sections to 1024. Added a warni… #55

Closed bincsh closed 2 years ago

bincsh commented 2 years ago

…ng message if elf2tab skips section padding due to larger gaps.

bradjc commented 2 years ago

This is an unfortunate problem, but this fix is probably the best option in the short term. This should work if the constant is 1024, correct? I think we should choose the smallest number that works.

The intent of this check is to avoid skipping a section if the sections are out of order in the ELF. If we set this constant too large then I think it is possible (but maybe not likely? I'm not sure) that we could end up with out-of-order sections.

The real fix is to redo the ELF parsing logic entirely.

bincsh commented 2 years ago

I don't know why elf2tab needs to do to actual get the real fix. I have more questions than answers. For instance, why it's not relying on program header's segment to extract memory layout - the problem here is 1 to 1 address mapping to the flash. I don't know other cases that led the oddly per section guess/assumptions to manually stitch into memory.

The only thing I can fix now is this arbitrary 100 bytes. My suggestion is that we fix this for now (I'll fix it to 1024 bytes if you say it's more appropriate). What do you think?

bradjc commented 2 years ago

The "actual" fix would be to scan the ELF segments, and include sections based on their inclusion in appropriate segments.

Right now, we are just iterating sections and essentially using heuristics to include the sections that we want. This worked reasonably well when had a single toolchain and a single architecture, but has gotten progressively more precarious with the increase in targets, host platforms, and toolchains over time.

bincsh commented 2 years ago

I agree with you with the actual fix. Can we merge this temporary fix? I think the warning is the most beneficial part, because it will help people to identify why their apps are not working easier.

I'll sync up with you offline to the actual fix.

bradjc commented 2 years ago

Yes, with 1024 as the number.

bincsh commented 2 years ago

Sorry about that. Ran cargo fmt --check locally and it passed now.

bradjc commented 2 years ago

We need to re-think the warning. When building RISC-V apps:

make RISCV=1
  CC        ../../libtock/adc.c
  CC        ../../libtock/alarm_timer.c
  CC        ../../libtock/ambient_light.c
  CC        ../../libtock/app_state.c
  CC        ../../libtock/buzzer.c
  CC        ../../libtock/console.c
  CC        ../../libtock/gpio_async.c
  CC        ../../libtock/humidity.c
  CC        ../../libtock/i2c_master.c
  CC        ../../libtock/i2c_master_slave.c
  CC        ../../libtock/ieee802154.c
  CC        ../../libtock/l3gd20.c
  CC        ../../libtock/lps25hb.c
  CC        ../../libtock/lsm303dlhc.c
  CC        ../../libtock/ltc294x.c
  CC        ../../libtock/max17205.c
  CC        ../../libtock/pca9544a.c
  CC        ../../libtock/proximity.c
  CC        ../../libtock/rng.c
  CC        ../../libtock/screen.c
  CC        ../../libtock/sdcard.c
  CC        ../../libtock/sound_pressure.c
  CC        ../../libtock/spi.c
  CC        ../../libtock/spi_peripheral.c
  CC        ../../libtock/temperature.c
  CC        ../../libtock/text_screen.c
  CC        ../../libtock/tock.c
  CC        ../../libtock/touch.c
  CC        ../../libtock/tsl2561.c
  CC        ../../libtock/udp.c
  CC        ../../libtock/unit_test.c
  CC        ../../libtock/usb.c
  AR        ../../libtock/build/rv32imac/libtock.a
  CC        ../../libtock/adc.c
  CC        ../../libtock/alarm_timer.c
  CC        ../../libtock/ambient_light.c
  CC        ../../libtock/app_state.c
  CC        ../../libtock/buzzer.c
  CC        ../../libtock/console.c
  CC        ../../libtock/gpio_async.c
  CC        ../../libtock/humidity.c
  CC        ../../libtock/i2c_master.c
  CC        ../../libtock/i2c_master_slave.c
  CC        ../../libtock/ieee802154.c
  CC        ../../libtock/l3gd20.c
  CC        ../../libtock/lps25hb.c
  CC        ../../libtock/lsm303dlhc.c
  CC        ../../libtock/ltc294x.c
  CC        ../../libtock/max17205.c
  CC        ../../libtock/pca9544a.c
  CC        ../../libtock/proximity.c
  CC        ../../libtock/rng.c
  CC        ../../libtock/screen.c
  CC        ../../libtock/sdcard.c
  CC        ../../libtock/sound_pressure.c
  CC        ../../libtock/spi.c
  CC        ../../libtock/spi_peripheral.c
  CC        ../../libtock/temperature.c
  CC        ../../libtock/text_screen.c
  CC        ../../libtock/tock.c
  CC        ../../libtock/touch.c
  CC        ../../libtock/tsl2561.c
  CC        ../../libtock/udp.c
  CC        ../../libtock/unit_test.c
  CC        ../../libtock/usb.c
  AR        ../../libtock/build/rv32imc/libtock.a
  CC        main.c
  LD        build/rv32imac/rv32imac.0x20040060.0x80002800.elf
  LD        build/rv32imac/rv32imac.0x403B0060.0x3FCC0000.elf
  CC        main.c
  LD        build/rv32imc/rv32imc.0x41000060.0x42008000.elf
  LD        build/rv32imc/rv32imc.0x00080060.0x40008000.elf
  LD        build/rv32imc/rv32imc.0x20030080.0x10005000.elf
  LD        build/rv32imc/rv32imc.0x20030880.0x10008000.elf
  LD        build/rv32imc/rv32imc.0x20032080.0x10008000.elf
  LD        build/rv32imc/rv32imc.0x20034080.0x10008000.elf
  LD        build/rv32imac/rv32imac.0x40430060.0x80004000.elf
  LD        build/rv32imac/rv32imac.0x40440060.0x80007000.elf
 E2T        build/blink.tab
Warning! Padding to section .data is too large (1610361080 bytes).
Warning! Padding to section .data is too large (16810184 bytes).
Warning! Padding to section .data is too large (1073250504 bytes).
Warning! Padding to section .data is too large (1069367544 bytes).
Warning! Padding to section .data is too large (1069314296 bytes).
Application size report for arch family cortex-m:
   text    data     bss     dec     hex filename
   1664     196    2400    4260    10a4 build/cortex-m0/cortex-m0.elf
   1456     196    2400    4052     fd4 build/cortex-m3/cortex-m3.elf
   1456     196    2400    4052     fd4 build/cortex-m4/cortex-m4.elf
   1456     196    2400    4052     fd4 build/cortex-m7/cortex-m7.elf
   6032     784    9600   16416    4020 (TOTALS)
Application size report for arch family rv32i:
   text    data     bss     dec     hex filename
   1704     108    2404    4216    1078 build/rv32imac/rv32imac.0x20040060.0x80002800.elf
   1704     108    2404    4216    1078 build/rv32imac/rv32imac.0x403B0060.0x3FCC0000.elf
   1752     108    2404    4264    10a8 build/rv32imc/rv32imc.0x41000060.0x42008000.elf
   1752     108    2404    4264    10a8 build/rv32imc/rv32imc.0x00080060.0x40008000.elf
   1752     108    2404    4264    10a8 build/rv32imc/rv32imc.0x20030080.0x10005000.elf
   1752     108    2404    4264    10a8 build/rv32imc/rv32imc.0x20030880.0x10008000.elf
   1752     108    2404    4264    10a8 build/rv32imc/rv32imc.0x20032080.0x10008000.elf
   1752     108    2404    4264    10a8 build/rv32imc/rv32imc.0x20034080.0x10008000.elf
   1704     108    2404    4216    1078 build/rv32imac/rv32imac.0x40430060.0x80004000.elf
   1704     108    2404    4216    1078 build/rv32imac/rv32imac.0x40440060.0x80007000.elf
  17328    1080   24040   42448    a5d0 (TOTALS)

Those warnings are not particularly helpful.