Discussion:
libhybris and musl?
Jens Staal
2014-09-01 08:55:26 UTC
Permalink
Hi

Has anyone tried if libhybris will emulate the bionic libc properly on top of
musl libc? Alternatively, are there plans for bionic binary/source
compatibility in musl like the glibc compatibility (or would this contribute
to bloat?).

I was mostly curious to look into the possiblility of building AOSP (or Mer)
with musl instead of bionic (or glibc in the case of Mer), but for Android app
(those built with NDK) compatibility, one would then need libhybris.

right now just thinking aloud - no real plans at the moment :)
Rich Felker
2014-09-01 21:08:23 UTC
Permalink
Post by Jens Staal
Hi
Has anyone tried if libhybris will emulate the bionic libc properly on top of
musl libc? Alternatively, are there plans for bionic binary/source
compatibility in musl like the glibc compatibility (or would this contribute
to bloat?).
I was mostly curious to look into the possiblility of building AOSP (or Mer)
with musl instead of bionic (or glibc in the case of Mer), but for Android app
(those built with NDK) compatibility, one would then need libhybris.
right now just thinking aloud - no real plans at the moment :)
While I haven't look at the details for how it works, I'm fairly
doubtful that using libhybris would be practical. My guess is that
you'll find it fairly glibc-specific, but perhaps more importantly I'm
not sure what benefit you would get from having apps built against
Bionic using musl. If you have particular aims in mind, let me know,
but my feeling is that it would be a lot more practical to just fix up
the things Bionic is doing that are gratuitously different/broken to
get to a point where programs using Bionic run cleanly side by side
with musl. But if the issue is binary apps using native NDK code with
the Bionic ABI, but where you want the non-native code to run on a
musl-linked Dalvik rather than a Bionic-linked one, and if this all
takes place in the same process context, then maybe something like
libhybris really is needed.

I'm quite interested in this project as a prototype for how Android
could be moved from Bionic to musl, and (optionally, but I think this
is the right direction) steered back from its gratuitous
incompatibilities in filesystem layout, handling of dns, user/group
lookups, etc. and re-unified with Linux. Please keep us informed if
you make any interesting progress!

Rich
Wermut
2014-09-02 07:11:33 UTC
Permalink
We used libhybris for one single thing. Getting Android/bionic linked
graphic drivers up and running under embedded glibc linux. Since all the
hardware vendors startet to only deliver their drivers in binary form and
exclusivly for Android, these is usually the only way to get GPU up and
running.

libhybris was originally developed for Sailfish OS that is using Android
drivers of all kind under a glibc enviroment. The graphic Stack is Android
OpenGL driver > libhybris > wayland. Other projects like the Intel/Samsung
"mer" project is doing exactly the same.

If you are interessted how to install and use it, there is a rudimentary
how to:
http://www.cnx-software.com/2013/04/21/how-to-use-libhybris-and-android-gpu-libraries-with-mer-linux-on-the-cubieboard/

This thing is a therible hack, but unfortunatly this is often the only way
to get things like OpenGL, hw video decoding etc. working on embedded arm
linux. There are no signs that companies like Qualcom or ARM themself with
their Mali GPU will deliver open source drivers.

