2

I just did some basic functions in asm that I compile in a shared library. Like :

BITS 64
            global foo
            section .text
foo:
            mov rax, 1
            ret

I compiled with :

nasm -f elf64 foo.S -o foo.o && gcc -shared foo.o -o libfoo.so

I have a main of test :

#include <stdio.h>
int foo();

int main()
{
  printf("%d\n", foo());
  return (0);
}

If I compiled it with the foo.o directly, everything works well. But if I compiled like this :

gcc main.c -L. -lfoo

I would get this error :

/usr/.../bin/ld: warning: type and size of dynamic symbol `foo' are not defined

I thought it was because the prototype is not declared, but I recompiled foo.o with a lib.h file containing the prototype, and the same problem occurs.

Is that I must complete another section of the elf file?

Thank you.

Evan Carroll
  • 28,578
  • 45
  • 164
  • 290
OOM
  • 133
  • 1
  • 3

1 Answers1

2

You need to specify that the foo symbol corresponds to a function:

[BITS 64]
            global foo:function
            section .text
foo:
            mov rax, 1
            ret
Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164