Link problem in ChibiStudio

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: utzig, lbednarz, tfAteba, barthess, RoccoMarco

nbon
Posts: 10
Joined: Fri Jan 23, 2015 2:56 pm

Link problem in ChibiStudio

Postby nbon » Tue Sep 22, 2015 5:48 pm

Hi,
I'm experiencing a weird link problem which has already been mentionned in other posts, but without any solution.
Problem is (almost) the same with 4.7 2014q2\arm-none-eabi and 4.9 2015q2\arm-none-eabi
I'm coding in C/C++. Most of my code is in C++. I'm using RT/HAL with the last version of ChibiStudio.

Here's what I get with 4.9 2015q2\arm-none-eabi :

Code: Select all

c:/chibistudio/tools/gnu tools arm embedded/4.9 2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m\libg.a(lib_a-abort.o): In function `abort':
abort.c:(.text.abort+0xa): undefined reference to `_exit'
c:/chibistudio/tools/gnu tools arm embedded/4.9 2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m\libg.a(lib_a-signalr.o): In function `_kill_r':
signalr.c:(.text._kill_r+0xe): undefined reference to `_kill'
c:/chibistudio/tools/gnu tools arm embedded/4.9 2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m\libg.a(lib_a-signalr.o): In function `_getpid_r':
signalr.c:(.text._getpid_r+0x0): undefined reference to `_getpid'
c:/chibistudio/tools/gnu tools arm embedded/4.9 2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m\libg.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
collect2.exe: error: ld returned 1 exit status


I found out how to link my code by commenting out some lines, but then it won't work anymore !

It deals about a i2c slave request handler. I want to call different hook functions, depending on the first byte of the received request.
Here's the code :

Code: Select all

u8  rxBody[60];   /* stores last message master sent us */
u8  txBody[60];   /* response */

typedef   void HookFunction();
typedef struct {
   HookFunction*   hook;
   u8   size;
} I2cRequestHandler;

void   readSensor() {
   IdentifiedRecord   *rec   =   (IdentifiedRecord*)txBody;
   bool   res = mesures.pull(rec);
   if (!res) {
      rec->sensorId      = 0;
   }
}

I2cRequestHandler   clientReadHandlers[MAX_READ_OR_WRITE_COMMANDS] = {{ &readSensor, sizeof(IdentifiedRecord) }, {0, 0}}; // IF I DON'T INITIALIZE THIS LINE IT LINKS !!!

void i2cSlaveRxCpltCallback(I2CDriver *i2cp)
{
  (void)i2cp;
  u8   code   = rxBody[0];  // IF I CHANGE THIS LINE WITH code = 0; IT LINKS !!!
  u8   cmd      = code & CODE_MASK;
  if ((code >> 4) == 0) {   // Client reading function
    if (clientReadHandlers[cmd].hook != 0) {
      (*clientReadHandlers[cmd].hook)();
    }
  } else {            // Client writing to board function
    if (clientWriteHandlers[cmd].hook != 0) {
      (*clientWriteHandlers[cmd].hook)();
    }
  }
}

I2CSlaveMsg slaveRequest = {
  sizeof(rxBody),        /* max sizeof received msg body */
  rxBody,                /* body of received msg */
  ignore,              /* do nothing on address match */
  i2cSlaveRxCpltCallback,/* on msg received */
  ignore            //reportRxErr
};

I2CSlaveMsg slaveReply = {
  32,  /* trailing zero byte will be repeated as needed */
  txBody,
  ignore,               /* do nothing on address match */
  ignore,               /* do nothing after reply sent */
  ignore            //reportReplyErr
};


I tried static and const declarations for almost every global variable, but this doesn't change anything : keeping my code functionnal makes it impossible to link.
Thank you for the help.
NB

nbon
Posts: 10
Joined: Fri Jan 23, 2015 2:56 pm

Re: Link problem in ChibiStudio

Postby nbon » Tue Sep 22, 2015 6:05 pm

I found out how to compile my code, but I still don't understand the link problem. And I have to give up the setTime() functionnality :
I had to comment out one line in one of my hook functions, the one used to set the RTC time :

Code: Select all

void   sndTimestamp() {
     struct tm tim;
     struct tm *canary;
     time_t *unix_time = (time_t*)rxBody;


     /* If the conversion is successful the function returns a pointer
        to the object the result was written into.*/
//     canary = localtime_r(unix_time, &tim); // COMMENTING OUT THIS LINE SOLVES THE PROBLEM
     osalDbgCheck(&tim == canary);

     rtcConvertStructTmToDateTime(&tim, 0, &timespec);
     rtcSetTime(&RTCD1, &timespec);
}


I found this piece of code on this forum.
I still don't get the reason of the link problem.

User avatar
Giovanni
Site Admin
Posts: 12744
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 693 times
Been thanked: 572 times
Contact:

Re: Link problem in ChibiStudio

Postby Giovanni » Tue Sep 22, 2015 6:19 pm

Hi,

The C library requires those functions, there is a module under /os/various named syscall.c, you should include it in your application Makefile.

Giovanni

nbon
Posts: 10
Joined: Fri Jan 23, 2015 2:56 pm

Re: Link problem in ChibiStudio

Postby nbon » Wed Sep 23, 2015 4:09 pm

Thank you for the advice, but I had already tried this.

_exit, _kill and _getpid symbols are defined in /os/various/cpp_wrappers/syscalls_cpp.cpp
Adding $(CHIBIOS)/os/various/cpp_wrappers/syscalls_cpp.cpp \ to CPPSRC in Makefile gives this error, for 4.7 and 4.9 versions :

Code: Select all

`_exit' referenced in section `.text.abort' of c:/chibistudio/tools/gnu tools arm embedded/4.7 2014q2/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/armv7e-m\libg.a(lib_a-abort.o): defined in discarded section `.text' of build/obj/syscalls_cpp.o (symbol from plugin)
`_kill' referenced in section `.text._kill_r' of c:/chibistudio/tools/gnu tools arm embedded/4.7 2014q2/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/armv7e-m\libg.a(lib_a-signalr.o): defined in discarded section `.text' of build/obj/syscalls_cpp.o (symbol from plugin)
`_getpid' referenced in section `.text._getpid_r' of c:/chibistudio/tools/gnu tools arm embedded/4.7 2014q2/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/armv7e-m\libg.a(lib_a-signalr.o): defined in discarded section `.text' of build/obj/syscalls_cpp.o (symbol from plugin)


Adding $(CHIBIOS)/os/various/syscalls.c \ to CSRC in Makefile does not resolve anything.

User avatar
Giovanni
Site Admin
Posts: 12744
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 693 times
Been thanked: 572 times
Contact:

Re: Link problem in ChibiStudio

Postby Giovanni » Wed Sep 23, 2015 4:56 pm

Not sure about the cause.

Giovanni

nbon
Posts: 10
Joined: Fri Jan 23, 2015 2:56 pm

Re: Link problem in ChibiStudio

Postby nbon » Thu Sep 24, 2015 4:20 pm

For sure these last link error messages are chinese for me.
What does "defined in discarded section `.text'" mean ?

Notice that commenting out the localtime_r() call solved the problem only when I'm using version 4.9. The same problem remains with version 4.7.

fresird
Posts: 5
Joined: Thu Oct 13, 2016 9:13 am
Been thanked: 2 times

Re: Link problem in ChibiStudio

Postby fresird » Mon May 18, 2020 3:24 am

I get the same error message. After I change "USE_LINK_GC", "USE_LTO" from NO to Yes. Problem is solved. I am using ChibiOS_19.1.3 and gcc 10.1.0


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 1 guest