I have an assembly file that exports two functions. The function names are NASM_RDRAND_GenerateBlock
and NASM_RDSEED_GenerateBlock
. The symbols lack the leading underscore decoration. The file is assembled with NASM.
In the C/C++ code, the symbol names are declared as extern "C"
to avoid mangling. Linking under Linux and Cygwin works as expected. Linking under OS X fails with:
...
Undefined symbols for architecture x86_64:
"_NASM_RDRAND_GenerateBlock", referenced from:
RDRAND::GenerateBlock(unsigned char*, unsigned long) in libcryptopp.a(rdrand.o)
"_NASM_RDSEED_GenerateBlock", referenced from:
RDSEED::GenerateBlock(unsigned char*, unsigned long) in libcryptopp.a(rdrand.o)
ld: symbol(s) not found for architecture x86_64
I want to create an alias such that _NASM_RDRAND_GenerateBlock = NASM_RDRAND_GenerateBlock
so Apple's linker can link to the symbol. Microsoft's PE format and MASM allow it, but I'm not sure if Apple and Mach-O have similar facilities.
My first question is, does the Mach-O file format support symbol aliases?
If so, then my second question is, how do I tell NASM to create the alias? Or what do I need to do in NASM to create a symbol alias?
Here are the command used to build the object files:
nasm -f macho32 rdrand.S -DX86 -g -o rdrand-x86.o
nasm -f macho64 rdrand.S -DX64 -g -o rdrand-x64.o
Here is the assembler file.