Author Topic: OSX and NASM  (Read 2492 times)

Offline nasmman123

  • Jr. Member
  • *
  • Posts: 4
« on: November 28, 2013, 06:11:50 AM »
I am woking on a compiler and using NASM to make the object files from the output .s files.  It works for Linux, and Windows, both in both 32 and 64 bit and I am porting to OSX (32 bit first).  I am using it with ld for osx and I am getting a strange linking error for one of my programs.  The only difference between the .s files that I have for the operating system is a runtime that has its own file (runtime.s) and output format.  There is a strange test programs that act differently when I am using OSX and I am wondering if there is a strange reason with NASM and "Mach-O object i386"?  There is only one of my hundreds of tests that for some reason won't link on OSX.  The output .o files all seem good and the test links on other platforms.

I have the following code in my pipeline after I generate the .s files

nasm -O1 -f macho <file>.s -o <DIR>/<file>.o  (for each file)

ld -macosx_version_min 10.4 -e _start -o main <DIR>/*.o

I am getting the following error when I get to ld:

Undefined symbols for architecture i386:
  "List.A.this$", referenced from:
      ?default?.Main.test$ in Main.o
  "List.A@SIT", referenced from:
      ?default?.Main.test$ in Main.o
  "List.A@Subtype", referenced from:
      ?default?.Main.test$ in Main.o
ld: symbol(s) not found for inferred architecture i386

but I can see each of the defines with nm
nm List.A.o
00000010 T List.A.this$

nm _joos.sit.o | grep List.A
00000770 D List.A@SIT

nm _joos.subtypeIT.o | grep List.A
00000000 D List.A@Subtype

Any help would be greatly appreciated.

Offline nasmman123

  • Jr. Member
  • *
  • Posts: 4
Re: OSX and NASM
« Reply #1 on: December 07, 2013, 11:41:53 PM »
Just in case anyone has the same problem, it seems like symbols can't start with "List" for ld?  When I renamed the symbols (leaving everything else the same) to ?List... in place of List it worked.  Not sure if this is a bug in ld for osx (since linux was cool with it) or a macho format thing or what it was.  I tried other symbols adding List. at the beginning and it had the same issue of not linking.  I don't think it's a nasm bug for macho because nm saw the items.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2446
  • Country: us
Re: OSX and NASM
« Reply #2 on: December 08, 2013, 12:20:25 AM »
Thanks for the update, Nasmman123! Sorry you didn't get an answer, but I didn't have the slightest idea what the problem could be. Doesn't like "List", eh? Well, whatever works. I'll try to remember that for the next time it crops up!