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

add roothide support #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

add roothide support #40

wants to merge 2 commits into from

Conversation

roothider
Copy link

What does this implement/fix? Explain your changes.

add roothide support

Does this close any currently open issues?

no

Any relevant logs, error output, etc?

Any other comments?

no

Where has this been tested?

Operating System: macos

Platform: arm64

Target Platform: ios15/16/17

Toolchain Version: clang-1400.0.29.202

SDK Version: 15.4

@L1ghtmann
Copy link
Member

This questions spawns from my ignorance of Xcode -- is there a reason the search path list isn't just:

LD_RUNPATH_SEARCH_PATHS = (
	"$(inherited)",
	"@executable_path/Frameworks",
	"@loader_path/Frameworks",
	"@rpath/Library/Frameworks",
);

considering that @loader_path/.jbroot is a valid rpath?

@roothider
Copy link
Author

This questions spawns from my ignorance of Xcode -- is there a reason the search path list isn't just:


LD_RUNPATH_SEARCH_PATHS = (

	"$(inherited)",

	"@executable_path/Frameworks",

	"@loader_path/Frameworks",

	"@rpath/Library/Frameworks",

);

considering that @loader_path/.jbroot is a valid rpath?

yes @loader_path/.jbroot is a valid rpath on rh. ❤️

@L1ghtmann
Copy link
Member

L1ghtmann commented Dec 8, 2024

Tuan and I discussed this briefly and wonder if it may be worthwhile to pass the rootless rpath flags to Xcode as well (see https://github.com/theos/theos/blob/master/vendor/mod/rootless/instance/rules.mk) which would allow, among other things, us to use @rpath here and simplify the search path list.

@leptos-null
Copy link
Member

Have you tested this? This doesn't seem valid to me, as the rpath would be recursive if I'm understanding correctly

@leptos-null
Copy link
Member

leptos-null commented Dec 8, 2024

It looks to me (via testing) that dyld does detect the cycle, and stops.

num.c:

int someFunc(void) {
    return 2;
}

numctl.c:

extern int someFunc(void);

int main(void) {
    return someFunc();
}

test:

clang '-Wl,-dylib,-install_name,@rpath/libnum.dylib' num.c -o libnum.dylib
clang numctl.c -lnum -L. -o numctl -rpath '@rpath/.'
./numctl
# dyld[79285]: Library not loaded: @rpath/libnum.dylib
#   Referenced from: ./numctl
#   Reason: tried: '@rpath/./libnum.dylib' (no such file), '@rpath/./libnum.dylib' (no such file)
uname -v
# Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000

Another test that more closely matches what I understand as the use-case here.

clang '-Wl,-dylib,-install_name,@rpath/libaux.dylib' aux.c -o extra/libaux.dylib
clang '-Wl,-dylib,-install_name,@rpath/libnum.dylib' -rpath '@rpath/extra' -laux -Lextra num.c -o libnum.dylib
clang -rpath '@executable_path' -lnum -L. numctl.c -o numctl
./numctl
dyld[80465]: Library not loaded: @rpath/libaux.dylib
  Referenced from: /private/tmp/link-test/libnum.dylib
  Reason: tried: '@rpath/extra/libaux.dylib' (no such file), '/private/tmp/link-test/libaux.dylib' (no such file), '/private/tmp/link-test/libaux.dylib' (no such file)

Based on this, I do not believe using @rpath in the runtime paths definition will expand as expected.

@roothider
Copy link
Author

roothider commented Dec 9, 2024

It looks to me (via testing) that dyld does detect the cycle, and stops.

num.c:

int someFunc(void) {
    return 2;
}

numctl.c:

extern int someFunc(void);

int main(void) {
    return someFunc();
}

test:

clang '-Wl,-dylib,-install_name,@rpath/libnum.dylib' num.c -o libnum.dylib
clang numctl.c -lnum -L. -o numctl -rpath '@rpath/.'
./numctl
# dyld[79285]: Library not loaded: @rpath/libnum.dylib
#   Referenced from: ./numctl
#   Reason: tried: '@rpath/./libnum.dylib' (no such file), '@rpath/./libnum.dylib' (no such file)
uname -v
# Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000

Another test that more closely matches what I understand as the use-case here.

clang '-Wl,-dylib,-install_name,@rpath/libaux.dylib' aux.c -o extra/libaux.dylib
clang '-Wl,-dylib,-install_name,@rpath/libnum.dylib' -rpath '@rpath/extra' -laux -Lextra num.c -o libnum.dylib
clang -rpath '@executable_path' -lnum -L. numctl.c -o numctl
./numctl
dyld[80465]: Library not loaded: @rpath/libaux.dylib
  Referenced from: /private/tmp/link-test/libnum.dylib
  Reason: tried: '@rpath/extra/libaux.dylib' (no such file), '/private/tmp/link-test/libaux.dylib' (no such file), '/private/tmp/link-test/libaux.dylib' (no such file)

Based on this, I do not believe using @rpath in the runtime paths definition will expand as expected.

dyld has never supported @rpath in rpath, dyld only supports @loader_path/@executable_path in rpath:
https://github.com/apple-oss-distributions/dyld/blob/66c652a1f1f6b7b5266b8bbfd51cb0965d67cc44/dyld/Loader.cpp#L1301C1-L1305C1

@roothider
Copy link
Author

@leptos-null

@leptos-null
Copy link
Member

Thanks for confirming @roothider 👍

This PR looks good to me in terms of the change working.
I'm not sure if we've started integrating roothide paths into other Theos components. Personally, I'm fine with adding this path here.

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 this pull request may close these issues.

3 participants