XCode pthread kext编译(链接)问题

时间:2018-04-19 20:46:00

标签: xcode multithreading macos pthreads clang

首先,这里提供了代码问题: 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)。

是隐藏在com.apple.kpi.private中的pthreads和osspinlock函数调用吗?我真的需要这些功能用于我的驱动程序,我离不开它们。

我记得当我第一次尝试声明OSSinLock时,Xcode IDE会说&#34;你的意思是IOSimpleLOCK?&#34; (显然不是),我通过改变

来解决
#include <libkern/OSAtomic.h>

#include </usr/include/libkern/OSAtomic.h>

但所有这一切都是允许XCode编译代码&#34;成功&#34;,如果kextutil / libs报告丢失的符号,显然不是这种情况。

任何帮助都会很棒。

感谢。

1 个答案:

答案 0 :(得分:0)

感谢来自newosxbook论坛的Siguza,我可以看看这个问题。

我们的交流记录是here

It turns out, and as Siguza patiently and painstakingly (arguably lovingly ;)) explained,我没有完全围绕从“kernel-land program”到“kernel-land driver”的过渡,后者强加了禁止依赖共享库(例如pthreads)的额外约束。

因此,我不得不将pthread_mutex_lock调用包装到IOLock,并暂时使用Siguza的OSSpinLockLock macro that exploits the availability of OSSpinLockTry