Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
xenomai --wrap inconsistency
We are using firmware version 1.5.8.

We have a Background C Program that uses a socket to communicate with a remote machine. The generated Makefile for this program includes a bunch of "-Wl,--wrap,xxx" options including wrapping socket, open, recvmsg, etc. My supposition is that we should be using the xenomai versions of these functions (though I'm not really sure why).

However, the actual socket code is located in a Library that the program links to. Oddly, the generated library makefile is missing all these --wrap options, so we are presumably not using the xenomai wrapped functions after all. Will this cause us any trouble?

The code seems to work, though occasionally it will lock up. Sometimes this hang is followed by a hard watchdog, but sometimes not. Could the missing wrapping have anything to do with this?

Another odd thing: select() is wrapped, but not pselect(). We use the latter to wait on the socket as well as two FIFOs sending data from an RTI CPLC. Is this a concern? We actually don't use the signal masking, so we could revert to simple select().
smr99: The wrap statements force the linker to use the Xenomai functions instead of the standard posix functions. See

To figure out what is causing the hard watchdog, plug a serial cable into the serial port and you should get a debug output when the processor crashes. This can help you troubleshoot what the problem is and where it is occurring. I can't say more without seeing your code.

Regarding pselect(), off the top of my head I don't think Xenomai has a wrapper for that function (which explains why it isn't wrapped).
(06-19-2014, 03:39 PM)shansen Wrote: Shared libraries do not need the wrap statements. However, applications that call the shared libraries DO need the wrap statements.

That is the root of the inconsistency: if I were to directly call socket() in my background program, it would use the wrapped function; but within the library, it uses the unwrapped socket(). Thus the behaviour is different. Why?

(06-19-2014, 03:39 PM)shansen Wrote: Regarding pselect(), off the top of my head I don't think Xenomai has a wrapper for that function (which explains why it isn't wrapped).

Correct. But select() and pselect() are basically identical in function if you don't use signal masking (as we don't). So again there's a change in behaviour if I choose pselect() over select(). It seems to me if Xenomai needs to wrap one, there's some chance that using the unwrapped alternative may confuse Xenomai.

EDIT: My comment was backwards! It depends on how the LIBRARY was linked, not how the program was linked.

If you call pselect(), your code will momentarily be switched from primary mode to secondary mode. If that is not desired behavior, then you should use select() and wrap it in your library's linker flags.
(06-20-2014, 11:59 AM)shansen Wrote: smr99:

There are two possible cases:

Case 1) A background program linked without wrap flags calls your shared library, which calls socket(). Because the program did not have wrap flags, the socket() function will not be wrapped.

Case 2) A background program linked WITH wrap flags calls your shared library, which calls socket(). Now the program was linked with wrap flags, so the socket() function is wrapped by Xenomai.

In other words, it depends on how the program was linked, not how the library was linked (this only applies to shared libraries, not to static libraries).

OK. So to understand better, I tried replicating this in a simple test case where I have code that uses open() both in the main program and in a shared library (liba), linked together with a second library (libb) that provides __wrap_open(). I built both with/without --wrap and what I observe is that only the main program call is wrapped. The shared library function myopen() does NOT call the wrapped open().

Perhaps I've missed something subtle. The attached tarball shows my experiment.

Attached Files
.gz   ld-wrap.tar.gz (Size: 678 bytes / Downloads: 4)
OK smr99, I just re-read my previous comments and I typed it backwards!

If you link liba with --wrap=open, calls to open() via the library will be wrapped regardless of whether or not the program was linked with --wrap. BUT, if the same program calls open() directly (e.g. not through the library) and the program was compiled without --wrap, open() will not be wrapped.

So, the --wrap argument goes with whatever is actually calling the function (be it library or program). If you are directly calling the function from BOTH library and program and want it to be wrapped in all cases, both need to have the --wrap argument.

So back to your original point: if you want your libraries to call the Xenomai wrapped POSIX functions, make sure your Makefiles for the libraries include the --wrap argument.
(06-23-2014, 12:37 PM)shansen Wrote: OK smr99, I just re-read my previous comments and I typed it backwards!

OK. I think we agree now. Thanks!

Forum Jump:

Users browsing this thread: 1 Guest(s)