Shop OBEX P1 Docs P2 Docs Learn Events
Simple blinky program and linker pruning — Parallax Forums

Simple blinky program and linker pruning

DavidZemonDavidZemon Posts: 2,973
edited 2014-10-22 19:37 in Propeller 1
Simple blinky program:
int main () {
    const int led = 0x10000;


    DIRA |= led;


    while (1) {
        OUTA ^= led;
        waitcnt(CLKFREQ / 4 + CNT);
    }
}

Hangs if I compile with `-ffunction-sections -fdata-sections` and link with `-Wl,--gc-sections` with cog memory model. Any idea why?

Comments

  • DavidZemonDavidZemon Posts: 2,973
    edited 2014-10-21 19:27
    For reference, here's the assembly output (with linker pruning off)
    .text
        .balign    4
        .global    _main
    _main
        mov    r7, DIRA
        mov    r6, .LC0
        or    r7, r6
        mov    DIRA, r7
    .L2
        xor    OUTA,r6
        mov    r5, CNT
        rdlong    r7, .LC1
        shr    r7, #2
        add    r7, r5
        waitcnt    r7,#0
        jmp    #.L2
        .balign    4
    .LC0
        long    65536
        .balign    4
    .LC1
        long    __clkfreq
    
  • ersmithersmith Posts: 6,053
    edited 2014-10-22 07:42
    If you do a "propeller-elf-objdump -d" on the generated elf files you'll see that everything is stripped out when "-mcog -gc-sections" is used. This is probably a bug in the way the -mcog linker script and startup files are set up. You can work around it by adding ''-Wl,-e -Wl,_main'' to the link command line -- this will stop the main() function from being stripped.
  • DavidZemonDavidZemon Posts: 2,973
    edited 2014-10-22 19:37
    Well, I doubt there are many folks using cog memory model anyway, so not the end of the world. but too bad for sure. Your post is a good work around for anyone that needs to actually use cog model for a project. For PropWare, I'm just going to have to do a check and, if the memory model is cog, disable linker pruning.
Sign In or Register to comment.