Linking your own apps to bionic/libhybris makes absolutly no sense. The
reason for libhybris is to use bionic binaries (drivers) within glibc based
enviroments.
Post by Jens Staal
Post by Jens Staal
Hi
Has anyone tried if libhybris will emulate the bionic libc properly on
top of
Post by Jens Staal
musl libc? Alternatively, are there plans for bionic binary/source
compatibility in musl like the glibc compatibility (or would this
contribute
Post by Jens Staal
to bloat?).
I was mostly curious to look into the possiblility of building AOSP (or
Mer)
Post by Jens Staal
with musl instead of bionic (or glibc in the case of Mer), but for
Android app
Post by Jens Staal
(those built with NDK) compatibility, one would then need libhybris.
right now just thinking aloud - no real plans at the moment :)
While I haven't look at the details for how it works, I'm fairly
doubtful that using libhybris would be practical. My guess is that
you'll find it fairly glibc-specific, but perhaps more importantly I'm
not sure what benefit you would get from having apps built against
Bionic using musl. If you have particular aims in mind, let me know,
but my feeling is that it would be a lot more practical to just fix up
the things Bionic is doing that are gratuitously different/broken to
get to a point where programs using Bionic run cleanly side by side
with musl. But if the issue is binary apps using native NDK code with
the Bionic ABI, but where you want the non-native code to run on a
musl-linked Dalvik rather than a Bionic-linked one, and if this all
takes place in the same process context, then maybe something like
libhybris really is needed.
I'm quite interested in this project as a prototype for how Android
could be moved from Bionic to musl, and (optionally, but I think this
is the right direction) steered back from its gratuitous
incompatibilities in filesystem layout, handling of dns, user/group
lookups, etc. and re-unified with Linux. Please keep us informed if
you make any interesting progress!
Rich
Rich Felker
2014-09-02 08:34:37 UTC
Permalink
Post by Wermut
We used libhybris for one single thing. Getting Android/bionic linked
graphic drivers up and running under embedded glibc linux. Since all the
hardware vendors startet to only deliver their drivers in binary form and
exclusivly for Android, these is usually the only way to get GPU up and
running.
libhybris was originally developed for Sailfish OS that is using Android
drivers of all kind under a glibc enviroment. The graphic Stack is Android
OpenGL driver > libhybris > wayland. Other projects like the Intel/Samsung
"mer" project is doing exactly the same.
If you are interessted how to install and use it, there is a rudimentary
http://www.cnx-software.com/2013/04/21/how-to-use-libhybris-and-android-gpu-libraries-with-mer-linux-on-the-cubieboard/
This thing is a therible hack, but unfortunatly this is often the only way
to get things like OpenGL, hw video decoding etc. working on embedded arm
linux. There are no signs that companies like Qualcom or ARM themself with
their Mali GPU will deliver open source drivers.
Linking your own apps to bionic/libhybris makes absolutly no sense. The
reason for libhybris is to use bionic binaries (drivers) within glibc based
enviroments.
How does this work when the binary driver is accessing the same symbol
names (mainly standard functions, but not necessarily) as the program
the driver is loaded into, but the latter needs the real versions in
libc and only the former should be routed through a hack layer?

Rich
Wermut
2014-09-02 09:25:20 UTC
Permalink
I think the following blog post explains the concept nicely:
http://groleo.wordpress.com/2013/07/22/brief-intro-to-libhybris/

I simply overrites the bionic symbols and provides glibc compatible calls.
This solution works very nicely, but can have problems if threading is
involved.

Also good references from the original creator of libhybris:
http://mer-project.blogspot.fi/2013/04/wayland-utilizing-android-gpu-drivers.html
http://mer-project.blogspot.fi/2013/05/wayland-utilizing-android-gpu-drivers.html
Post by Jens Staal
Post by Wermut
We used libhybris for one single thing. Getting Android/bionic linked
graphic drivers up and running under embedded glibc linux. Since all the
hardware vendors startet to only deliver their drivers in binary form and
exclusivly for Android, these is usually the only way to get GPU up and
running.
libhybris was originally developed for Sailfish OS that is using Android
drivers of all kind under a glibc enviroment. The graphic Stack is
Android
Post by Wermut
OpenGL driver > libhybris > wayland. Other projects like the
Intel/Samsung
Post by Wermut
"mer" project is doing exactly the same.
If you are interessted how to install and use it, there is a rudimentary
http://www.cnx-software.com/2013/04/21/how-to-use-libhybris-and-android-gpu-libraries-with-mer-linux-on-the-cubieboard/
Post by Wermut
This thing is a therible hack, but unfortunatly this is often the only
way
Post by Wermut
to get things like OpenGL, hw video decoding etc. working on embedded arm
linux. There are no signs that companies like Qualcom or ARM themself
with
Post by Wermut
their Mali GPU will deliver open source drivers.
Linking your own apps to bionic/libhybris makes absolutly no sense. The
reason for libhybris is to use bionic binaries (drivers) within glibc
based
Post by Wermut
enviroments.
How does this work when the binary driver is accessing the same symbol
names (mainly standard functions, but not necessarily) as the program
the driver is loaded into, but the latter needs the real versions in
libc and only the former should be routed through a hack layer?
Rich
Rich Felker
2014-09-03 22:35:53 UTC
Permalink
Post by Wermut
http://groleo.wordpress.com/2013/07/22/brief-intro-to-libhybris/
I simply overrites the bionic symbols and provides glibc compatible calls.
This solution works very nicely, but can have problems if threading is
involved.
http://mer-project.blogspot.fi/2013/04/wayland-utilizing-android-gpu-drivers.html
http://mer-project.blogspot.fi/2013/05/wayland-utilizing-android-gpu-drivers.html
I didn't find any of those links terribly informative for
understanding the aspects of _how it works_ that I'm unclear on --
particularly, how it deals with the fact that the symbols it wants to
override for bionic-linked DSOs have the same names as existing
symbols from the system libc that need to be left visible.

