addon with LD_PRELOAD hooking is not working

80 views
Skip to first unread message

cinyoung hur

unread,
Feb 12, 2015, 1:05:01 AM2/12/15
to nod...@googlegroups.com
Hello,

I'm testing addon with LD_PRELOAD hooking.

In the test, I made hooking object for fopen call.
When I test with this example, fopen hooking worked.

#include <stdio.h>

int main()
{}
    // ld_preload test
    FILE* fd = NULL;
    printf("Calling the fopen() function. \n");
    fd = fopen("test.txt", "r");
    if(!fd) {
      printf("ok\n");

    }
    printf("fopen() succeeded\n");
}

But, if I apply this within node addons, hooking didn't work.

NAN_METHOD(MyObject::New) {
  NanScope();

  if (args.IsConstructCall()) {
    // Invoked as constructor: `new MyObject(...)`
    MyObject* obj = new MyObject();
    obj->Wrap(args.This());

    // ld_preload test
    FILE* fd = NULL;
    printf("Calling the fopen() function. \n");
    fd = fopen("test.txt", "r");
    if(!fd) {
      printf("null\n");

    }
    printf("fopen() succeeded\n");
    
    NanReturnValue(args.This());
  } 
}


Node addon documents say that Node statically compiles all its dependencies into the executable.

Is that why LD_PRELOAD is not working?
Please guide me to solve this problem.

Floby

unread,
Feb 13, 2015, 4:49:46 AM2/13/15
to nod...@googlegroups.com
Yes, LD_PRELOAD only works with dynamically linked libraries.

Floby

unread,
Feb 13, 2015, 4:53:17 AM2/13/15
to nod...@googlegroups.com
That being said

$ nm `which node` | grep fopen
                 U fopen64@@GLIBC_2.2.5
                 U fopen@@GLIBC_2.2.5

seems to indicate that fopen is indeed dynamically linked.



On Thursday, 12 February 2015 07:05:01 UTC+1, cinyoung hur wrote:
Reply all
Reply to author
Forward
0 new messages