You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by prelude <wg...@163.com> on 2022/07/11 06:11:05 UTC

Can musl libc replace the libc of nuttx system?


I am currently working on a project that I want to transplant musl LIC to nuttx to replace the built-in libc, have any friends done similar work? I want to ask how to start.Thank you.

Re: Can musl libc replace the libc of nuttx system?

Posted by Tomek CEDRO <to...@cedro.info>.
On Tue, Jul 12, 2022 at 4:38 AM Xiang Xiao  wrote:
> musl is designed to work exclusively with Linux and then there is no OS
> abstraction layer. So it's hard to adapt musl to other OS.
> Alan asks a good question: what benefit do you want to get from replacing
> NuttX' libc with musl?

Just my 2 cents as BSD user (FreeBSD to be exact) so please stay cool :-)

Yes there are lots of "Open-Source" solutions that works only on Linux
by design. Some people do this because of ignorance, some people do it
on purpose. Life would be simpler when it has "Linux-Only" sticker on
top just to know what to avoid :-)

Linux was always known to be "most-self-incomatible-system-ever" but
gets more and more away from Unix world nowadays into "constant
change" "temporary solution" world. I don't know musl but it seems to
be yet another example of Linux-Only solution (to add Docker, SystemD
and all dependent programs). I am porting lots of Open-Source
applications and libraries to BSD and I know the problem pretty well.
It goes wrong direction with applause of the masses. Kind of
Closed-Open-Source.

People think that Open-Source is Linux, but Linux is only small part
of the Open-Source world. Because Linux starts to live in its own
world, there will be more and more problems of this kind. I was using
Linux since 2.0.36 and I stopped using around 2.4.11 when kernel API
started changing with every minor release. This is clearly "enforced
changes ideology" in practice. You cannot build anything solid on non
solid fundaments.

BSD is a good proving grounds for well designed portable Open-Source.
If you make something here it will still work in two years ;-) Give it
a try :-)

https://www.freebsd.org/ - versatile OS for Embedded, Desktop, Server
(supports ZFS, RISC-V, etc).
https://nomadbsd.org/ - USB drive portable version of FreeBSD.
https://www.openbsd.org/ - most secure OS ever.

-- 
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info

Re: Can musl libc replace the libc of nuttx system?

