[PATCH] Add a fallback mechanism for undefined atom.

Shankar Kalpathi Easwaran shankarke at gmail.com
Fri Sep 6 13:19:33 PDT 2013


  It also changes the call to the __wrap_symbol if real symbol is not found.
  If the real symbol is found, the call still is routed to the real function and not the wrap function.
  This is clearly the alias feature. The implementation suggested by Nick is very clean in my opinion for this.

  Below is a snippet that uses calls to wrap :-

  Example :-
  (1) Using wrap function directly
  $cat wrap.c
  #include <stdio.h>

  void __wrap_myfn()
  {
    printf("Hello World\n");
  }

  int main() {
    myfn();
    return 0;
  }
  $gcc wrap.c -Wl,--wrap,myfn
  $./a.out
  Hello World
  $gcc wrap.c
  /tmp/ccV7Dm8C.o: In function `main':
  wrap.c:(.text+0x1a): undefined reference to `myfn'
  collect2: error: ld returned 1 exit status

  (2) wrap with a definition

  #include <stdio.h>

  void myfn() {
    printf("not in wrap function\n");
  }

  void __wrap_myfn()
  {
    printf("Hello World\n");
  }

  int main() {
    myfn();
    return 0;
  }

  $gcc wrapdefn.c -Wl,--wrap,myfn
  $./a.out
  not in wrap function

http://llvm-reviews.chandlerc.com/D1550



More information about the llvm-commits mailing list