Shop OBEX P1 Docs P2 Docs Learn Events
Linking addresses and -mcog — Parallax Forums

Linking addresses and -mcog

CircuitsoftCircuitsoft Posts: 1,166
edited 2013-01-04 11:54 in Propeller 1
I'm trying to convert Lonesock's FastFullDuplexSerial object to C, and running into issues.

All my experience with linking and symbols has been on processors with only one address space, so I'm not sure how to do this on PropGCC.
alex@alex-thinks ~/Projects/Parallax Library/serial $ cat Makefile 
CC=/opt/parallax/bin/propeller-elf-gcc
CFLAGS=-g3 -DTEST
all: ffds1
ffds1m.o: ffds1m.S
        $(CC) -c -o $@ -mcog $^ -g3
ffds1: ffds1.o ffds1m.o
        $(CC) -o $@ $^
alex@alex-thinks ~/Projects/Parallax Library/serial $ make -j2
/opt/parallax/bin/propeller-elf-gcc -g3 -DTEST   -c -o ffds1.o ffds1.c
/opt/parallax/bin/propeller-elf-gcc -c -o ffds1m.o -mcog ffds1m.S -g3
/opt/parallax/bin/propeller-elf-gcc -o ffds1 ffds1.o ffds1m.o
ffds1m.o: In function `ffds1.entry':
(.ffds1.text+0x4): relocation truncated to fit: R_PROPELLER_SRC against symbol `ffds1.ctra_val' defined in .ffds1.text section in ffds1m.o
ffds1m.o: In function `ffds1.entry':
(.ffds1.text+0x8): relocation truncated to fit: R_PROPELLER_SRC against symbol `ffds1.maskTX' defined in .ffds1.text section in ffds1m.o
ffds1m.o: In function `ffds1.entry':
(.ffds1.text+0xc): relocation truncated to fit: R_PROPELLER_SRC against symbol `ffds1.ctrb_val' defined in .ffds1.text section in ffds1m.o
ffds1m.o: In function `ffds1.entry':
(.ffds1.text+0x14): relocation truncated to fit: R_PROPELLER_DST against `step_clocks'
ffds1m.o: In function `ffds1.entry':
(.ffds1.text+0x14): relocation truncated to fit: R_PROPELLER_SRC against symbol `ffds1.period_ptr' defined in .ffds1.text section in ffds1m.o
ffds1m.o: In function `ffds1.entry':
(.ffds1.text+0x1c): relocation truncated to fit: R_PROPELLER_DST against `timestamp'
ffds1m.o: In function `ffds1.entry':
(.ffds1.text+0x1c): relocation truncated to fit: R_PROPELLER_SRC against `step_clocks'
ffds1m.o: In function `ffds1.entry':
(.ffds1.text+0x20): relocation truncated to fit: R_PROPELLER_DST against `timestamp'
ffds1m.o: In function `rx_main':
(.ffds1.text+0x28): relocation truncated to fit: R_PROPELLER_DST against `lockstep_ret'
ffds1m.o: In function `rx_main':
(.ffds1.text+0x28): relocation truncated to fit: R_PROPELLER_SRC against `tx_jump'
ffds1m.o: In function `rx_main':
(.ffds1.text+0x2c): additional relocation overflows omitted from the output
collect2: ld returned 1 exit status
make: *** [ffds1] Error 1

I'm sure that all these problems need the same fix, but I just don't know what it is.

Comments

  • jazzedjazzed Posts: 11,803
    edited 2012-12-29 13:05
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-12-29 14:19
    Ok.The ".cog_ram" directive after the section name isn't explained. Can you expand on that?
  • jazzedjazzed Posts: 11,803
    edited 2012-12-29 18:07
    Ok.The ".cog_ram" directive after the section name isn't explained. Can you expand on that?

    .cog_ram Marks symbols to indicate that their values should be treated as long word
    addresses, not byte addresses, by the linker. This is intended to duplicate the
    standard behavior of the PASM assembler.

    https://propgcc.googlecode.com/files/as.pdf page 211
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-12-29 19:41
    Ah, so .cog_ram means I can use the symbols locally within the assembler, but I need to multiply their addresses by 4, and add the __start offset to access them from outside before calling coginit.
  • jazzedjazzed Posts: 11,803
    edited 2013-01-01 15:21
    Ah, so .cog_ram means I can use the symbols locally within the assembler, but I need to multiply their addresses by 4, and add the __start offset to access them from outside before calling coginit.

    Actually, I think it means you don't need to multiply their addresses. Eric or David may have better explanations - i'm not much of a gas user.
  • ersmithersmith Posts: 6,054
    edited 2013-01-04 11:54
    Ah, so .cog_ram means I can use the symbols locally within the assembler, but I need to multiply their addresses by 4, and add the __start offset to access them from outside before calling coginit.

    That's pretty much correct: .cog_ram makes the symbols long addresses rather than byte addresses, so if you want to refer to them in C functions (which typically expect byte addresses) you will have to multiply by 4. You could equally well modify the original assembly to use byte addresses instead; that's what spin2cpp --gas will do.

    Eric
Sign In or Register to comment.