Under gdb, I can see that the libfoo.so.1 library is loaded:
$ LD_PRELOAD=$(realpath ./libfoo.so.1 ) gdb ./a.out
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "powerpc64le-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...(no debugging symbols found)...done.
(gdb) sta
Temporary breakpoint 1 at 0x10000a24
Starting program: /home/acm/opt/src/1640518/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/powerpc64le-linux-gnu/libthread_db.so.1".
Temporary breakpoint 1, 0x0000000010000a24 in main ()
(gdb) info inferior
Num Description Executable
* 1 process 14046 /home/acm/opt/src/1640518/a.out
(gdb) !lsof -p 14046 | grep lib
a.out 14046 amorrow mem REG 8,2 74328 2621621 /lib/powerpc64le-linux-gnu/libgcc_s.so.1
a.out 14046 amorrow mem REG 8,2 856616 2622143 /lib/powerpc64le-linux-gnu/libm-2.23.so
a.out 14046 amorrow mem REG 8,2 1851512 2622139 /lib/powerpc64le-linux-gnu/libc-2.23.so
a.out 14046 amorrow mem REG 8,2 171632 2622098 /lib/powerpc64le-linux-gnu/libpthread-2.23.so
a.out 14046 amorrow mem REG 8,2 2042040 2752992 /usr/lib/powerpc64le-linux-gnu/libstdc++.so.6.0.21
a.out 14046 amorrow mem REG 8,2 69136 6182484 /home/acm/opt/src/1640518/libfoo.so.1
a.out 14046 amorrow mem REG 8,2 268976 2622140 /lib/powerpc64le-linux-gnu/ld-2.23.so
Setting a breakpoint in pthread_mutex_lock lands me in __GI___pthread_mutex_lock. Perhaps the interposition symbol needs to be changed?
$ LD_PRELOAD=$(realpath ./libfoo.so.1 ) gdb ./a.out
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "powerpc64le-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...(no debugging symbols found)...done.
(gdb) break pthread_mutex_lock
Breakpoint 1 at 0x10000da0
(gdb) r
Starting program: /home/acm/opt/src/1640518/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/powerpc64le-linux-gnu/libthread_db.so.1".
Breakpoint 1, __GI___pthread_mutex_lock (mutex=0x3fffb7ff0908 <_rtld_global+2312>) at ../nptl/pthread_mutex_lock.c:67
warning: Source file is more recent than executable.
I don't think the interposition is working, or I'm doing something wrong.
I changed pthread_ mutex_lock. c to the following:
$ cat pthread_ mutex_lock. c
#include <pthread.h>
#include <stdlib.h>
#define PTHREAD_ MUTEX_NO_ ELISION_ NP 512 mutex_lock (pthread_mutex_t *);
extern int __pthread_
int >__data. __kind |= PTHREAD_ MUTEX_NO_ ELISION_ NP; mutex_lock (mutex);
pthread_mutex_lock (pthread_mutex_t *mutex)
{
abort();
mutex-
return __pthread_
}
$ gcc -c -fPIC pthread_ mutex_lock. c libfoo. so.1 -o libfoo.so.1
$ gcc -shared -Wl,-soname,
I then wrote a small C++ program:
$ cat use_foo.cpp
#include <mutex>
int main(int argc, char* argv[]) { :lock_guard< std::mutex> guard(m);
std::mutex m;
std:
return EXIT_SUCCESS;
}
Compiled it to a.out:
$ g++ -std=c++11 -pthread ./use_foo.cpp
When run, it does *not* terminate in abort:
LD_PRELOAD= $(realpath ./libfoo.so.1 ) ./a.out ; echo $?
Under gdb, I can see that the libfoo.so.1 library is loaded:
$ LD_PRELOAD= $(realpath ./libfoo.so.1 ) gdb ./a.out 0ubuntu1~ 16.04) 7.11.1 gnu.org/ licenses/ gpl.html> linux-gnu" . www.gnu. org/software/ gdb/bugs/>. www.gnu. org/software/ gdb/documentati on/>. opt/src/ 1640518/ a.out le-linux- gnu/libthread_ db.so.1" .
GNU gdb (Ubuntu 7.11.1-
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "powerpc64le-
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://
Find the GDB manual and other documentation resources online at:
<http://
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...(no debugging symbols found)...done.
(gdb) sta
Temporary breakpoint 1 at 0x10000a24
Starting program: /home/acm/
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/powerpc64
Temporary breakpoint 1, 0x0000000010000a24 in main () opt/src/ 1640518/ a.out e-linux- gnu/libgcc_ s.so.1 e-linux- gnu/libm- 2.23.so e-linux- gnu/libc- 2.23.so e-linux- gnu/libpthread- 2.23.so powerpc64le- linux-gnu/ libstdc+ +.so.6. 0.21 opt/src/ 1640518/ libfoo. so.1 e-linux- gnu/ld- 2.23.so
(gdb) info inferior
Num Description Executable
* 1 process 14046 /home/acm/
(gdb) !lsof -p 14046 | grep lib
a.out 14046 amorrow mem REG 8,2 74328 2621621 /lib/powerpc64l
a.out 14046 amorrow mem REG 8,2 856616 2622143 /lib/powerpc64l
a.out 14046 amorrow mem REG 8,2 1851512 2622139 /lib/powerpc64l
a.out 14046 amorrow mem REG 8,2 171632 2622098 /lib/powerpc64l
a.out 14046 amorrow mem REG 8,2 2042040 2752992 /usr/lib/
a.out 14046 amorrow mem REG 8,2 69136 6182484 /home/acm/
a.out 14046 amorrow mem REG 8,2 268976 2622140 /lib/powerpc64l
Setting a breakpoint in pthread_mutex_lock lands me in __GI___ pthread_ mutex_lock. Perhaps the interposition symbol needs to be changed?
$ LD_PRELOAD= $(realpath ./libfoo.so.1 ) gdb ./a.out 0ubuntu1~ 16.04) 7.11.1 gnu.org/ licenses/ gpl.html> linux-gnu" . www.gnu. org/software/ gdb/bugs/>. www.gnu. org/software/ gdb/documentati on/>. opt/src/ 1640518/ a.out le-linux- gnu/libthread_ db.so.1" .
GNU gdb (Ubuntu 7.11.1-
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "powerpc64le-
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://
Find the GDB manual and other documentation resources online at:
<http://
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...(no debugging symbols found)...done.
(gdb) break pthread_mutex_lock
Breakpoint 1 at 0x10000da0
(gdb) r
Starting program: /home/acm/
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/powerpc64
Breakpoint 1, __GI___ pthread_ mutex_lock (mutex= 0x3fffb7ff0908 <_rtld_ global+ 2312>) at ../nptl/ pthread_ mutex_lock. c:67
warning: Source file is more recent than executable.