0

My base assembler file foidlrt.asm started getting a bit too large so I broke it up into two. Here is the entirety of the second file folder_stdio.asm:

; foidl_stdio.asm

%include   "foidlstnd.inc"


        section .text

        DEFAULT REL

global foidl_fclose           ; Raw file close

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; foidl_close
; Raw file close
; REGISTERS (1):
; RDI file handle
; CALLS:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

foidl_fclose:
    mov       rax,SYSCALL_FILE_CLOSE  ; 0x2000006
    syscall
    ret

However, now when I build I am now getting this error from make despite the global declaration in the new file:

nasm src/foidlrt.asm -f macho64 --prefix _ -g -O0 -Iincludes/ -o asmobjs/foildrt.o
nasm src/foidlrt.asm -f macho64 --prefix _ -g -O0 -Iincludes/ -o asmobjs/foidl_stdio.o
libtool -static -s -o libs/libfoidlrt.a asmobjs/foildrt.o asmobjs/foidl_stdio.o
gcc src/testlink.c -L libs -l foidlrt -Wall -g -L. -Wl,-pie -I. -o bin/testlink
Undefined symbols for architecture x86_64:
  "_foidl_fclose", referenced from:
      _main in testlink-4b5ad3.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Version information:

XCode - 7.2.1 (7C1002)
nasm  - NASM version 2.12 compiled on Feb 28 2016
gcc   - Apple LLVM version 7.0.2 (clang-700.1.81)

RESOLVED

Error was all mine, makefile rule was bad. Working as expected now.

Frank C.
  • 7,758
  • 4
  • 35
  • 45
  • Did you declare `foidl_fclose` as `extern` in the other source file? – Michael Mar 20 '16 at 10:56
  • I declared it extern `testit.c` as well as in `foidl.asm` to no avail. – Frank C. Mar 20 '16 at 11:03
  • As the error message says, apparently you need a leading underscore on symbol names. So change your `foidl_fclose` to `_foidl_fclose`. – Jester Mar 20 '16 at 12:02
  • @Jester,I set that in the nasm compile with `--prefix _` in both files. This worked correctly when it was just one file. – Frank C. Mar 20 '16 at 12:12
  • I missed that. Yes, indeed that should work. Next question, does the `libtool -s` maybe strip the symbols? Check the object and the library with (the equivalent of) `nm` or `objdump`. – Jester Mar 20 '16 at 12:18
  • Very strange, running `nm -A` against each individual .o(bject) file produces the same symbol table listing and they are **identical** and **devoid** of the one function noted above. Same if I run against the static library. – Frank C. Mar 20 '16 at 12:52
  • AHA! I think I found the problem – Frank C. Mar 20 '16 at 12:53
  • 1
    @Jester - It was my make rule. If you look at the make output it was re-compiling `foidlrt.asm` out to `foidl_stdio.o`. User error! – Frank C. Mar 20 '16 at 13:15

0 Answers0