1

I am trying to add entey/exit hooks to ls in the coreutils package. I followed instuctions from here to get the source and build it:
https://askubuntu.com/questions/976002/how-to-compile-the-sorcecode-of-the-offical-ls-c-source-code

Now, to add hooks, i modiified ls code as:

Makefile

diff --git a/src/local.mk b/src/local.mk

+src_ls_CFLAGS = -g  -finstrument-functions
+src_ls_LDFLAGS = -ldl -rdynamic

and the hooks in ls source:

diff --git a/src/ls.c b/src/ls.c

+void __attribute__((no_instrument_function))
+__cyg_profile_func_enter (void *this_fn,
+                               void *call_site)
+{
+    printf("hacked [+]\n");
+}
+
+void __attribute__((no_instrument_function))
+__cyg_profile_func_exit  (void *this_fn,
+                               void *call_site)
+{
+    printf("hacked [-]\n");
+}

But now when I run ls, it crashes:

// looks like stack depth exceeded but reports segmentation fault:

Program received signal SIGSEGV, Segmentation fault.
0x00000000004057de in printf (__fmt=<synthetic pointer>) at src/ls.c:263
263     {
(gdb) bt
#0  0x00000000004057de in printf (__fmt=<synthetic pointer>) at src/ls.c:263
#1  __cyg_profile_func_enter (this_fn=<optimized out>, call_site=<optimized out>) at src/ls.c:266
#2  0x00000000004057e3 in printf (__fmt=<synthetic pointer>) at src/ls.c:263
#3  __cyg_profile_func_enter (this_fn=<optimized out>, call_site=<optimized out>) at src/ls.c:266
#4  0x00000000004057e3 in printf (__fmt=<synthetic pointer>) at src/ls.c:263
#5  __cyg_profile_func_enter (this_fn=<optimized out>, call_site=<optimized out>) at src/ls.c:266
#6  0x00000000004057e3 in printf (__fmt=<synthetic pointer>) at src/ls.c:263
. . . . 
#712011 __cyg_profile_func_enter (this_fn=<optimized out>, call_site=<optimized out>) at src/ls.c:266
< still running >

Why __attribute__((no_instrument_function)) in entry/exit hook functions not working??

(gdb) disas __cyg_profile_func_enter
Dump of assembler code for function __cyg_profile_func_enter:
   0x00000000004057d0 <+0>:     sub    $0x8,%rsp
   0x00000000004057d4 <+4>:     mov    $0x404aa0,%edi
   0x00000000004057d9 <+9>:     mov    0x8(%rsp),%rsi
=> 0x00000000004057de <+14>:    callq  0x4057d0 <__cyg_profile_func_enter>
   0x00000000004057e3 <+19>:    mov    $0x41b3cf,%edi
   0x00000000004057e8 <+24>:    callq  0x404920 <puts@plt>
   0x00000000004057ed <+29>:    mov    0x8(%rsp),%rsi
   0x00000000004057f2 <+34>:    mov    $0x404aa0,%edi
   0x00000000004057f7 <+39>:    add    $0x8,%rsp
   0x00000000004057fb <+43>:    jmp    0x4057a0 <__cyg_profile_func_exit>
End of assembler dump.
(gdb)

Coreutils source: http://git.savannah.gnu.org/cgit/coreutils.git/tree/

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.