public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "atgraham at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/33169]  New: Compiler generates two different relocs for the same symbol
Date: Thu, 23 Aug 2007 22:45:00 -0000	[thread overview]
Message-ID: <bug-33169-12114@http.gcc.gnu.org/bugzilla/> (raw)

The compiler generates two different relocs for the same function call, which
causes the linker to get confused.

----- Input -----
#include "pthread.h"
#include <map>
#include <ext/pool_allocator.h>
typedef __gnu_cxx::__pool_alloc<std::pair<int const, int> > myalloc;
int main() {
  std::map<int, int, std::less<int>, myalloc> y;
  pthread_mutex_lock(0);
}
-----------------
build with:
  mipsel-linux-g++ -Os -fno-inline -c foo.cc
(No command line flags are required; they don't appear to make a difference,
but the examples here will reflect those above.)

In this code chunk, pthread_mutex_lock is called from two places.  The first is
from inside the allocator, the second is directly in main.  From the allocator,
a R_MIPS_GOT16/R_MIPS_LO16 reloc is generated.  From main(), a R_MIPS_CALL16
reloc is generated.

0000001c <__gthread_mutex_lock(pthread_mutex_t*)>:
  1c:   3c1c0000        lui     gp,0x0
                        1c: R_MIPS_HI16 _gp_disp
  20:   279c0000        addiu   gp,gp,0
                        20: R_MIPS_LO16 _gp_disp
  24:   0399e021        addu    gp,gp,t9
  28:   27bdffe0        addiu   sp,sp,-32
  2c:   afbf001c        sw      ra,28(sp)
  30:   afb00018        sw      s0,24(sp)
  34:   afbc0010        sw      gp,16(sp)
  38:   8f990000        lw      t9,0(gp)
                        38: R_MIPS_GOT16        .text
  3c:   27390000        addiu   t9,t9,0
                        3c: R_MIPS_LO16 .text
  40:   0320f809        jalr    t9
  44:   00808021        move    s0,a0
  48:   10400008        beqz    v0,6c
<__gthread_mutex_lock(pthread_mutex_t*)+0x
50>
  4c:   8fbc0010        lw      gp,16(sp)
  50:   8f990000        lw      t9,0(gp)
                        50: R_MIPS_GOT16        pthread_mutex_lock
  54:   02002021        move    a0,s0
  58:   8fbf001c        lw      ra,28(sp)
  5c:   8fb00018        lw      s0,24(sp)
  60:   27390000        addiu   t9,t9,0
                        60: R_MIPS_LO16 pthread_mutex_lock
  64:   03200008        jr      t9
  68:   27bd0020        addiu   sp,sp,32
  6c:   8fbf001c        lw      ra,28(sp)
  70:   8fb00018        lw      s0,24(sp)
  74:   03e00008        jr      ra
  78:   27bd0020        addiu   sp,sp,32

000000dc <main>:
  dc:   3c1c0000        lui     gp,0x0
                        dc: R_MIPS_HI16 _gp_disp
  e0:   279c0000        addiu   gp,gp,0
                        e0: R_MIPS_LO16 _gp_disp
  e4:   0399e021        addu    gp,gp,t9
  e8:   27bdffc8        addiu   sp,sp,-56
  ec:   afbf0034        sw      ra,52(sp)
  f0:   afb00030        sw      s0,48(sp)
  f4:   afbc0010        sw      gp,16(sp)
  f8:   8f990000        lw      t9,0(gp)
                        f8: R_MIPS_CALL16       std::map<int, int,
std::less<int
>, __gnu_cxx::__pool_alloc<std::pair<int const, int> > >::map()
  fc:   27b00018        addiu   s0,sp,24
 100:   0320f809        jalr    t9
 104:   02002021        move    a0,s0
 108:   8fbc0010        lw      gp,16(sp)
 10c:   8f990000        lw      t9,0(gp)
                        10c: R_MIPS_CALL16      pthread_mutex_lock
 110:   0320f809        jalr    t9
 114:   00002021        move    a0,zero
 118:   8fbc0010        lw      gp,16(sp)
 11c:   8f990000        lw      t9,0(gp)
                        11c: R_MIPS_CALL16      std::map<int, int,
std::less<int
>, __gnu_cxx::__pool_alloc<std::pair<int const, int> > >::~map()
 120:   0320f809        jalr    t9
 124:   02002021        move    a0,s0
 128:   8fbc0010        lw      gp,16(sp)
 12c:   8fbf0034        lw      ra,52(sp)
 130:   8fb00030        lw      s0,48(sp)
 134:   00001021        move    v0,zero
 138:   03e00008        jr      ra
 13c:   27bd0038        addiu   sp,sp,56

When the linker sees the R_MIPS_CALL16, it decides that a PLT entry should be
generated for the symbol, and thusly changes its object-modification behavior
for *all* invocations of the function.  The R_MIPS_CALL16 relocs are then
linked correctly, but the R_MIPS_GOT16 are linked incorrectly.

This is just as likely a bug in the linker as it is in the compiler, but gcc
4.0.0 (the only other version I have tested) doesn't have this problem.  It is
more consistent and generates R_MIPS_CALL16 in both cases.  If this is not a
bug in the compiler, I'll report to binutils.


-- 
           Summary: Compiler generates two different relocs for the same
                    symbol
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: atgraham at gmail dot com
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: mipsel-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33169


             reply	other threads:[~2007-08-23 22:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-23 22:45 atgraham at gmail dot com [this message]
2007-08-24  0:40 ` [Bug c++/33169] " atgraham at gmail dot com
2007-08-24  9:23 ` [Bug target/33169] " pinskia at gcc dot gnu dot org
2007-08-24 16:01 ` atgraham at gmail dot com
2007-08-24 16:07 ` pinskia at gcc dot gnu dot org
2007-08-24 16:12 ` atgraham at gmail dot com
2007-08-24 16:17 ` pinskia at gcc dot gnu dot org
2007-08-24 16:34 ` atgraham at gmail dot com
2007-09-06 18:25 ` rsandifo at gcc dot gnu dot org
2007-10-03  5:31 ` atgraham at gmail dot com
2007-10-22 20:11 ` rsandifo at gcc dot gnu dot org
2007-10-22 20:15 ` rsandifo at gcc dot gnu dot org

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=bug-33169-12114@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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).