gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > undefined reference to _kill:problem with devkitarm

#85392 - xyierz - Mon May 29, 2006 8:32 pm

Last night I was struggling with a linker error while trying to compile a library for the DS:
Code:

/usr/local/devkitpro/devkitARM/bin/../lib/gcc/arm-elf/4.1.0/../../../../arm-elf/lib/interwork/libc.a(signalr.o): In function `_kill_r':
: undefined reference to `_kill'

I found the cause of the error this morning. When I was asking about it in IRC, I was told that someone had posted here asking about this error, but I haven't been able to find the post.

Anyway, the problem is that for some reason the linker is trying to link signalr.o which does indeed contain an undefined reference to _kill. If you take a look at the symbols exported by signalr.o:

Code:

$ arm-elf-objdump -t libc.a

signalr.o:     file format elf32-littlearm

SYMBOL TABLE:
00000000 l    d  .text  00000000 .text
00000000 l    d  .data  00000000 .data
00000000 l    d  .bss   00000000 .bss
00000000 l    d  .comment       00000000 .comment
00000000 g     F .text  00000004 _getpid_r
00000000         *UND*  00000000 _getpid
00000004 g     F .text  0000003c _kill_r
00000000         *UND*  00000000 _kill
00000000         *UND*  00000000 errno


You'll notice that signalr.o exports the functions _getpid_r and _kill_r. Taking a look at which libc functions refer to these symbols:

Code:

$ find . -name '*.a' | xargs arm-elf-nm -u -A | grep _getpid_r
./libc.a:mktemp.o:         U _getpid_r
./libc.a:signal.o:         U _getpid_r
./libc.a:tmpnam.o:         U _getpid_r

$ find . -name '*.a' | xargs arm-elf-nm -u -A | grep _kill_r
./libc.a:signal.o:         U _kill_r


Since mktemp.o, signal.o, and tmpnam.o all reference symbols defined in signalr.o, using any functions that they define will link in signalr.o and trigger the linker error. Using another objdump, I determined that the functions that these object files export are

mktemp.o: mktemp(), mkstemp()
signal.o: raise(), signal()
tmpnam.o: tempnam(), tmpnam()

For a proof of concept, I wrote a simple program with examples of all the function calls that trigger this error:
Code:

#include <stdio.h>
#include <stdlib.h>

int main() {
  // the following libc function calls trigger the linker error
  signal(0, NULL);
  tmpnam(NULL);
  tempnam(NULL, NULL);
  mktemp(NULL);
  mkstemp(NULL);

  return 0;
}


Since none of these functions are really very useful on the DS, probably the best fix is to simply avoid using them.

#85412 - tepples - Tue May 30, 2006 1:06 am

Wouldn't mktemp() and friends be useful with Chishm's FAT library?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.