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

dyld fails after Xcode.app is moved #130

Open
manicmaniac opened this issue Aug 12, 2022 · 0 comments
Open

dyld fails after Xcode.app is moved #130

manicmaniac opened this issue Aug 12, 2022 · 0 comments

Comments

@manicmaniac
Copy link
Owner

manicmaniac commented Aug 12, 2022

xcnew links Xcode internal dynamic frameworks like IDEFoundation.framework and DVTFoundation.framework.
To find these frameworks, xcnew also set its runpath to $DEVELOPER_DIR/../{Frameworks,SharedFrameworks,PlugIns} where $DEVELOPER_DIR points the current Xcode at link time.
Thus if the path to Xcode is changed, xcnew consistently fails to link necessary frameworks.
Of course runpath can be updated with install_name_tool so it doesn't a big problem for experts.
However, I think I should not assume all users are familiar with such a deep knowledge.

This problem can be avoided if xcnew doesn't rely on runpath but loads those frameworks in other way.
There's two options I think:

A. Implement a custom linker and set its path to LC_LOAD_DYLINKER (ref: https://stackoverflow.com/q/10028639/6918498)
B. Implement a wrapper to set DYLD_FRAMEWORK_PATH and so on before running the main program and
dynamically load classes in IDEFoundation and DVTFoundation.

https://github.com/octoml/macho-dyld seems to be a good example of the option A but it looks too difficult for me to implement the full set API of dyld (macho-dyld says it lacks some important features like loading with install name).

So the option B may be better.
Actually it cannot be done because dyld works before the main entry point runs.

The steps to achieve the goal would be:

  1. Locate Xcode.app bundle from the current user's $DEVELOPER_DIR at runtime
    • For retrieving $DEVELOPER_DIR value, xcselect.h has nice API
  2. Analyze Xcode's mach-o binary to get the correct runpaths (LC_RPATH) and embeded environment variables (LC_DYLD_ENVIRONMENT)
  3. Set DYLD_FRAMEWORK_PATH or so to the running environment
  4. To enable the environment update, exec the current process again
  5. Run the main program
@manicmaniac manicmaniac changed the title dyld failed after Xcode.app is moved dyld fails after Xcode.app is moved Aug 12, 2022
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

Successfully merging a pull request may close this issue.

1 participant