Rich
Rich Felker
2014-09-03 22:59:17 UTC
Permalink
Post by Rich Felker
Post by Jens Staal
Hi
Has anyone tried if libhybris will emulate the bionic libc properly on top of
musl libc? Alternatively, are there plans for bionic binary/source
compatibility in musl like the glibc compatibility (or would this contribute
to bloat?).
I was mostly curious to look into the possiblility of building AOSP (or Mer)
with musl instead of bionic (or glibc in the case of Mer), but for Android app
(those built with NDK) compatibility, one would then need libhybris.
right now just thinking aloud - no real plans at the moment :)
While I haven't look at the details for how it works, I'm fairly
doubtful that using libhybris would be practical. My guess is that
After writing this, I had some more ideas based on recent discussions
on #musl that were not particularly related to Bionic drivers, but
rather the problems with existing FOSS and binary-ware drivers for
non-mobile hardware, such as the nvidia drivers, which some users are
presently working on using with musl's glibc-ABI-compatibility.

Basically, my view, as expressed many times on #musl, is that all of
the existing GL drivers, but especially the non-free ones, are full of
way too much bad code to be safe to load into your program's address
space. Any process that's loaded them should be treated as potentially
crashing or aborting at any time, and possibly also has serious
namespace pollution from random libs getting pulled in.

The way I'd like to see this solved for our "new platform vision" is
to move the actual GL implementation out of the address space of the
application using it, and instead provide a universal libGL for
applications to link (even statically, if desired) that marshals all
GL operations over shared-memory-based IPC to a separate process which
has loaded the actual driver for the target hardware you want to
render to. As long as the IPC tools used don't depend on a particular
libc's ABI at all, this should make it trivial to solve the problem
libhybris aimed to solve at the same time: you simply use Bionic in
the GL driver process, and your preferred libc with the application
side libGL.


Rich
Isaac Dunham
2014-09-04 15:17:09 UTC
Permalink
Post by Rich Felker
Basically, my view, as expressed many times on #musl, is that all of
the existing GL drivers, but especially the non-free ones, are full of
way too much bad code to be safe to load into your program's address
space. Any process that's loaded them should be treated as potentially
crashing or aborting at any time, and possibly also has serious
namespace pollution from random libs getting pulled in.
The way I'd like to see this solved for our "new platform vision" is
to move the actual GL implementation out of the address space of the
application using it, and instead provide a universal libGL for
applications to link (even statically, if desired) that marshals all
GL operations over shared-memory-based IPC to a separate process which
has loaded the actual driver for the target hardware you want to
render to. As long as the IPC tools used don't depend on a particular
libc's ABI at all, this should make it trivial to solve the problem
libhybris aimed to solve at the same time: you simply use Bionic in
the GL driver process, and your preferred libc with the application
side libGL.
I saw an implementation of GL based on this design or something very
similar recently.
The point the developer had was to make a GL that could be statically
linked and handle remote rendering.

Ah yes, there it is:
https://github.com/msharov/gleri
"Network protocol, service, and API for using OpenGL remotely."

