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

Replace realpath to BSD implementation #5620

Closed
wants to merge 1 commit into from

Conversation

yujincheng08
Copy link
Collaborator

Fix #5530

The thing is, ndk changes its realpath implementation to a new one that does not support kernel with version < 3.6. So, on some old devices or TWRP, readlink -f will fail. This replaces the realpath implementation to support older kernel versions.

@osm0sis Could you help me make this change to ndk-kitchen and co-author me? Thx.

@yujincheng08 yujincheng08 requested a review from osm0sis March 19, 2022 17:12
@yujincheng08 yujincheng08 changed the title Replace realpath to BSD implementatio Replace realpath to BSD implementation Mar 19, 2022
@yujincheng08
Copy link
Collaborator Author

This issue is introduced by NDK, see: android/ndk#1260

And NDK seems not going to fix it. So sad.

@osm0sis
Copy link
Collaborator

osm0sis commented Mar 19, 2022

Not a ton of time with a 1-month old here; basically limited to stuff I can do on my phone in between/during feedings. 🥲😴😅

Copy link
Collaborator

@osm0sis osm0sis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be best to do this in the busybox source, similar to this: https://github.com/osm0sis/android-busybox-ndk/blob/master/patches/024-a-hush-platform.patch

It's how busybox handles broken/incomplete platforms.

@yujincheng08
Copy link
Collaborator Author

yujincheng08 commented Mar 21, 2022

Might be best to do this in the busybox source, similar to this: https://github.com/osm0sis/android-busybox-ndk/blob/master/patches/024-a-hush-platform.patch

It's how busybox handles broken/incomplete platforms.

No. Your patch is for undefined symbols but mine is for replacing the bionic implementation. So doing something like your patch will raise duplicated symbols when linking.

@osm0sis
Copy link
Collaborator

osm0sis commented Mar 21, 2022

platform.h/.c can be used to wrap and add various functions and calls, sometimes replacing ones from the libc used on a particular platform by defining a bb_ version instead.

Yours could be added in code as bb_realpath in platform.c, then defined as a replacement in platform.h, I think I've seen that done in busybox before. 🤷‍♂️

@yujincheng08
Copy link
Collaborator Author

@osm0sis
Copy link
Collaborator

osm0sis commented Mar 21, 2022

Sort of? I might be also thinking about how I took the bb_ functions for ttyname and used them in my nano builds by defining it as the replacement for the useless NDK stub version of it: https://forum.xda-developers.com/t/tools-zips-scripts-osm0sis-odds-and-ends-multiple-devices-platforms.2239421/page-34#post-66486572

But busybox platform.h/.c should allow for something similar I thought.

@yujincheng08
Copy link
Collaborator Author

Ok, I see now. Instead of -Wl,--wrap them, busybox prefers to use macro #define bb_x x to replace x function. Well, as long as it can cover all source code, it's okay. I use wrap because I am afraid some source files don't include platform.h and use the original function from libc.a.

@osm0sis
Copy link
Collaborator

osm0sis commented Mar 21, 2022

Bingo! And nah, in busybox platform is in all, since it has all the platform hacks needed everywhere. 👍

@yujincheng08
Copy link
Collaborator Author

yujincheng08 commented Mar 21, 2022

Then it's safe to use bb_ trick. But I just let it go since this PR is only for testing and demonstration because I don't want to mess up with the busybox kitchen. It's up to the one who actually makes this change to the busybox kitchen. Maybe you, or Jhon.

@osm0sis
Copy link
Collaborator

osm0sis commented Mar 21, 2022

Sounds good. Can you let me know the first SDK version or NDK version where this issue started? It worked last with Magisk 24.1 I believe. I'll look into guarding it in a patch to platform.h with that, and upstream it in busybox if they'll accept it.

@yujincheng08
Copy link
Collaborator Author

ndk 21 and ndk 22 have no problem. ndk 23 introduces the problem.

@osm0sis
Copy link
Collaborator

osm0sis commented Mar 22, 2022

Could this regression break anything else in Magisk? Should the used NDK perhaps be downgraded for now? I know @topjohnwu has done that in the past.

@yujincheng08
Copy link
Collaborator Author

Only busybox is affected.

@topjohnwu topjohnwu closed this in b1faa5e Mar 22, 2022
@canyie canyie deleted the realpath branch March 22, 2022 11:22
@topjohnwu
Copy link
Owner

topjohnwu commented Mar 22, 2022

@osm0sis we shouldn't upstream this to BusyBox, as this is an issue with Bionic updating realpath to an implementation that requires higher Linux versions. Bionic does not really support static executables, so no considerations has been made when this Bionic change is pushed. If we build busybox as a dynamically linked executable (which 99.9% of people should, we build busybox statically for no reason other than supporting recovery installations), there would be no issues at all.

@osm0sis
Copy link
Collaborator

osm0sis commented Mar 22, 2022

I mean, busybox is about supporting broken platforms in places so it's not entirely outside their usual, but 👍

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.

readlink -f from busybox is broken for kernel version < 3.6
3 participants