告诉'ld'dyld_stub_binder不再在libSystem.dyld中,而是在libSystem.B.dyld

时间:2018-01-24 02:34:00

标签: macos assembly linker x86-64 mach-o

我正在尝试重新创建Launchpad可执行文件,到目前为止一切似乎都正确,除非我在运行ld时收到此警告:

汇编/链接:

as myprogram.s -o myprogram.o
ld myprogram.o -arch x86_64 -macosx_version_min 10.12 -e _start -framework Foundation -framework ApplicationServices -o myprogram

ld: symbol dyld_stub_binder not found (normally in libSystem.dylib).  Needed to perform lazy binding to function _CoreDockSendNotification for architecture x86_64

这是我的代码(对不起NASM人员,AT& T语法):

.section __DATA, __const
.section __TEXT, __text
.globl _start
_start:
pushq %rbp
movq %rbp, %rsp
lea lpToggle_cfstring_(%rip), %rdi
xor %esi, %esi
callq _CoreDockSendNotification
mov %rax, %r14
xor %rdi, %rdi
mov $0x2000001, %rax
syscall

.section __TEXT,__cstring,cstring_literals
lpToggle: .asciz    "com.apple.launchpad.toggle"
.section __DATA,__cfstring
lpToggle_cfstring_:
    .quad   ___CFConstantStringClassReference
    .long   1992                    
    .space  4
    .quad   lpToggle
    .quad   26 

我已更新到xcode和命令行工具的最新版本,我尝试将_start更改为_main,我尝试直接链接libSystem.B.dyld(两者都与没有'.dyld'扩展名):

ld lp.o -arch x86_64 -macosx_version_min 10.12 -e _start -framework Foundation -framework ApplicationServices -L/usr/lib/ -llibSystem.B.dyld -o lp

ld lp.o -arch x86_64 -macosx_version_min 10.12 -e _start -framework Foundation -framework ApplicationServices -llibSystem.B.dyld -o lp

ld lp.o -arch x86_64 -macosx_version_min 10.12 -e _start -framework Foundation -framework ApplicationServices -o lp -l/usr/lib/libSystem.B.dyld

ld lp.o -arch x86_64 -macosx_version_min 10.12 -e _start -framework Foundation -framework ApplicationServices -o lp -libSystem.B.dyld

我得到了:

ld: warning: directory not found for option '-L/usr/lib/ -llibSystem.B.dyld'

ld: warning: directory not found for option '-l/usr/lib/libSystem.B.dyld'

ld: warning: library not found for option '-l/usr/lib/libSystem.B.dyld'

取决于我尝试的那个。

我甚至尝试直接从ld目录使用/Applications/Xcode.app/Contents/Developer/usr/bin来查看新旧版本之间是否存在符号链接问题

我使用lldb来转储libSystem.dyld的symtab,并确定包含以下内容的行:

`[  108] 108 X Undefined 0x0000000000000000 0x0000000000000000 0x00010000 dyld_stub_binder`

这意味着它有index / user id 108X表示它是外部定义的(可能是libSystem.B),{{1} } type,'0x0'的文件地址/值'没有Undefined,标志为Load Address

我在Hopper中加载了Launchpad可执行文件,看看它是怎么回事,但它没有多大帮助(除了它告诉我dyld_stub_binder在libSystem.B.dyld中)。

不确定这是否相关,但在实际的Launchpad标题中包含:

0x00010000

; Load Command 4 ; 0000000100000410 struct __macho_dyld_info_command { LC_DYLD_INFO_ONLY, // LC_DYLD_INFO or LC_DYLD_INFO_ONLY 0x30, // sizeof(struct dyld_info_command) 0x2000, // file offset to rebase info 0x8, // size of rebase info 0x2008, // file offset to binding info 0x40, // size of binding info 0x0, // file offset to weak binding info 0x0, // size of weak binding info 0x2048, // file offset to lazy binding info 0x20, // size of lazy binding infs 0x2068, // file offset to lazy binding info 0x20 // size of lazy binding infs } ;Load command 7 00000001000004a8 struct __macho_dylinker_command { LC_LOAD_DYLINKER, // LC_ID_DYLINKER, LC_LOAD_DYLINKER or LC_DYLD_ENVIRONMENT 0x20, // includes pathname string 0xc // dynamic linker's path name (should be 12) } 00000001000004b4 db "/usr/lib/dyld", 0 00000001000004c2 db 0x00 ; '.' 00000001000004c3 db 0x00 ; '.' 00000001000004c4 db 0x00 ; '.' 00000001000004c5 db 0x00 ; '.' 00000001000004c6 db 0x00 ; '.' 00000001000004c7 db 0x00 ; '.' 部分(看起来像某种无限循环完全跳过中间的4条指令):

_stub_helper

0000000100000f80 lea, qword [dyld_stub_binder_100001000+8]; CODE XREF=0x100000f95 0000000100000f87 push r11 0000000100000f89 jmp qword [dyld_stub_binder_100001000] ; dyld_stub_binder 0000000100000f8f db 0x90 0000000100000f90 push 0x0 0000000100000f95 jmp 0x100000f80 部分:

__DATA__nl_symbol_ptr

0000000100001000 dq dyld_stub_binder ; DATA XREF=0x100000f89 0000000100001008 dq 0x0000000000000000 ; DATA XREF=0x100000f80 细分中:

External Symbols

更有趣的是,如果我用gcc编译:

                 dyld_stub_binder:
0000000100005010         db  0x00 ; '.' ; in /usr/lib/libSystem.B.dylib, CODE XREF=0x100000f89DATA XREF=dyld_stub_binder_100001000
0000000100005011         db  0x00 ; '.'
0000000100005012         db  0x00 ; '.'
0000000100005013         db  0x00 ; '.'
0000000100005014         db  0x00 ; '.'
0000000100005015         db  0x00 ; '.'
0000000100005016         db  0x00 ; '.'
0000000100005017         db  0x00 ; '.'

它将构建没有问题但是在运行时期间会在某些时候出现段错误。我在某些时候说,因为如果我用gcc -arch x86_64 -e _start -framework Foundation -framework ApplicationServices lp.s 加载它并执行lldb a.out命令,它就会执行它应该执行的,没有segfault。因此,很难找到究竟发生了什么。我的预感是run 指向我的应用程序到正确的lldb但我可能是错的

但是,如果我在dyld_stub_binder版本上运行sudo ./myfile,它会运行得很好。什么gccgcc不是?或者是ld命令中的某些内容?

我使用核心macOS程序集仍然相对较新,所以任何指针都会有所帮助!

P.S。我也试过as,但这不起作用

1 个答案:

答案 0 :(得分:2)

ld myprogram.o -arch x86_64 -macosx_version_min 10.12 -e _start -framework Foundation -framework ApplicationServices -o myprogram -l libSystem.B-lsystem.b -lsystem -lc -lm -ld 库的LC_LOAD_DYLIB(libSystem.B.dylib)搜索选项。{。} 添加其中任何一个:

$idbrang

所有都是可以解决缺少$this->db->where("kondisi = 'Ada' AND id_barang = '$idbrang' "); 加载命令的同义词。顺便说一下你的程序是否有效: - )