Skip to content

No support for variables in the linker script #115

Open
@Abestanis

Description

@Abestanis

I have a linker script that contains a variable, and the newest version v0.1.10 fails to parse the linker script because the evaluation logic added in #104 does not take variables into account.

Example linker script with a variable
_stack_guard_size = 0x100;
MEMORY {
    /** ... */
    STACK_GUARD : ORIGIN = 0x20000000, LENGTH = _stack_guard_size
    RAM         : ORIGIN = 0x20000000 + _stack_guard_size, LENGTH = 264K - _stack_guard_size
}
flip-link linker error
error: linking with `flip-link` failed: exit status: 101
  |
  [...]
    = note: thread 'main' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/flip-link-0.1.10/src/main.rs:353:13:
          Failed to parse expression "0x20000000 + _stack_guard_size" ("0x20000000 + _stack_guard_size"), got error VariableIdentifierNotFound("_stack_guard_size")
          stack backtrace:
             0: rust_begin_unwind
             1: core::panicking::panic_fmt
             2: flip_link::evaluate_expression
             3: flip_link::main
          note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I used that same linker script with old versions of flip-link and they never complained, but I guess variables were never supported so my RAM sizes must have always been wrong?

I'm not sure manually parsing the entire linker script is a good idea, but it would be possible to use a crate to do the parsing. I've found
ldscript-parser which has not received any activity within a year but seems to be very well tested.

I would be willing to provide a PR trying to replace evalexpr with ldscript-parser if you are on board with this approach.
Just checked and ldscript-parser only supports raw values in the origin and length fields, so we can't use it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions