{"action":"created","issue":{"url":"https://api.github.com/repos/google/sanitizers/issues/295","repository_url":"https://api.github.com/repos/google/sanitizers","labels_url":"https://api.github.com/repos/google/sanitizers/issues/295/labels{/name}","comments_url":"https://api.github.com/repos/google/sanitizers/issues/295/comments","events_url":"https://api.github.com/repos/google/sanitizers/issues/295/events","html_url":"https://github.com/google/sanitizers/issues/295","id":104153726,"number":295,"title":"make operator new more standard compliant ","user":{"login":"ramosian-glider","id":912627,"avatar_url":"https://avatars.githubusercontent.com/u/912627?v=3","gravatar_id":"","url":"https://api.github.com/users/ramosian-glider","html_url":"https://github.com/ramosian-glider","followers_url":"https://api.github.com/users/ramosian-glider/followers","following_url":"https://api.github.com/users/ramosian-glider/following{/other_user}","gists_url":"https://api.github.com/users/ramosian-glider/gists{/gist_id}","starred_url":"https://api.github.com/users/ramosian-glider/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramosian-glider/subscriptions","organizations_url":"https://api.github.com/users/ramosian-glider/orgs","repos_url":"https://api.github.com/users/ramosian-glider/repos","events_url":"https://api.github.com/users/ramosian-glider/events{/privacy}","received_events_url":"https://api.github.com/users/ramosian-glider/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/google/sanitizers/labels/Priority-Medium","name":"Priority-Medium","color":"ededed"},{"url":"https://api.github.com/repos/google/sanitizers/labels/ProjectAddressSanitizer","name":"ProjectAddressSanitizer","color":"ededed"},{"url":"https://api.github.com/repos/google/sanitizers/labels/Status-Accepted","name":"Status-Accepted","color":"ededed"},{"url":"https://api.github.com/repos/google/sanitizers/labels/Type-Enhancement","name":"Type-Enhancement","color":"ededed"}],"state":"open","locked":false,"assignee":{"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},"assignees":[{"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}],"milestone":null,"comments":14,"created_at":"2015-08-31T23:32:58Z","updated_at":"2016-07-21T15:12:38Z","closed_at":null,"body":"Originally reported on Google Code with ID 295\n```\nUsers sometimes complain that asan's operator new is not fully standard-compliant\r\nwhen it comes to handling out of memory situation.\r\n\r\nIn particular: \r\n\r\n  - new-nothrow does not return 0 by default (it does with ASAN_OPTIONS=allocator_may_return_null=1)\r\n  - new does not throw std::bad_alloc\r\n  - either variant does not call new_handler \r\n\r\n\r\nImplementing these features appears to be surprisingly difficult.\r\n\r\nThe implementation of asan's operator new resides in asan/asan_new_delete.cc\r\nhttp://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_new_delete.cc?view=markup\r\n\r\nasan's new/delete is essentially a user replacement of these operators. \r\nThis has a side effect: a user can not replace new/delete with his own variants,\r\n(this is undefined behavior: http://en.cppreference.com/w/cpp/memory/new/operator_new)\r\n\r\nThrowing exceptions from asan/asan_new_delete.cc is currently not possible because\r\nwe build the entire run-time w/o exceptions. \r\nWe can overcome this by having special flags for asan/asan_new_delete.cc.\r\nThen there is a problem of linking with c++ lib.\r\nasan run-time does not depend on c++ run-time and can be used with pure C w/o linking\nc++.\r\nWe probably may overcome this my splitting asan_new_delete.cc into a separate library\r\nasan-rt-cxx that will be linked in asan mode only for C++ programs. \r\n\r\nCalling new_handler from asan's operator new would be possible in c++11, where \r\nstd::get_new_handler() is present, but we can't rely on this yet\r\n(libstdc++ in gcc 4.8.2 does not have std::get_new_handler).\r\nAnd again, the same problem with linking with c++ lib.\r\n  \r\nWe can also simply remove our new/delete interceptors.\r\nThis will route new/delete to the standard c++ library and will solve the problem completely\r\n(assuming new/delete call malloc/free),\r\nbut we will lose the ability to detect new/free and new[]/delete mismatch bugs. \r\n\r\nSo, the possible plan is: \r\n- split asan run-time, moving asan/asan_new_delete.cc into a separate library and link\nit only when libstdc++/libc++ is linked.\r\n- make our operator new() throw bad_alloc\r\n- declare std::get_new_handler() as weak and if it is present, handle the new_handler\ncase.\r\n\r\nOMG, that sounds so hard, and for very little outcome.\r\nI am tempted to leave it as is unless we find an easier route.\r\nBetter implementation ideas are welcome. \n```\n\nReported by `konstantin.s.serebryany` on 2014-04-15 12:00:10\n"},"comment":{"url":"https://api.github.com/repos/google/sanitizers/issues/comments/234285026","html_url":"https://github.com/google/sanitizers/issues/295#issuecomment-234285026","issue_url":"https://api.github.com/repos/google/sanitizers/issues/295","id":234285026,"user":{"login":"jwakely","id":1254480,"avatar_url":"https://avatars.githubusercontent.com/u/1254480?v=3","gravatar_id":"","url":"https://api.github.com/users/jwakely","html_url":"https://github.com/jwakely","followers_url":"https://api.github.com/users/jwakely/followers","following_url":"https://api.github.com/users/jwakely/following{/other_user}","gists_url":"https://api.github.com/users/jwakely/gists{/gist_id}","starred_url":"https://api.github.com/users/jwakely/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwakely/subscriptions","organizations_url":"https://api.github.com/users/jwakely/orgs","repos_url":"https://api.github.com/users/jwakely/repos","events_url":"https://api.github.com/users/jwakely/events{/privacy}","received_events_url":"https://api.github.com/users/jwakely/received_events","type":"User","site_admin":false},"created_at":"2016-07-21T15:12:38Z","updated_at":"2016-07-21T15:12:38Z","body":"And `__cxa_allocate` and construct a `bad_alloc` object.\r\n\r\nFor libstdc++ you can call `std::__throw_bad_alloc()` but that doesn't help for libc++ or anything that isn't linked to libstdc++.so (including GCC-compiled code only linked to libsupc++.so)\r\n"}}
{"actor":{"display_login":"jwakely"}}