【发布时间】:2018-04-19 20:45:59
【问题描述】:
首先,这里有问题代码: https://github.com/i3roly/CMI8788
我的问题的简要描述是,虽然 Xcode 可以将代码编译成 Kext,但生成的 kext 缺少 pthread 和 OSSpinLock 函数调用。
具体来说,当我运行 kextlibs -v 6 PCIAudioDriver.kext 时,我得到了这个:
GagansMacPro:CMI8788 Gagan$ sudo kextlibs -v 6 PCIAudioDriver.kext/
Kext user-space log filter changed from 0xff2 to 0xfff.
Kext kernel-space log filter changed from 0xff2 to 0xfff.
Kext library architecture set to x86_64.
Kext library architecture is x86_64 (unchanged).
For all architectures:
com.apple.iokit.IOAudioFamily = 203.3
com.apple.iokit.IOPCIFamily = 2.9
com.apple.kpi.iokit = 14.5
com.apple.kpi.libkern = 14.5
For x86_64:
7 symbols not found in any library kext.
所以我在这个 kext 上运行了 kextutil -v 6 并得到了这个:
Loading PCIAudioDriver.kext.
(kernel) User-space log flags changed from 0x0 to 0xfff.
(kernel) Received kext load request from user space.
(kernel) Received request from user space to load kext com.CMedia.CMI8788.PCIAudioDriver.
(kernel) Loading kext com.CMedia.CMI8788.PCIAudioDriver.
(kernel) Kext com.apple.kpi.bsd is already loaded.
(kernel) Kext com.apple.kpi.libkern is already loaded.
(kernel) Kext com.apple.kpi.mach is already loaded.
(kernel) Kext com.apple.iokit.IOPCIFamily is already loaded.
(kernel) Kext com.apple.iokit.IOPCIFamily sending 3 personalities to the IOCatalogue and starting matching.
(kernel) Kext com.apple.kpi.iokit is already loaded.
(kernel) Kext com.apple.iokit.IOAudioFamily is already loaded.
(kernel) Kext com.apple.kec.pthread is already loaded.
(kernel) Kext com.apple.kpi.unsupported is already loaded.
(kernel) Allocated link buffer for kext com.CMedia.CMI8788.PCIAudioDriver at 0xffffff7f89b88000 (98304 bytes).
(kernel) kxld[com.CMedia.CMI8788.PCIAudioDriver]: The following symbols are unresolved for this kext:
(kernel) kxld[com.CMedia.CMI8788.PCIAudioDriver]: _OSSpinLockLock
(kernel) kxld[com.CMedia.CMI8788.PCIAudioDriver]: _pthread_cond_init
(kernel) kxld[com.CMedia.CMI8788.PCIAudioDriver]: _pthread_cond_timedwait
(kernel) kxld[com.CMedia.CMI8788.PCIAudioDriver]: _pthread_mutex_init
(kernel) kxld[com.CMedia.CMI8788.PCIAudioDriver]: _pthread_mutex_lock
(kernel) kxld[com.CMedia.CMI8788.PCIAudioDriver]: _pthread_mutex_unlock
(kernel) Can't load kext com.CMedia.CMI8788.PCIAudioDriver - link failed.
(kernel) Failed to load executable for kext com.CMedia.CMI8788.PCIAudioDriver.
(kernel) Kext com.CMedia.CMI8788.PCIAudioDriver failed to load (0xdc008016).
(kernel) Failed to load kext com.CMedia.CMI8788.PCIAudioDriver (error 0xdc008016).
(kernel) Kext com.CMedia.CMI8788.PCIAudioDriver removing all personalities naming it from the IOCatalogue.
Kernel error handling kext request - (libkern/kext) link error.
Failed to load PCIAudioDriver.kext - (libkern/kext) link error.
Failed to load PCIAudioDriver.kext - (libkern/kext) link error.
Check library declarations for your kext with kextlibs(8).
我已尽力调整 OSBundleLibraries,目前:
<key>OSBundleLibraries</key>
<dict>
<key>com.apple.iokit.IOAudioFamily</key>
<string>203.3</string>
<key>com.apple.iokit.IOPCIFamily</key>
<string>2.9</string>
<key>com.apple.kec.pthread</key>
<string>1.0</string>
<key>com.apple.kpi.bsd</key>
<string>12.0</string>
<key>com.apple.kpi.iokit</key>
<string>14.5</string>
<key>com.apple.kpi.libkern</key>
<string>11.2</string>
<key>com.apple.kpi.mach</key>
<string>11.2</string>
<key>com.apple.kpi.unsupported</key>
<string>11.2</string>
</dict>
但没有任何效果。我在 10.10.5 上运行 XCode 7.2.1(与 10.10 和 10.11 SDK)。
pthreads 和 osspinlock 函数调用是否隐藏在 com.apple.kpi.private 中?我的驱动程序确实需要这些功能,而我离不开它们。
我记得当我第一次尝试声明 OSSpinLock 时,Xcode IDE 会说“您是指 IOSimpleLOCK 吗?” (显然不是),我通过更改修复了这个问题
#include <libkern/OSAtomic.h>
到
#include </usr/include/libkern/OSAtomic.h>
但这一切只是让 XCode 能够“成功”编译代码,如果 kextutil/libs 报告缺少符号,显然情况并非如此。
任何帮助都会很棒。
谢谢。
【问题讨论】:
标签: xcode multithreading macos pthreads clang