Menu

#2646 __at can't place some data at a specific location amidst some code

open
nobody
None
other
7
2018-12-05
2017-09-01
No

I haven't been using the keyword __at much.
But now I have a case where I want code to be placed in the 0x0000 to
0x9fff range.

However, at the specific location 0x1ff0 I want 16 specific header
bytes. The linker should just put the code around the header (which
might require leaving a few bytes unused), but it doesn't work for me so
far.

I tried

const struct header __at(0x1ff0) header = ...;

but the linker creates an overlap: The header gets put into the binary
at the correct location with the correct data. But that means the data
ends up in the middle of a function.

Probably the linker is not capable of doing what I wanted to achieve here anyway, but I'd expect to at least see an error message.

I consider this a bug, since it is different from the behaviour documented in the manual for __at with initialized variables. I'm giving it above-average priority, since bad code is generated silently.

Philipp

P.S.: I was using current SDCC and the z80 backend.

Discussion

  • Philipp Klaus Krause

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -21,4 +21,6 @@
     I consider this a bug, since it is different from the behaviour documented in the manual for __at with initialized variables. I'm giving it above-average priority, since bad code is generated silently.
    
     Philipp
    +
    +P.S.: I was using current SDCC and the z80 backend.
     ~~~~
    
     
  • Maarten Brock

    Maarten Brock - 2018-12-05
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,5 +1,4 @@
    -~~~~
    -I haven't been using the keyword __at much.
    +I haven't been using the keyword \_\_at much.
     But now I have a case where I want code to be placed in the 0x0000 to
     0x9fff range.
    
    @@ -10,7 +9,7 @@
    
     I tried
    
    -const struct header __at(0x1ff0) header = ...;
    +const struct header \_\_at(0x1ff0) header = ...;
    
     but the linker creates an overlap: The header gets put into the binary
     at the correct location with the correct data. But that means the data
    @@ -18,9 +17,8 @@
    
     Probably the linker is not capable of doing what I wanted to achieve here anyway, but I'd expect to at least see an error message.
    
    -I consider this a bug, since it is different from the behaviour documented in the manual for __at with initialized variables. I'm giving it above-average priority, since bad code is generated silently.
    +I consider this a bug, since it is different from the behaviour documented in the manual for \_\_at with initialized variables. I'm giving it above-average priority, since bad code is generated silently.
    
     Philipp
    
     P.S.: I was using current SDCC and the z80 backend.
    -~~~~
    
     
  • Maarten Brock

    Maarten Brock - 2018-12-05

    Indeed the z80 linker does not support this. In a distant past I modified the mcs51 linker to sort absolute segments to the front and place them first, then place the rest in the remaining spaces. I also documented this, but maybe not marked mcs51 specific. When Borut merged the linker sources, he decided to use macros to separate behaviour for different targets instead of merging the enhancements. I'll see if I can fix this.

     

Log in to post a comment.

Monday.com Logo