{"action":"created","issue":{"url":"https://api.github.com/repos/google/sanitizers/issues/629","labels_url":"https://api.github.com/repos/google/sanitizers/issues/629/labels{/name}","comments_url":"https://api.github.com/repos/google/sanitizers/issues/629/comments","events_url":"https://api.github.com/repos/google/sanitizers/issues/629/events","html_url":"https://github.com/google/sanitizers/issues/629","id":119980327,"number":629,"title":"asan: problem calling NVIDIA CUDA libraries","user":{"login":"maleadt","id":383068,"avatar_url":"https://avatars.githubusercontent.com/u/383068?v=3","gravatar_id":"","url":"https://api.github.com/users/maleadt","html_url":"https://github.com/maleadt","followers_url":"https://api.github.com/users/maleadt/followers","following_url":"https://api.github.com/users/maleadt/following{/other_user}","gists_url":"https://api.github.com/users/maleadt/gists{/gist_id}","starred_url":"https://api.github.com/users/maleadt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maleadt/subscriptions","organizations_url":"https://api.github.com/users/maleadt/orgs","repos_url":"https://api.github.com/users/maleadt/repos","events_url":"https://api.github.com/users/maleadt/events{/privacy}","received_events_url":"https://api.github.com/users/maleadt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-12-02T16:25:17Z","updated_at":"2015-12-03T19:32:45Z","closed_at":null,"body":"I'm having an issue using ASAN with the NVIDIA CUDA libraries on a x86_64 system, returning bogus when calling `cuInit`. Given this small test-case (compiled with `clang -lcuda`):\r\n\r\n```c\r\n#include <cuda.h>\r\n#include <stdio.h>\r\n\r\nint main() {\r\n    printf(\"cuInit(0) = %d\\n\", cuInit(0));\r\n    return 0;\r\n}\r\n```\r\n\r\nWhen using `-fsanitize=address`, this call returns 2 (an impossible return value for this call) instead of the expected 0. I tried tweaking almost every ASAN option, to no avail.\r\n\r\nA verbose log:\r\n```\r\n$ ASAN_OPTIONS=verbosity=4,debug=1 ./cuinit_asan\r\n==9400==Parsed ASAN_OPTIONS: verbosity=4,debug=1\r\n==9400==AddressSanitizer: failed to intercept '__isoc99_printf'\r\n==9400==AddressSanitizer: failed to intercept '__isoc99_sprintf'\r\n==9400==AddressSanitizer: failed to intercept '__isoc99_snprintf'\r\n==9400==AddressSanitizer: failed to intercept '__isoc99_fprintf'\r\n==9400==AddressSanitizer: failed to intercept '__isoc99_vprintf'\r\n==9400==AddressSanitizer: failed to intercept '__isoc99_vsprintf'\r\n==9400==AddressSanitizer: failed to intercept '__isoc99_vsnprintf'\r\n==9400==AddressSanitizer: failed to intercept '__isoc99_vfprintf'\r\n==9400==AddressSanitizer: libc interceptors initialized\r\n|| `[0x10007fff8000, 0x7fffffffffff]` || HighMem    ||\r\n|| `[0x02008fff7000, 0x10007fff7fff]` || HighShadow ||\r\n|| `[0x00008fff7000, 0x02008fff6fff]` || ShadowGap  ||\r\n|| `[0x00007fff8000, 0x00008fff6fff]` || LowShadow  ||\r\n|| `[0x000000000000, 0x00007fff7fff]` || LowMem     ||\r\nMemToShadow(shadow): 0x00008fff7000 0x000091ff6dff 0x004091ff6e00 0x02008fff6fff\r\nredzone=16\r\nmax_redzone=2048\r\nquarantine_size=256M\r\nmalloc_context_size=30\r\nSHADOW_SCALE: 3\r\nSHADOW_GRANULARITY: 8\r\nSHADOW_OFFSET: 7fff8000\r\n==9400==Installed the sigaction for signal 11\r\n==9400==SetCurrentThread: 0x7fe10a946000 for thread 0x7fe10a940780\r\n==9400==T0: stack [0x7fff9d022000,0x7fff9d822000) size 0x800000; local=0x7fff9d8219c0\r\n==9400==AddressSanitizer Init done\r\ncuInit(0) = 2\r\n__tls_get_addr: DTLS_Resize 0x7fe10a940760 0\r\n__tls_get_addr: 0x7fe108c81d90 {0x000000000002,0x000000000000} => 0x7fe10a9406a8; tls_beg: 0x7fe10a9406a8; sp: 0x7fff9d821980 num_live_dtls 1\r\n__tls_get_addr: Can't guess glibc version\r\n==9401==Attached to thread 9400.\r\n==9401==Detached from thread 9400.\r\n```\r\n\r\nSystem specs: clang 3.5.0 from Debian repositories, on a x86_64 system running linux 3.16.0 with NVIDIA drivers 340.65 (corresponding with CUDA 6.0). On an otherwise identical 32-bit system, the error does not occur.\r\nAlso tried with llvm/clang/compiler-rt from svn trunk, same issue."},"comment":{"url":"https://api.github.com/repos/google/sanitizers/issues/comments/161755902","html_url":"https://github.com/google/sanitizers/issues/629#issuecomment-161755902","issue_url":"https://api.github.com/repos/google/sanitizers/issues/629","id":161755902,"user":{"login":"kcc","id":1789297,"avatar_url":"https://avatars.githubusercontent.com/u/1789297?v=3","gravatar_id":"","url":"https://api.github.com/users/kcc","html_url":"https://github.com/kcc","followers_url":"https://api.github.com/users/kcc/followers","following_url":"https://api.github.com/users/kcc/following{/other_user}","gists_url":"https://api.github.com/users/kcc/gists{/gist_id}","starred_url":"https://api.github.com/users/kcc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kcc/subscriptions","organizations_url":"https://api.github.com/users/kcc/orgs","repos_url":"https://api.github.com/users/kcc/repos","events_url":"https://api.github.com/users/kcc/events{/privacy}","received_events_url":"https://api.github.com/users/kcc/received_events","type":"User","site_admin":false},"created_at":"2015-12-03T19:32:45Z","updated_at":"2015-12-03T19:32:45Z","body":"Here is my test (derived from http://llvm.org/docs/CompileCudaWithLLVM.html): \r\n\r\naxpy.cu: \r\n```\r\n#include <helper_cuda.h> // for checkCudaErrors\r\n#include <iostream>\r\n__global__ void axpy(float a, float* x, float* y) {\r\n  y[threadIdx.x] = a * x[threadIdx.x];\r\n}\r\nvoid test_axpy() {\r\n  const int kDataLen = 4;\r\n  float a = 2.0f;\r\n  float host_x[kDataLen] = {1.0f, 2.0f, 3.0f, 4.0f};\r\n  float host_y[kDataLen];\r\n  float* device_x;\r\n  float* device_y;\r\n  checkCudaErrors(cudaMalloc(&device_x, kDataLen * sizeof(float)));\r\n  checkCudaErrors(cudaMalloc(&device_y, kDataLen * sizeof(float)));\r\n  checkCudaErrors(cudaMemcpy(device_x, host_x, kDataLen * sizeof(float),\r\n                             cudaMemcpyHostToDevice));\r\n  axpy<<<1, kDataLen>>>(a, device_x, device_y);\r\n  checkCudaErrors(cudaDeviceSynchronize());\r\n  checkCudaErrors(cudaMemcpy(host_y, device_y, kDataLen * sizeof(float),\r\n                             cudaMemcpyDeviceToHost));\r\n  for (int i = 0; i < kDataLen; ++i) {\r\n    std::cout << \"y[\" << i << \"] = \" << host_y[i] << \"\\n\";\r\n  }\r\n  checkCudaErrors(cudaDeviceReset());\r\n}\r\n```\r\naxpy_main.cc:\r\n```\r\nvoid test_axpy();\r\nint main() { test_axpy(); }\r\n```\r\nBuild:\r\n```\r\nclang --cuda-path=cuda -I cuda/samples/common/inc/ axpy.cu -c\r\nclang++ axpy_main.cc axpy.o -lcudart_static -lcuda -ldl -lrt -pthread  -L /usr/lib/x86_64-linux-gnu/ -L cuda/lib64 -fsanitize=address\r\n```\r\n\r\nRun: \r\n```\r\nASAN_OPTIONS=protect_shadow_gap=0:replace_intrin=0:detect_leaks=0 ./a.out \r\n```\r\n\r\nW/o protect_shadow_gap=0 cuInit() returns 2\r\n\r\nW/o replace_intrin=0 (which disables checks inside memset interceptor) I get this: \r\n```\r\n==17300==ERROR: AddressSanitizer: unknown-crash on address 0x000200000000 at pc 0x00000049b6c6 bp 0x7fffa85cb210 sp 0x7fffa85ca9c8\r\nWRITE of size 65536 at 0x000200000000 thread T0\r\n    #0 0x49b6c5 in __interceptor_memset\r\n    #1 0x7fb0c82e6813  (/usr/lib/x86_64-linux-gnu/libcuda.so.1+0x225813)\r\n    #2 0x7fb0c82e6ee7  (/usr/lib/x86_64-linux-gnu/libcuda.so.1+0x225ee7)\r\n    #3 0x7fb0c82e761d  (/usr/lib/x86_64-linux-gnu/libcuda.so.1+0x22661d)\r\n    #4 0x7fb0c8241bc4  (/usr/lib/x86_64-linux-gnu/libcuda.so.1+0x180bc4)\r\n    #5 0x7fb0c83d7a4e  (/usr/lib/x86_64-linux-gnu/libcuda.so.1+0x316a4e)\r\n    #6 0x7fb0c822761b  (/usr/lib/x86_64-linux-gnu/libcuda.so.1+0x16661b)\r\n    #7 0x7fb0c81f325a in cuDevicePrimaryCtxRetain (/usr/lib/x86_64-linux-gnu/libcuda.so.1+0x13225a)\r\n...\r\nAddress 0x000200000000 is located in the shadow gap area.\r\n```\r\nThis failure should be easy to fix, but for now let's use replace_intrin=0\r\n\r\nW/o detect_leaks=0  I get this at the end:\r\n\r\n```\r\n==17352==ERROR: LeakSanitizer: detected memory leaks\r\nDirect leak of 4904 byte(s) in 1 object(s) allocated from:\r\n    #0 0x4b1154 in calloc \r\n    #1 0x7fe8667fd4a2  (/usr/lib/x86_64-linux-gnu/libcuda.so.1+0x2264a2)\r\n    #2 0x7fe866757bc4  (/usr/lib/x86_64-linux-gnu/libcuda.so.1+0x180bc4)\r\n    #3 0x7fe8668eda4e  (/usr/lib/x86_64-linux-gnu/libcuda.so.1+0x316a4e)\r\n    #4 0x7fe86673d61b  (/usr/lib/x86_64-linux-gnu/libcuda.so.1+0x16661b)\r\n    #5 0x7fe86670925a in cuDevicePrimaryCtxRetain\r\n```\r\n\r\nNow I'd like to have a test that does something more interesting and fails somewhere else. "}}