As a mental exercise, I'm trying to write a program that links directly against the GPU driver of my Macbook Pro rather than using Apple's Metal framework. Some exploration led me to this file (presumably specific to my particular hardware):
/System/Library/Extensions/AMDRadeonX6000MTLDriver.bundle/Contents/MacOS/AMDRadeonX6000MTLDriver
Running file
on it confirms this is a Mach-O 64-bit dynamically linked shared library.
Running nm
on it tells me it's a superset of AMD's ROCr runtime. One symbol in particular that interests me is this one:
$ nm -gD AMDRadeonX6000MTLDriver | grep "hsa_init"
00000000001cca20 T __ZN3HSA8hsa_initEv
$ nm -gCD AMDRadeonX6000MTLDriver | grep "hsa_init"
00000000001cca20 T HSA::hsa_init()
So I wrote this simple program (rocr_test.cpp
):
typedef int hsa_status_t;
namespace HSA {
hsa_status_t hsa_init();
}
int main() {
HSA::hsa_init();
return 0;
}
And compiled it like so:
$ clang++ rocr_test.cpp -c
$ clang++ rocr_test.o /System/Library/Extensions/AMDRadeonX6000MTLDriver.bundle/Contents/MacOS/AMDRadeonX6000MTLDriver
Undefined symbols for architecture x86_64:
"HSA::hsa_init()", referenced from:
_main in rocr_main-95c854.o
ld: symbol(s) not found for architecture x86_64
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
However, nm
on the object file shows the linker should look for a symbol with the same name:
$ nm rocr_test.o
U __ZN3HSA8hsa_initEv
0000000000000000 T _main
Why am I seeing this linker error, when nm
shows that a symbol with this exact name clearly exists in the shared library?