All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Gerum <rpm@xenomai.org>
To: yi li <liyi.dev@domain.hid>
Cc: Xenomai-core@domain.hid
Subject: Re: [Xenomai-core] [PATCH] blackfin: build xenomai in FLAT format
Date: Thu, 26 Feb 2009 12:12:01 +0100	[thread overview]
Message-ID: <49A67901.60506@domain.hid> (raw)
In-Reply-To: <a0e7fce50902260256o49ab88fcmbe6269b67b92aa5f@domain.hid>

yi li wrote:
> On Thu, Feb 26, 2009 at 6:20 PM, Gilles Chanteperdrix
> <gilles.chanteperdrix@xenomai.org> wrote:
>> -lpthread does need to be set in libpthread_rt_la_LDFLAGS, if you look
>> at libpthread_rt code (which you apparently do not want to dot), you
>> will see that it uses libpthread functions.
> 
> Thanks for the detailed explanation. And I did read libpthread_rt code ;).
> However, my point is _not_  putting "-lpthread" before or after
> "libpthread_rt.a". My point is, is it reasonable to put "-lpthread" in
> the LDFLAGS of libpthread_rt.a?
> 
>> The issue you have has already been discussed on this list, and we
>> already know the correct workaround. The correct workaround is not to
>> link with -lpthread first. Linking with -lpthread first leads to broken
>> binaries, whose libpthread functions call libpthread_rt functions. The
>> correct workaround is to link your binary in two stages, or to forget
>> about FLAT and use FDPIC.
> 
> In my option, a better workaround is to group the achieves, with
> "--start-group", "--end-group":
> 
> bfin-uclinux-gcc -pipe -Wall -g -O2 -mcpu=bf527-0.1
> -Wl,@/home/adam/new_workspace/local_svn/kernel/adeos/uclinux-dist/user/xenomai/xenomai-2.4.x/src/skins/posix/posix.wrappers
> -D_GNU_SOURCE -D_REENTRANT -Wall -pipe -Wl,-elf2flt -mcpu=bf527-0.1 -o
> cyclictest cyclictest-cyclictest.o  -lrt -Wl,--start-group
> ../../skins/posix/.libs/libpthread_rt.a -lpthread -Wl,--end-group
>

Yi, the point is about our use of the --wrap linker directive for linking POSIX
apps. If we go for the start/end group scheme, then we will end up having
libpthread wrongly use our wrapped libpthread calls from libpthread_rt, which is
going to break the application badly. This is the other way around: our wrappers
may want to use libpthread.

We just cannot let the linker pick whatever symbol it sees fit to resolve the
references, it is not a dependency order issue that start/end group would indeed
solve. When using a static link format, we have to make sure to resolve the
references the applications makes to libpthread_rt first, then, and only after
that, finalize the link with libpthread, because both the application and
libpthread_rt have dependencies on libpthread.

This is why we are talking about "two-phase" link for static mode. In fact,
fixing the issue your reported would require to implement two-phase link
conditionally in our Makefiles producing POSIX binaries, to be used when FLAT
format is wanted. This is doable, but requires a bit more work than just
reordering or removing dependencies on libpthread.

> -Yi
> 


-- 
Philippe.


  parent reply	other threads:[~2009-02-26 11:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-24  8:18 [Xenomai-core] [PATCH] blackfin: build xenomai in FLAT format yi li
2009-02-24 16:30 ` Philippe Gerum
2009-02-25  4:22   ` yi li
2009-02-25 10:23     ` Gilles Chanteperdrix
2009-02-26  6:21       ` yi li
2009-02-26 10:20         ` Gilles Chanteperdrix
2009-02-26 10:56           ` yi li
2009-02-26 11:01             ` Gilles Chanteperdrix
2009-02-26 11:12             ` Philippe Gerum [this message]
2009-02-27 10:02               ` yi li

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=49A67901.60506@domain.hid \
    --to=rpm@xenomai.org \
    --cc=Xenomai-core@domain.hid \
    --cc=liyi.dev@domain.hid \
    /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.