brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 59c4d5c Raw
73 lines · cpp
1// Test for ASAN_OPTIONS=start_deactivated=1 mode.2// Main executable is uninstrumented, but linked to ASan runtime. The shared3// library is instrumented.4// Fails with debug checks: https://bugs.llvm.org/show_bug.cgi?id=468625// XFAIL: !compiler-rt-optimized6 7// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so8// RUN: %clangxx -O0 %s -c -o %t.o9// RUN: %clangxx_asan -O0 %t.o %libdl -o %t10 11// RUN: rm -f %t.asan.options.activation-options.cpp.tmp12// RUN: rm -f %t.asan.options.ABCDE13// RUN: echo "help=1" >%t.asan.options.activation-options.cpp.tmp14 15// RUN: %env_asan_opts=start_deactivated=1 \16// RUN:   ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b %run %t 2>&1 | \17// RUN:   FileCheck %s --check-prefix=CHECK-HELP --check-prefix=CHECK-FOUND18 19// RUN: %env_asan_opts=start_deactivated=1 \20// RUN:   ASAN_ACTIVATION_OPTIONS=include=%t.asan.options not %run %t 2>&1 | \21// RUN:   FileCheck %s --check-prefix=CHECK-NO-HELP --check-prefix=CHECK-MISSING22 23// RUN: %env_asan_opts=start_deactivated=1 \24// RUN:   ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b not %run %t --fix-name 2>&1 | \25// RUN:   FileCheck %s --check-prefix=CHECK-NO-HELP --check-prefix=CHECK-MISSING26 27// RUN: echo "help=1" >%t.asan.options.ABCDE28 29// RUN: %env_asan_opts=start_deactivated=1 \30// RUN:   ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b %run %t --fix-name 2>&1 | \31// RUN:   FileCheck %s --check-prefix=CHECK-HELP --check-prefix=CHECK-FOUND32 33// XFAIL: android34 35#if !defined(SHARED_LIB)36#include <assert.h>37#include <dlfcn.h>38#include <stdio.h>39#include <stdlib.h>40#include <string.h>41#include <unistd.h>42 43#include <string>44 45#include "sanitizer/asan_interface.h"46 47typedef void (*Fn)();48 49int main(int argc, char *argv[]) {50  std::string path = std::string(argv[0]) + "-so.so";51 52  if (argc > 1 && strcmp(argv[1], "--fix-name") == 0) {53    assert(strlen(argv[0]) > 5);54    strcpy(argv[0], "ABCDE");55  }56 57  void *dso = dlopen(path.c_str(), RTLD_NOW);58  if (!dso) {59    fprintf(stderr, "dlopen failed: %s\n", dlerror());60    return 1;61  }62 63  return 0;64}65#else  // SHARED_LIB66// Empty: all we need is an ASan shared library constructor.67#endif  // SHARED_LIB68 69// CHECK-HELP: Available flags for {{.*}}Sanitizer:70// CHECK-NO-HELP-NOT: Available flags for {{.*}}Sanitizer:71// CHECK-FOUND-NOT: Failed to read options72// CHECK-MISSING: Failed to read options73