Posted by Nathan Hartman <ha...@gmail.com>.
On Thu, Jul 14, 2022 at 5:30 PM Alan Carvalho de Assis
<ac...@gmail.com> wrote:
>
> You are right, currently Apex RTOS and RT-Thread (only their "Smart
> brand" that only works on CPU with MMU) are using musl lib.
>
> So it could be useful to have musl support for NuttX.


Why not make NuttX libc as good as possible instead of introducing
different choices that will make maintenance more complicated?

Cheers,
Nathan

Re: Can musl libc replace the libc of nuttx system?

Posted by Alan Carvalho de Assis <ac...@gmail.com>.
On 7/14/22, Ismael Luceno <is...@iodev.co.uk> wrote:
> On 12/Jul/2022 10:38, Xiang Xiao wrote:
>> musl is designed to work exclusively with Linux and then there is no OS
>> abstraction layer. So it's hard to adapt musl to other OS.
>
> Not really, adapting to another kernel is as simple as either providing
> the missing syscalls, adding stubs, or emulating them.
>

You are right, currently Apex RTOS and RT-Thread (only their "Smart
brand" that only works on CPU with MMU) are using musl lib.

So it could be useful to have musl support for NuttX.

BR,

Alan

Re: Can musl libc replace the libc of nuttx system?

Posted by Ismael Luceno <is...@iodev.co.uk>.
On 12/Jul/2022 10:38, Xiang Xiao wrote:
> musl is designed to work exclusively with Linux and then there is no OS
> abstraction layer. So it's hard to adapt musl to other OS.

Not really, adapting to another kernel is as simple as either providing
the missing syscalls, adding stubs, or emulating them.

Re: Can musl libc replace the libc of nuttx system?

Posted by Xiang Xiao <xi...@gmail.com>.
musl is designed to work exclusively with Linux and then there is no OS
abstraction layer. So it's hard to adapt musl to other OS.
Alan asks a good question: what benefit do you want to get from replacing
NuttX' libc with musl?

On Tue, Jul 12, 2022 at 9:50 AM Alan Carvalho de Assis <ac...@gmail.com>
wrote:

> Hi Prelude,
>
> I don't think someone already tried it before.
>
> BTW, why do you want to do it?
>
> BR,
>
> Alan
>
> On Monday, July 11, 2022, prelude <wg...@163.com> wrote:
>
> >
> >
> > I am currently working on a project that I want to transplant musl LIC to
> > nuttx to replace the built-in libc, have any friends done similar work? I
> > want to ask how to start.Thank you.
>

Re: Can musl libc replace the libc of nuttx system?

Posted by Gregory Nutt <sp...@gmail.com>.
> > But there would be many, many smaller issues of compatibility with
> > header files, data structures, etc.  This effort would be complex,
> > invasive, and probably more work than anyone really would want to
> > commit to doing.
> > He said it would be like “a death from a thousand cuts.”
>
> It depends if such incompatibilities are regarded as bugs in NuttX;
> when it comes to musl, it tries to be standards-compliant, it won't
> accomodate for non-standard expectations in NuttX.
>
> There is no standard governing the interface between the C library and the
OS.  Standards like POSIX rather specify the interface between an
application and the C library.  The C library then interfaces to the OS via
non-standard system calls like
https://elixir.bootlin.com/linux/latest/source/include/linux/syscalls.h for
the case of Linux.

It is the lack of any standard at this level that Tomas Cedro was lamenting.

There is little compatibility between Linux and NuttX system calls.
Compare to
https://github.com/apache/incubator-nuttx/blob/master/syscall/syscall.csv.
The NuttX system calls are closer to the application interface standard but
not very close to Linux.

So when I mentioned compatibility between header files and data structures,
I was referring to the header files and data structures that define the
non-standard, OS system call interface used by the C library and not the
standard application interface provided by the C library.

Another complexity is that there are two C libraries, both in Linux and
NuttX:  One built into the kernel logic and one made available for use by
the applications.  So there are, for example, two strcpy()
implementations:  One for use within the kernel and one for use by
applications).  In Linux these are separate files within the OS; for NuttX,
the C library may be built twice (with different configuration options),
depending upon  the build mode.

Re: Can musl libc replace the libc of nuttx system?

Posted by Ismael Luceno <is...@iodev.co.uk>.
On 11/Jul/2022 21:10, Gregory Nutt wrote:
<...>
> MUSL supports only Linux.  Hopefully, the MUSL OS interface is
> well modularized to support use of a different OS.

Musl is well-structured, ports aren't difficult.

<...>
> But there would be many, many smaller issues of compatibility with
> header files, data structures, etc.  This effort would be complex,
> invasive, and probably more work than anyone really would want to
> commit to doing.
> He said it would be like “a death from a thousand cuts.”

It depends if such incompatibilities are regarded as bugs in NuttX;
when it comes to musl, it tries to be standards-compliant, it won't
accomodate for non-standard expectations in NuttX.

> If there is missing functionality in the NuttX LibC, most people
> would opt to extend the NuttX LibC, not port a different Libc.

OTOH, sharing code with other projects is generally a good thing,
specially with quality-conscious projects.

A libc is far more taxing than a kernel to develop and test in that it
must be compliant with a large body of standards to aid portability.

Re: Can musl libc replace the libc of nuttx system?

Posted by Gregory Nutt <sp...@gmail.com>.
People have talked about using other C libraries in the past, but no one
has been successful.



C libraries support an operating specific interface.  For example, a Linux
LibC will need to use Linux system calls and Linux data structures to
interface with the kernel.  A similar interface would be needed to work
with NuttX.  MUSL supports only Linux.  Hopefully, the MUSL OS interface is
well modularized to support use of a different OS.



Some things have very intense interactions such as C standard I/O and
buffered I/O.



A good contributor who is no longer associated with the NuttX project
looked into using newlib with NuttX 10 or 12 years ago and said that the
effort would be quite large.  It is technically feasible and there is no
known single show-stopping issue.  But there would be many, many smaller
issues of compatibility with header files, data structures, etc.  This
effort would be complex, invasive, and probably more work than anyone
really would want to commit to doing.  He said it would be like “a death
from a thousand cuts.”



If there is missing functionality in the NuttX LibC, most people would opt
to extend the NuttX LibC, not port a different Libc.



But if you are willing to put in a significant effort, then perhaps you
could be successful.  Since this would require the development of the OS
interface as part of MUSL,  it would not be a part of NuttX; it would be a
part of MUSL.  If you are serious about pursuing this, you really should be
discussing the effort with Rich Felker and the MUSL team.

On Mon, Jul 11, 2022 at 7:50 PM Alan Carvalho de Assis <ac...@gmail.com>
wrote:

> Hi Prelude,
>
> I don't think someone already tried it before.
>
> BTW, why do you want to do it?
>
> BR,
>
> Alan
>
> On Monday, July 11, 2022, prelude <wg...@163.com> wrote:
>
> >
> >
> > I am currently working on a project that I want to transplant musl LIC to
> > nuttx to replace the built-in libc, have any friends done similar work? I
> > want to ask how to start.Thank you.
>

Re: Can musl libc replace the libc of nuttx system?

Posted by Alan Carvalho de Assis <ac...@gmail.com>.
Hi Prelude,

I don't think someone already tried it before.

BTW, why do you want to do it?

BR,

Alan

On Monday, July 11, 2022, prelude <wg...@163.com> wrote:

>
>
> I am currently working on a project that I want to transplant musl LIC to
> nuttx to replace the built-in libc, have any friends done similar work? I
> want to ask how to start.Thank you.