public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug dynamic-link/23240] LD_PRELOAD doesn't work with non-lazy binding and IFUNC
       [not found] <bug-23240-131@http.sourceware.org/bugzilla/>
@ 2021-08-10 17:29 ` i at maskray dot me
  0 siblings, 0 replies; only message in thread
From: i at maskray dot me @ 2021-08-10 17:29 UTC (permalink / raw)
  To: glibc-bugs

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

Fangrui Song <i at maskray dot me> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |i at maskray dot me

--- Comment #7 from Fangrui Song <i at maskray dot me> ---
[A copy-pastable form.]

cat > main.c <<eof
  extern void bar (char *, const char *, unsigned int);
  int main () {
    char dst[50];
    const char src[] = "This is a test";
    bar (dst, src, sizeof (src));
    if (__builtin_memcmp (dst, src, sizeof (src)) != 0)
      __builtin_abort ();
    return 0;
  }
eof
cat > bar.c <<eof
  void bar (char *dst, const char *src, unsigned int size) {
    __builtin_memmove (dst, src, size);
  }
eof
cat > memmove.c <<eof
  #include <stddef.h>
  void * my_memmove(void *dst_p, const void *src_p, size_t n) {
    const char *src = src_p;
    char *dst = dst_p;
    char *ret = dst;
    if (src < dst)
      {
        dst += n;
        src += n;
        while (n--)
        *--dst = *--src;
      }
    else
      while (n--)
        *dst++ = *src++;
    return ret;
  }

  void *memmove (void *, const void *, size_t)
    __attribute__ ((ifunc ("resolve_memmove")));

  typedef void *(*memmove_t) (void *, const void *, size_t);
  static memmove_t resolve_memmove (void) { return my_memmove; }
eof

gcc -O2 -g -fPIC -shared  -o libbar.so bar.c
gcc -o x -O2 main.c libbar.so -Wl,-R,.
gcc -O2 -g -fPIC -shared  -o libmemmove.so memmove.c
exit

% ./x
% LD_PRELOAD=./libmemmove.so ./x
% LD_PRELOAD=./libmemmove.so LD_BIND_NOW=1 ./x
./x: Relink `./libbar.so' with `./libmemmove.so' for IFUNC symbol `memmove'
[1]    2623256 segmentation fault  LD_PRELOAD=./libmemmove.so LD_BIND_NOW=1 ./x

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-10 17:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-23240-131@http.sourceware.org/bugzilla/>
2021-08-10 17:29 ` [Bug dynamic-link/23240] LD_PRELOAD doesn't work with non-lazy binding and IFUNC i at maskray dot me

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