instrprof-dlopen-dlclose-main_three-libs.c.gcov 4.97 KB
// CHECK:        -:    0:Source:{{.*}}Inputs/instrprof-dlopen-dlclose-main.c
// CHECK-NEXT:        -:    0:Graph:instrprof-dlopen-dlclose-main.gcno
// CHECK-NEXT:        -:    0:Data:instrprof-dlopen-dlclose-main.gcda
// CHECK-NEXT:        -:    0:Runs:1
// CHECK-NEXT:        -:    0:Programs:1
// CHECK-NEXT:        -:    1:#include <dlfcn.h>
// CHECK-NEXT:        -:    2:#include <stdio.h>
// CHECK-NEXT:        -:    3:#include <stdlib.h>
// CHECK-NEXT:        -:    4:
// CHECK-NEXT:        1:    5:int main(int argc, char *argv[]) {
// CHECK-NEXT:        1:    6:  dlerror();
// CHECK-NEXT:        1:    7:  void *f1_handle = dlopen("func.shared", RTLD_LAZY | RTLD_GLOBAL);
// CHECK-NEXT:        1:    8:  if (f1_handle == NULL) {
// CHECK-NEXT:    #####:    9:    fprintf(stderr, "unable to open 'func.shared': %s\n", dlerror());
// CHECK-NEXT:    #####:   10:    return EXIT_FAILURE;
// CHECK-NEXT:        -:   11:  }
// CHECK-NEXT:        -:   12:
// CHECK-NEXT:        1:   13:  void (*func)(void) = (void (*)(void))dlsym(f1_handle, "func");
// CHECK-NEXT:        1:   14:  if (func == NULL) {
// CHECK-NEXT:    #####:   15:    fprintf(stderr, "unable to lookup symbol 'func': %s\n", dlerror());
// CHECK-NEXT:    #####:   16:    return EXIT_FAILURE;
// CHECK-NEXT:        -:   17:  }
// CHECK-NEXT:        -:   18:
// CHECK-NEXT:        1:   19:  dlerror();
// CHECK-NEXT:        1:   20:  void *f2_handle = dlopen("func2.shared", RTLD_LAZY | RTLD_GLOBAL);
// CHECK-NEXT:        1:   21:  if (f2_handle == NULL) {
// CHECK-NEXT:    #####:   22:    fprintf(stderr, "unable to open 'func2.shared': %s\n", dlerror());
// CHECK-NEXT:    #####:   23:    return EXIT_FAILURE;
// CHECK-NEXT:        -:   24:  }
// CHECK-NEXT:        -:   25:
// CHECK-NEXT:        1:   26:  void (*func2)(void) = (void (*)(void))dlsym(f2_handle, "func2");
// CHECK-NEXT:        1:   27:  if (func2 == NULL) {
// CHECK-NEXT:    #####:   28:    fprintf(stderr, "unable to lookup symbol 'func2': %s\n", dlerror());
// CHECK-NEXT:    #####:   29:    return EXIT_FAILURE;
// CHECK-NEXT:        -:   30:  }
// CHECK-NEXT:        1:   31:  func2();
// CHECK-NEXT:        -:   32:
// CHECK-NEXT:        -:   33:#ifdef USE_LIB3
// CHECK-NEXT:        1:   34:  void *f3_handle = dlopen("func3.shared", RTLD_LAZY | RTLD_GLOBAL);
// CHECK-NEXT:        1:   35:  if (f3_handle == NULL) {
// CHECK-NEXT:    #####:   36:    fprintf(stderr, "unable to open 'func3.shared': %s\n", dlerror());
// CHECK-NEXT:    #####:   37:    return EXIT_FAILURE;
// CHECK-NEXT:        -:   38:  }
// CHECK-NEXT:        -:   39:
// CHECK-NEXT:        1:   40:  void (*func3)(void) = (void (*)(void))dlsym(f3_handle, "func3");
// CHECK-NEXT:        1:   41:  if (func3 == NULL) {
// CHECK-NEXT:    #####:   42:    fprintf(stderr, "unable to lookup symbol 'func3': %s\n", dlerror());
// CHECK-NEXT:    #####:   43:    return EXIT_FAILURE;
// CHECK-NEXT:        -:   44:  }
// CHECK-NEXT:        1:   45:  func3();
// CHECK-NEXT:        -:   46:#endif
// CHECK-NEXT:        -:   47:
// CHECK-NEXT:        1:   48:  dlerror();
// CHECK-NEXT:        1:   49:  void (*gcov_flush1)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
// CHECK-NEXT:        1:   50:  if (gcov_flush1 == NULL) {
// CHECK-NEXT:    #####:   51:    fprintf(stderr, "unable to find __gcov_flush in func.shared': %s\n", dlerror());
// CHECK-NEXT:    #####:   52:    return EXIT_FAILURE;
// CHECK-NEXT:        -:   53:  }
// CHECK-NEXT:        -:   54:
// CHECK-NEXT:        1:   55:  dlerror();
// CHECK-NEXT:        1:   56:  void (*gcov_flush2)() = (void (*)())dlsym(f2_handle, "__gcov_flush");
// CHECK-NEXT:        1:   57:  if (gcov_flush2 == NULL) {
// CHECK-NEXT:    #####:   58:    fprintf(stderr, "unable to find __gcov_flush in func2.shared': %s\n", dlerror());
// CHECK-NEXT:    #####:   59:    return EXIT_FAILURE;
// CHECK-NEXT:        -:   60:  }
// CHECK-NEXT:        -:   61:
// CHECK-NEXT:        1:   62:  if (gcov_flush1 == gcov_flush2) {
// CHECK-NEXT:    #####:   63:    fprintf(stderr, "Same __gcov_flush found in func.shared and func2.shared\n");
// CHECK-NEXT:    #####:   64:    return EXIT_FAILURE;
// CHECK-NEXT:        -:   65:  }
// CHECK-NEXT:        -:   66:
// CHECK-NEXT:        1:   67:  dlerror();
// CHECK-NEXT:        1:   68:  if (dlclose(f2_handle) != 0) {
// CHECK-NEXT:    #####:   69:    fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
// CHECK-NEXT:    #####:   70:    return EXIT_FAILURE;
// CHECK-NEXT:        -:   71:  }
// CHECK-NEXT:        -:   72:
// CHECK-NEXT:        1:   73:  func();
// CHECK-NEXT:        -:   74:
// CHECK-NEXT:        1:   75:  int g1 = 0;
// CHECK-NEXT:        1:   76:  int g2 = 0;
// CHECK-NEXT:        1:   77:  int n = 10;
// CHECK-NEXT:        -:   78:
// CHECK-NEXT:        1:   79:  if (n % 5 == 0)
// CHECK-NEXT:        1:   80:    g1++;
// CHECK-NEXT:        -:   81:  else
// CHECK-NEXT:    #####:   82:    g2++;
// CHECK-NEXT:        -:   83:
// CHECK-NEXT:        1:   84:  return EXIT_SUCCESS;
// CHECK-NEXT:        1:   85:}
// CHECK-NEXT:        -:   86: