Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 objc_msgSend 请教 #4

Open
qiaolw opened this issue Jan 8, 2019 · 1 comment
Open

关于 objc_msgSend 请教 #4

qiaolw opened this issue Jan 8, 2019 · 1 comment

Comments

@qiaolw
Copy link

qiaolw commented Jan 8, 2019

objc 代码 编译生成 objc_msgSend 函数, 那应该是在 编译过程中产生的吧,具体是哪一步?; runtime 是不是就是个 动态库;objc_msgSend 就是runtime动态库里的方法, 最后会链接,装载成 执行文件吗?

望指教.

@LeoMobileDeveloper
Copy link
Owner

LeoMobileDeveloper commented Jan 10, 2019

objc代码生成objc_msgSend是在哪一步?

是在CodeGen这一步,这一步会对Objective C的runtime进行桥接,objective c的方法会被转换为objc_msgSend函数调用。 详见:深入浅出iOS编译

runtime 是不是就是动态库?

runtime是一套Objective C运行时机制,把runtime叫做动态库是不严谨的,runtime会依赖于一些动态库,核心的是libobjc.A.dylib,在操作系统的这个目录下 /usr/lib/libobjc.A.dylib

objc_msgSend 就是runtime动态库里的方法, 最后会链接,装载成 执行文件吗?

不会,Objective C的ABI非常稳定,所以动态库libobjc.A.dylib是iOS操作系统层面提供的,不需要打包进App。链接时,可执行文件里会写入objc_msgSend来自libobjc.A.dylib,然后App启动的时候,由dyld修复objc_msgSend函数在内存中的地址。详见:深入理解iOS App的启动过程

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants