Search code examples
c++macosclangkernel-extension

Kext compiled fine with symbols undefined


I am recently writing a kernel module for osx 10.9, and found out that every symbol in the final binary I compiled is undefined by nm tool.

How is it done by specifying flags in build settings? I mean, when you are building a user mode application, it cant be linked correctly when it has symbols unresolved. I cant find any related flags in command line of building the kext binary.

Just out of cuirosity, where is this flag that tells linker any undefined symbols are ok? I know the --unresolved-symbols flag but it is not found in the build command line.

Moreover, how do I link directly against mach_kernel? Cause I just saw a driver of osx 10.5 which links to macho. Or is it only possible in the old days?


Solution

  • The flag that accomplishes this for a kext is the -Xlinker -kext, it also includes the option -nostdlib because the base standard library is not available to a kext. These rules tell the OSX linker that it doesn't need to resolve all the symbols in the resulting binary.

    You don't link directly to the kernel, you rely on the undefined symbols being connected up at kext load time rather than at any other time.