public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug dynamic-link/18411] New: Failure to resolve gnu indirect functions in library specified using LD_PRELOAD
@ 2015-05-13 18:43 bavisonpmbz at gmail dot com
  2015-07-11 13:04 ` [Bug dynamic-link/18411] " neleai at seznam dot cz
  0 siblings, 1 reply; 2+ messages in thread
From: bavisonpmbz at gmail dot com @ 2015-05-13 18:43 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=18411

            Bug ID: 18411
           Summary: Failure to resolve gnu indirect functions in library
                    specified using LD_PRELOAD
           Product: glibc
           Version: 2.13
            Status: NEW
          Severity: normal
          Priority: P2
         Component: dynamic-link
          Assignee: unassigned at sourceware dot org
          Reporter: bavisonpmbz at gmail dot com
  Target Milestone: ---

I have been writing a library to override certain glibc functions with
optimised versions. To achieve this, the new library is specified using
LD_PRELOAD or in /etc/ld.so.preload. This has been working fine, until I wanted
to have multiple different optimised versions for different architecture
variants, selected between using a gnu_indirect_function.

The problem is that sometimes, but not always, resolving the indirect function
leads to a segfault or bus error. It has proved very difficult to track down
the conditions under which this happens - something as complex as bringing up X
will definitely fail. Trying to find a simpler test case, I have identified
that the /usr/bin/man binary reliably triggers the bug. Unfortunately when I
built it from source, that version was unaffected, so I was unable to further
track down the trigger.

The simplified test case below is enough to trigger the bug for me:

::::::::::::::
lib.c
::::::::::::::
#include <string.h>

#define USE_INDIRECT_FUNCTION 1

#if USE_INDIRECT_FUNCTION

void *mymemcpy(void *__restrict dest, __const void *__restrict src, size_t n);

#ifdef __arm__
asm(".type " "memcpy" ", %gnu_indirect_function");
#else
asm(".type " "memcpy" ", @gnu_indirect_function");
#endif
typeof(memcpy) *memcpy_dispatch(void) __asm__("memcpy");
typeof(memcpy) *memcpy_dispatch(void)
{
    return mymemcpy;
}

#else

#define mymemcpy memcpy

#endif

void *mymemcpy(void *__restrict dest, __const void *__restrict src, size_t n)
{
  char       *d = dest;
  const char *s = src;
  while (n-- > 0)
    *d++ = *s++;
  return dest;
}
::::::::::::::
Makefile
::::::::::::::
test: lib.so
        LD_PRELOAD=./lib.so /usr/bin/man -h

clean:
        rm -f *.o *.so

%.o: %.c
        gcc -Wall -Wextra -O2 -g -c -o $@ $^

lib.so: lib.o
        gcc -shared -o $@ $^
::::::::::::::

If I set USE_INDIRECT_FUNCTION to 0, then it works correctly.

I'm targeting Raspbian - sorry, I know it's quite an old version of glibc:

Linux raspberrypi 3.18.7-v7+ #9 SMP PREEMPT Tue Feb 24 20:16:50 GMT 2015 armv7l
GNU/Linux
GNU C Library (Debian EGLIBC 2.13-38+rpi2+deb7u7) stable release version 2.13

I can generate the same errors on an old Ubuntu x86 install I have that is also
running glibc 2.13:

Linux ubuntu-11-10 3.0.0-32-generic #51-Ubuntu SMP Thu Mar 21 15:51:26 UTC 2013
i686 i686 i386 GNU/Linux
GNU C Library (Ubuntu EGLIBC 2.13-20ubuntu5.3) stable release version 2.13

Someone kindly provided me with some packages to update my Raspbian to glibc
2.19, and this didn't resolve the bug either.

Sorry if this has already been addressed in the bleeding-edge version of glibc.
If someone who is running it (ideally on an ARM) dares build the above and
point their /etc/ld.so.preload at it then manages to complete a full boot (or
not) then that would be interesting to hear.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug dynamic-link/18411] Failure to resolve gnu indirect functions in library specified using LD_PRELOAD
  2015-05-13 18:43 [Bug dynamic-link/18411] New: Failure to resolve gnu indirect functions in library specified using LD_PRELOAD bavisonpmbz at gmail dot com
@ 2015-07-11 13:04 ` neleai at seznam dot cz
  0 siblings, 0 replies; 2+ messages in thread
From: neleai at seznam dot cz @ 2015-07-11 13:04 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=18411

Ondrej Bilka <neleai at seznam dot cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |neleai at seznam dot cz

--- Comment #1 from Ondrej Bilka <neleai at seznam dot cz> ---
also reproduces on current x64.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-11 13:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-13 18:43 [Bug dynamic-link/18411] New: Failure to resolve gnu indirect functions in library specified using LD_PRELOAD bavisonpmbz at gmail dot com
2015-07-11 13:04 ` [Bug dynamic-link/18411] " neleai at seznam dot cz

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).