HTH,
Isaac Dunham
Rich Felker
2014-09-04 15:55:46 UTC
Permalink
Post by Isaac Dunham
Post by Rich Felker
Basically, my view, as expressed many times on #musl, is that all of
the existing GL drivers, but especially the non-free ones, are full of
way too much bad code to be safe to load into your program's address
space. Any process that's loaded them should be treated as potentially
crashing or aborting at any time, and possibly also has serious
namespace pollution from random libs getting pulled in.
The way I'd like to see this solved for our "new platform vision" is
to move the actual GL implementation out of the address space of the
application using it, and instead provide a universal libGL for
applications to link (even statically, if desired) that marshals all
GL operations over shared-memory-based IPC to a separate process which
has loaded the actual driver for the target hardware you want to
render to. As long as the IPC tools used don't depend on a particular
libc's ABI at all, this should make it trivial to solve the problem
libhybris aimed to solve at the same time: you simply use Bionic in
the GL driver process, and your preferred libc with the application
side libGL.
I saw an implementation of GL based on this design or something very
similar recently.
The point the developer had was to make a GL that could be statically
linked and handle remote rendering.
https://github.com/msharov/gleri
"Network protocol, service, and API for using OpenGL remotely."
While interesting, it could potentially require a lot of work to adapt
this to something practical. My intent is for the performance to be as
close as possible to current performance with the buggy, insecure
design people are using, because the closer it is, the better chance
it has of displacing the utterly idiotic system people are using now.

For example, IPC via shared memory should be as the primary mechanism
(rather than sockets) for all large or low-latency transfers, and I
also want to be able to pass the fd used for mapping GPU buffers
across a socket to the application to allow it to directly map this
buffer, assuming my information is correct that nothing there needs to
be validated (my understanding is that it contains data to be
processed by shaders on the GPU which run without privileges to do any
harm). Of course compiling shaders should take place on the driver
process side, so that applications cannot bypass the shader compiler
and submit their own potentially malicious compiled code which would
be difficult to validate.

These issues were discussed a lot more on IRC. I admit freely to not
being an expert on current graphics technology, so I may have
misconceptions on some details. But independent of this, it's obvious
that the current architecture of loading drivers into applications is
an utter disaster from a security and robustness standpoint. My hope
is that it can be fixed at a cost that's not noticable to most users,
but it really needs to be fixed at any cost.

Rich
u***@aetey.se
2014-09-04 07:25:20 UTC
Permalink
Post by Rich Felker
way too much bad code to be safe to load into your program's address
space. Any process that's loaded them should be treated as potentially
crashing or aborting at any time, and possibly also has serious
namespace pollution from random libs getting pulled in.
The way I'd like to see this solved for our "new platform vision" is
to move the actual GL implementation out of the address space of the
application using it, and instead provide a universal libGL for
applications to link (even statically, if desired) that marshals all
GL operations over shared-memory-based IPC to a separate process which
has loaded the actual driver for the target hardware you want to
render to.
IMHO this is how the shared libs concept should have been implemented
from the very beginning. An (efficient) IPC is so much better in the
long run than allowing everything to every module and hoping that it
knows what it does (far from the reality) and of course that it does
not abuse its powers (not extremely reliable).

There has been plenty of research around microkernels vs monolithic but
regrettably I am not aware of corresponding research for libraries as
IPC versus the monolithic ones.

Rune
u***@aetey.se
2014-09-04 08:05:24 UTC
Permalink
Post by u***@aetey.se
IMHO this is how the shared libs concept should have been implemented
from the very beginning.
Not shared libs in general, but for "arbitrary pluggable modules to
inject into arbitrary programs to extend their functionality", yes.
Indeed, it is using the shared libs technology for purposes where it is
not a suitable tool which made it harmful.
Another clear example where this is needed is PAM. The idea of loading
Sure, it was a brain-dead design from the beginning, otherwise also the
nsswitch and even perl's and python's and gtk's ".so" modules and the
non-GL X11 drivers too - the examples are unfortunately too numerous.

Why do misleading concepts become so popular so easily?
(NFS comes to mind as an impressive non-library example).

Probably because they solve a problem of the day - who cares if they
create a problem of a decennium or two... Sigh.

Rune

Loading...