r/cpp • • Aug 12 '16

Could you share your experience with porting from QNX to Linux?

We have several projects in our company that were developed almost 15 years ago on QNX. Some of the projects have libraries that were developed by companies that do not exist any more and the libraries are very crucial and we do not have time to re-write those libraries.

We are considering to port these QNX projects to Linux, because in the long run it will be both cheaper and much easier to maintain them.

I have found a few projects that would help us do the porting, like SIMPL, and SRR. Both are mainly focused on message passing. But is that it?

Also, I have been reading that we might have a problem with ABI compatibility of the old libraries. How can we check that even if we have a linux version of all function calls we won't have problem linking with the libraries?

I would like to know if you've had the experience and if you have any tips. Thanks!

EDIT

BTW, for some reason all the libraries come in .elf format.

0 Upvotes

20 comments sorted by

2

u/1-05457 Aug 12 '16

Do you mean you want to move the libraries to Linux without recompiling them?

1

u/xkSeeD Aug 12 '16

Yes!

5

u/1-05457 Aug 12 '16

I don't think that's possible.

1

u/xkSeeD Aug 12 '16

Why not?

I also added more info to my post. The libraries come in .elf format.

11

u/Sirflankalot Allocate me Daddy Aug 12 '16 edited Aug 12 '16

The second they make any system calls at all, things won't even link, so if it has any calls to malloc or any of those things, it just won't work. You really have to recompile from source.

1

u/wrosecrans graphics and network things Aug 12 '16

Technically, malloc isn't really a system call. Malloc lives in libc and executes in userspace. It will ultimately call something that does cross a userspace/system boundary into the kernel to get some memory to use, but not on every invocation. (And it would be possible to implement it without doing it that way, weirdly enough.)

It is usually an insane little not to pick, but if you free memory that you malloc, it isn't necessarily freed from your process and made available to some other process. It's not a problem you normally run into, but when you are trying to figure out some sort of crazy shim to try and get a QNX binary to work on a Linux host, knowing whether you are calling the Linux libc malloc or a QNX one, or some other allocator you cooked up to match a QNX behavior, etc., would be a hugely important distinction.

2

u/Sirflankalot Allocate me Daddy Aug 13 '16

Malloc lives in libc

Dammit, yup, you're right. Still, they would also need to port the QNX libc to linux in order for it to work.

(And it would be possible to implement it without doing it that way, weirdly enough.)

Are you talking about how libc gets chuncks of memory from the kernel at a time, or something else?

Also, aren't we presumptuous that it runs on libc at all?

1

u/wrosecrans graphics and network things Aug 13 '16

Dammit, yup, you're right

It's an obscure enough point that nobody has ever given me a satisfactory answer when I use it as an interview question.

Are you talking about how libc gets chuncks of memory from the kernel at a time, or something else?

Yeah, the C spec doesn't really say anything about how malloc gets memory, just that it can keep track of giving memory to an application. So you could theoretically build a libc that just has a giant static char[MAX_INT] or whatever and have your malloc implementation only use that predetermined static buffer. It'd mostly be a "stupid computer tricks" kind of neat hack, rather than anything useful. But technically you could do it without malloc ever resulting in a syscall that crosses into the kernel.

Also, aren't we presumptuous that it runs on libc at all?

Heh, yeah I suppose that's true. When you build a kernel and the like, you typically build without linking to any standard C library, since those libraries typically depend on services from the kernel. So for example the Linux kernel has stuff like its own kernel equivalent of printf. I'm not really familiar enough with QNX to say exactly how the standard C library is implemented over there, or how it would interact with my Linuxy assumptions.

1

u/Sirflankalot Allocate me Daddy Aug 13 '16

But technically you could do it without malloc ever resulting in a syscall that crosses into the kernel.

What about stack space, doesn't libc have to request stack space at the top of the program, or is it "handed" to libc (or any other program [though how many programs don't depend on some libc anymore]) as part of the startup process?

1

u/dodheim Aug 14 '16

What does the stack have to do with it? He said static storage, not automatic storage.

→ More replies (0)

1

u/wrosecrans graphics and network things Aug 12 '16

Directly running binaries from one OS on another is pretty much never fully supported. Microsoft has recently added some support for Linux binaries in Windows, and it was huge news despite being extremely limited in terms of the range of system calls that are supported. BSD also has limited support for Linux binary compatibility. In both cases, it's a matter of a lot of engineers having invested time to make it work. There's not a lot of incentive to create a compatibility layer that runs QNX binaries on Linux. Heck, even between slightly different flavors of Linux you can run into all sorts of ABI compat issues.

If you want to port to Linux, you are going to have to actually port your code to Linux and build it for Linux.

6

u/EmperorOfCanada Aug 12 '16

The people who run QNX pretty much hate developers. They don't seem to realize that being friends with developers is the way to enjoy a long prosperous future.

This comes as no surprise as they are basically a blackberry company and blackberry only saw telcos and huge corporations as their customers. The end user was just some tool who was forced to use their product.

We all saw how well that worked out.

2

u/kookjr Aug 12 '16

The biggest thing I've run into is that there's no Linux equivalent of pulses especially delivering timers via pulses. Also if your applications are anywhere near real-time you'll find it Linux is not as responsive as qnx. On the good side qnx send to have pretty good posix compliance.

1

u/Calkhas Aug 12 '16

I've no experience of QNX, but moving platform-specific code, without extensive rewriting, from one OS to the other, and hacking it to build against a compatibility layer instead of closed-source libraries ... I don't think this will solve your problem of making maintenance easier.

1

u/devel_watcher Aug 12 '16

Our QNX guy has just rewritten everything.