This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/2683] dladdr() returns wrong symbol names in rare cases


------- Additional Comments From satoru at 0xcc dot net  2006-05-28 05:04 -------
(In reply to comment #1)
> Correct patch, I applied it to CVS.

Thank you for fixing the bug.

I just realized that completly skipping undefined references
could be a problem.  Consider the following code.

  #include <stdio.h>
  int main() {
      printf("%p\n", &printf);
      return 0;
  }

If I compile it without -fPIC on my machine (Debian GNU/Linux sarge on a x86_32
machine), 
&printf points to a memory address in PLT.

  % gcc test.c
  % ./a.out
  0x8048288

  % readelf -S a.out  |grep " \.plt"
  [11] .plt          PROGBITS        08048270 000270 000030 04  AX  0   0  4

The binary contains the undefined symbols for printf both in
.dysym and .symtab sections and the values of the undefined symbols
correspond to the memory address in PLT (0x8048288).

  % readelf --symbols a.out |grep printf
   2: 08048288    57 FUNC    GLOBAL DEFAULT  UND printf@GLIBC_2.0 (2)
  99: 08048288    57 FUNC    GLOBAL DEFAULT  UND printf@@GLIBC_2.0

Hence, to support dladdr(&printf, info) for non-pic binaries,
probably we need to allow the condition something like this as well.

  (ELFW(ST_TYPE) (symtab->st_info) == STT_FUNC
   && symtab->st_shndx == SHN_UNDEF
   && match->l_addr + symtab->st_value == addr)


On the other hand, if I compile the same code with -fPIC,
&printf points to the printf definition in the map of glibc.
There is no problem in this case for doing dladdr(&printf, info).

  % gcc -fPIC test.c
  % ./a.out
  0x4006e8e0

  % ldd a.out
        libc.so.6 => /lib/libc.so.6 (0x4001f000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
  % readelf --symbols /lib/libc.so.6|grep " printf"
   157: 0004f8e0    57 FUNC    GLOBAL DEFAULT   11       printf@@GLIBC_2.0

  % python
  >>> "%x" % (0x4001f000 + 0x0004f8e0)
  '4006e8e0'


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |


http://sourceware.org/bugzilla/show_bug.cgi?id=2683

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]