public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Geoff Keating <geoffk@ozemail.com.au>
To: Franz.Sirl-kernel@lauterbach.com
Cc: binutils@sourceware.cygnus.com, drow@false.org
Subject: Re: R_PPC_LOCAL24PC c++ linking problems with current binutils
Date: Mon, 19 Jul 1999 19:30:00 -0000	[thread overview]
Message-ID: <199907200217.MAA09776@geoffk.wattle.id.au> (raw)
In-Reply-To: <99072000221900.00843@ns1102.munich.netsurf.de>

> From: Franz Sirl <Franz.Sirl-kernel@lauterbach.com>
> Date: Tue, 20 Jul 1999 00:07:53 +0200
> Cc: drow@false.org, geoffk@ozemail.com.au
> 
> Hi,
> 
> linking this little program currently fails on Linux/PPC, glibc-2.1:
> 
> mmaptest.cc:
> #include <string>
> class FileFd
> {
> public:
>    int iFd;
>    unsigned long Flags;
>    string FileName;
> 
> 
>    FileFd(int Fd,bool) : iFd(Fd), Flags(0) {};
>    virtual ~FileFd();
> };
> 
> 
> Compiling with c++ -o mmaptest.so -fPIC -shared mmaptest.cc gives:
> mmaptest.o: In function `__default_alloc_template<true, 0>::_S_chunk_alloc(unsigned int, int &)':
> mmaptest.o(.__default_alloc_template<true, 0>::gnu.linkonce.t._S_chunk_alloc(unsigned int, int &)+0x234): undefined reference to `__default_alloc_template<true, 0>::_S_chunk_alloc(unsigned int, int &)'
> mmaptest.o(.__default_alloc_template<true, 0>::gnu.linkonce.t._S_chunk_alloc(unsigned int, int &)+0x2a8): undefined reference to `__default_alloc_template<true, 0>::_S_chunk_alloc(unsigned int, int &)'
> collect2: ld returned 1 exit status

OK, I see it.

The problem is that the following is happening:

1. g++ is defining the symbol 
 '__default_alloc_template<true, 0>::_S_chunk_alloc(unsigned int, int &)'
   (in demangled form, which I'll just call `...' from now on :-)
   weak in a linkonce section.
2. In libstdc++.so, the symbol is not defined weak.
3. In the same linkonce section, there is 'bl ...@local'.  The @local
   is because it's a recursive call.
4. ld finds the strong definition, in the shared object.
5. The symbol is not therefore defined locally, and linking fails.
  
I assume ld is correct in emitting the linkonce section even though
it will actually be using the shared object symbol.  I may be wrong.
Certainly it doesn't seem to make much sense to do this.

Other fixes would be:
(i) define the libstdc++ symbol weak, and/or
(ii) don't use @local on weak symbols and/or 
(iii) make @local relocs point to the symbol defined in this object
whether or not there is a stronger definition elsewhere.

(ii) implies that it is not legal to have a weak nested procedure (at
present the register used for the static chain conflicts with
registers clobbered in the PLT), but I'm not sure this makes sense
anyway.

(iii) might be hard.  It means we have to keep track of multiple
symbol definitions in ld.  It is probably also the correct solution
:-(.

Note that it is not valid to just ignore the @local, because calling
through the PLT is allowed to trash certain registers and @local is
not.

-- 
Geoffrey Keating <geoffk@cygnus.com> <geoffk@ozemail.com.au>

  parent reply	other threads:[~1999-07-19 19:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-19 15:21 Franz Sirl
1999-07-19 16:49 ` Ian Lance Taylor
1999-07-19 17:49   ` Daniel Jacobowitz
1999-07-19 19:56     ` Ian Lance Taylor
1999-07-19 20:07   ` Daniel Jacobowitz
1999-07-20  9:33     ` Ian Lance Taylor
1999-07-19 19:30 ` Geoff Keating [this message]
1999-07-19 20:05   ` Daniel Jacobowitz
1999-07-20  9:43   ` Ian Lance Taylor

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=199907200217.MAA09776@geoffk.wattle.id.au \
    --to=geoffk@ozemail.com.au \
    --cc=Franz.Sirl-kernel@lauterbach.com \
    --cc=binutils@sourceware.cygnus.com \
    --cc=drow@false.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).