All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Marco Barbosa <marcoafbarbosa@gmail.com>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai] Xenomai 2.6.4 segfault before main()
Date: Thu, 20 Aug 2015 18:33:00 +0200	[thread overview]
Message-ID: <20150820163300.GA3701@hermes.click-hack.org> (raw)
In-Reply-To: <CACwQX5PgaPA47Ak3gbNfSGJtAYhusP0QC4ZwNSSfd8_Y1wTRjA@mail.gmail.com>

On Thu, Aug 20, 2015 at 04:58:39PM +0100, Marco Barbosa wrote:
> Hi all,
> 
> while trying to build a xenomai app in a x86_64 debian 8.1 system I
> was getting segfaults before the program even gets into main(). After
> fiddling with this a bit, I built a minimal example which is really
> minimal.
> 
> Program is:
> 
> $ cat main.cpp
> 
> int
> main (int argn, char**argv)
> {
>   return 0;
> }
> 
> Which is compiled with the command:
> 
> g++ -L/usr/xenomai/lib -ggdb main.cpp -o main_xen -lxenomai -lpthread_rt
> 
> Now by running the program, I get:
> 
> $ ./main_xen
> Segmentation fault
> 
> Debugging with GDB gives this backtrace:
> 
> $ gdb ./main_xen
> [... snip ...]
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 0x7ffff7ff5700 (LWP 9389)]
> pthread_cond_wait@@GLIBC_2.3.2 () at
> ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:134
> 134     ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: No
> such file or directory.
> (gdb) bt
> #0  pthread_cond_wait@@GLIBC_2.3.2 () at
> ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:134
> #1  0x00007ffff7bd945f in printer_loop () from /usr/xenomai/lib/libxenomai.so.0
> #2  0x00007ffff6be90a4 in start_thread (arg=0x7ffff7ff5700) at
> pthread_create.c:309
> #3  0x00007ffff6ee404d in clone () at
> ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
> 
> Now if this is not weird enough, I just found out that if I reverse
> the order of those two libraries, i.e.:
> 
> g++ -L/usr/xenomai/lib -ggdb main.cpp -o main_xen -lpthread_rt -lxenomai
> 
> I will get no segfault in this situation, the program exits fine.
> 
> Does anyone have any idea of what is going on here? I would suspect
> that by switching library order, initialization of some static data
> which is done before entering main() is somehow affected and that can
> result in segfault if done in the wrong order.
> 
> Of course, this is a very simple example and I seem to have found a
> way around the problem, but in a more complex application with
> makefiles generated by CMake, I really have little control over the
> order in which libraries are declared and I am getting these segfaults
> all the time.

A makefile, whether cmake or make should use xeno-config to get the
libraries. And xeno-config puts -lxenomai last. I believe. So,
this is a non issue, unless you do things which the documentation
tells you not to do.

-- 
					    Gilles.
https://click-hack.org


      reply	other threads:[~2015-08-20 16:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-20 15:58 [Xenomai] Xenomai 2.6.4 segfault before main() Marco Barbosa
2015-08-20 16:33 ` Gilles Chanteperdrix [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150820163300.GA3701@hermes.click-hack.org \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=marcoafbarbosa@gmail.com \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.