Shop OBEX P1 Docs P2 Docs Learn Events
PropGCC: What is the "-r" flag? — Parallax Forums

PropGCC: What is the "-r" flag?

What does the "-r" flag do when invoking PropGCC? I noticed that it is used in the Makefile for cog_c_toggle in the PropGCC demos here.
toggle_1.o: toggle_cog.c
	$(CC) -r -Os -mcog -o $@ $<

Comments

  • Are you sure that's not an ld option?


    http://uw714doc.sco.com/en/man/html.1/ld.1.html
    ld -- link editor for object files
    
    -r
    Combine relocatable object files to produce one relocatable object file. ld will not complain about unresolved references. This option cannot be used in dynamic mode or with -a.
    

    dgately
  • As Dennis mentioned, -r is used to link multiple object files and libraries together and produce a single new (but still relocatable) object file. The output is linked with the -mcog libraries, so all the regular register and standard library functions are resolved, but there can still be some unresolved symbols (e.g. references to variables that are defined in the "main" program that will run in HUB).

    As you know, LMM and COG code need different libraries, since they have different calling conventions and since even some internal functions like multiply will end up in different places inside the COGs. So we need to resolve all the library symbols in the COG code so they don't try to use LMM libraries. One way to do that is to completely compile the COG code into a binary blob. However, that means the COG and LMM can't share any symbols at all, and sometimes we may want to e.g. refer to a variable in hub memory from both COG and LMM. To do that we need to do a partial link on the COG side, resolving as many symbols as possible but still allowing references to outside symbols as well.

    There's another wrinkle as well, which is that we don't want the symbols in the COG object to satisfy any LMM unresolved library calls. So the Makefile invokes objcopy with --localize-text to make all the code symbols in the COG be static. (The objcopy also has options to rename the .text section to .toggle.cog so the linker can do its overlay magic.)
Sign In or Register to comment.