knurling-rs / flip-link

Adds zero-cost stack overflow protection to your embedded programs
Apache License 2.0
270 stars 6 forks source link

Comments in memory.x are not properly handled #83

Closed ejpcmac closed 10 months ago

ejpcmac commented 10 months ago

Problem description

Let’s say I have a memory.x containing:

MEMORY
{
    FLASH : ORIGIN = 0x00200000, LENGTH = 2M
    RAM : ORIGIN = 0x20000000, LENGTH = 32K /* Use only SRAM1. */
}

Trying to use flip-link 0.1.7 gives me the following error:

  = note: thread 'main' panicked at 'internal error: entered unreachable code', src/main.rs:341:18
          stack backtrace:
             0:     0x55a78cf0a0d0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h0f67236053551eca
             1:     0x55a78cf2f38f - core::fmt::write::h13a8faf14f1ccf50
             2:     0x55a78cf02f67 - std::io::Write::write_fmt::ha1e4f1bb6310f8b3
             3:     0x55a78cf09ed5 - std::sys_common::backtrace::print::hda0e459003c3497e
             4:     0x55a78cef0e81 - std::panicking::default_hook::{{closure}}::h9fb0f39f8a4b4896
             5:     0x55a78cef0b1f - std::panicking::default_hook::h74777d9c83f82eb3
             6:     0x55a78cef1329 - std::panicking::rust_panic_with_hook::h5a53706624030272
             7:     0x55a78cf0a371 - std::panicking::begin_panic_handler::{{closure}}::h3941e21c138a8c98
             8:     0x55a78cf0a1a6 - std::sys_common::backtrace::__rust_end_short_backtrace::h5d3e0e241a65e49e
             9:     0x55a78cef1052 - rust_begin_unwind
            10:     0x55a78ced1453 - core::panicking::panic_fmt::h396c35e980c19b34
            11:     0x55a78ced14e3 - core::panicking::panic::h130b83b9706be6f0
            12:     0x55a78ced5371 - flip_link::perform_addition::h0f363ddbf86b6093
            13:     0x55a78ced4842 - flip_link::main::h1ef3404106dd9ce7
            14:     0x55a78ced9fe3 - std::sys_common::backtrace::__rust_begin_short_backtrace::hd8d493c30b3f63da
            15:     0x55a78ced9ff9 - std::rt::lang_start::{{closure}}::had3ef76cc40faa10
            16:     0x55a78cee81b7 - std::rt::lang_start_internal::h7910e71d80e7bec3
            17:     0x55a78ced5445 - main
            18:     0x7f297e27efce - __libc_start_call_main
            19:     0x7f297e27f089 - __libc_start_main_impl
            20:     0x55a78ced1a35 - _start
            21:                0x0 - <unknown>

Removing the comment from the memory.x or rolling back to flip-link 0.1.6 makes the issue disappear.

Expected behaviour

flip-link should support comments in the linker script.

BriocheBerlin commented 10 months ago

Thanks for raising this, we'll look into it.