How to fix? nstackwords linker problem

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
landon
Experienced Member
Posts: 71
Joined: Mon Sep 06, 2010 4:05 pm

How to fix? nstackwords linker problem

Post by landon »

I've got an odd linker error that I can't find a solution to. I've seen other references to this nstackwords link problem, but they always related to an XC to C/C++ call. In my case, the only call is within the same .C source file - I never cross boundaries between XC and C with this call.

In my .c file I have this structure:

Code: Select all

#define MAX_CMD_LEN  20
char commandCache[MAX_CMD_LEN];

void parse_virtjoule_cli( char *command )
{
  // do some stuff
}

void build_cli_line( unsigned char rxData)
{
	//....
	parse_virtjoule_cli( commandCache );
			
}
The linker error I'm getting says:

Code: Select all

xmap: Error: Value of undefined resource symbol "parse_virtjoule_cli.nstackwords" cannot be determined.
xmap: Error:   ...needed for function build_cli_line
xmap: Error:   ...needed for function executive
xmap: Error: Symbol "parse_virtjoule_cli.nstackwords" for resolution of resource expression for ".LLNK154" is undefined.
xmap: Error: Symbol for resolution of resource expression for ".LLNK157" is undefined.
xmap: Error: Symbol for resolution of resource expression for ".LLNK128" is undefined.
xmap: Error: Symbol for resolution of resource expression for ".LLNK160" is undefined.
xmap: Error: Symbol for resolution of resource expression for ".LLNK135" is undefined.
xmap: Error: Symbol for resolution of resource expression for ".LLNK163" is undefined.
xmap: Error: Symbol for resolution of resource expression for ".LLNK139" is undefined.
xmap: Error: Symbol for resolution of resource expression for ".LLNK166" is undefined.
xmap: Error: Symbol for resolution of resource expression for ".LLNK143" is undefined.
xmap: Error: Symbol for resolution of resource expression for ".LLNK147" is undefined.
xmap: Error: Symbol for resolution of resource expression for ".LLNK148" is undefined.
If I comment out the one call to parse_virtjoule_cli, it compiles and links fine.

If I comment out the one call and the function itself, it compiles and links fine so I know it's not being references elsewhere.

The method is declared before its use, so no externs should be involved at all.

This seems like a linker bug to me. How can I get around this problem? It's so basic but fails.

Landon


User avatar
landon
Experienced Member
Posts: 71
Joined: Mon Sep 06, 2010 4:05 pm

Post by landon »

I've narrowed this down to using a function pointer to make a call.

The code is essentially like this test code I stripped out of the code that's having a problem in XDev.

Code: Select all

#include <stdio.h>
#include <string.h>

void action_cmd_help( int param1, int param2, int param3 )
{
  printf("Help\n");
}

struct CLICommand
{
  char *cliCommand;
  void (*action)(int, int, int); // declare function ptr
  unsigned char hasParams;                        // value is number of parameters
} cliCommands[] =
    {
      [0].cliCommand = "?", [0].action = action_cmd_help, [0].hasParams = 0,
    };

int command_num = 1;
#define MAX_CMD_LEN  20
char commandCache[MAX_CMD_LEN];

void parse_cli( char *command )
{
  int i;
  int intParam1=0, intParam2=0;
  char dummy[10];
  void (*action)(int, int, int) = NULL;

  for( i = 0; i < command_num; i++ )
  {
    // compare the first letters of the given command to known commands
    if ( strncmp( command, cliCommands[i].cliCommand, strlen(cliCommands[i].cliCommand)) == 0 )
    {
      switch( cliCommands[i].hasParams )
      {
      case 0:
        break;
      case 1:
        sscanf(command, "%s %d", dummy, &intParam1 );
        break;
      case 2:
        sscanf(command, "%s %d %d", dummy, &intParam1, &intParam2 );
        break;
      }

      action = cliCommands[i].action;        // <-- set up function pointer (one way to)
      (*action)(0, intParam1, intParam2 );   // <-- if commented out, links fine.
      return;
    }
  }

}

int main( int argc, char *argv[] )
{
  parse_cli("?");
}
If I compile the code above with gcc on a typical host (linux, os x), it compiles and links fine. However, I need to comment out the call from a function pointer in order to get it to work in XDev.

Seems like the linker error is very misleading....it's complaining about the method in which the function pointer call is made, not the function pointer call itself.