gopalshankar / address-sanitizer

Automatically exported from code.google.com/p/address-sanitizer
0 stars 0 forks source link

Stack realignment with dynamic allocas #132

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

$ cat a.cpp 
#include <stdlib.h>

int main(int argc, char const* argv[])
{
    void* a = alloca(atoi(argv[1]));
    return 0;
}

$clang++ a.cpp -faddress-sanitizer
fatal error: error in backend: Stack realignment in presence of dynamic allocas 
is not supported

What is the expected output? What do you see instead?

I would expect address sanitizer to support this. perhaps by replacing alloca() 
and align all allocations.

What version of the product are you using? On what operating system?

$clang++ --version
Apple clang version 4.1 (tags/Apple/clang-421.11.65) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix

$ uname -a
Darwin arvid-macpro-634.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 
16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64

Original issue reported on code.google.com by arvid.no...@gmail.com on 9 Dec 2012 at 8:11

GoogleCodeExporter commented 9 years ago
Hi!
This doesn't reproduce for me:
$ cat realign.cc 
#include <stdlib.h>

int main(int argc, char const* argv[])
{
        void* a = alloca(atoi(argv[1]));
        return 0;
}
$ ../bin/clang++ -fsanitize=address realign.cc 
$ ./a.out 10

However, I use OS X 10.8.2 (Darwin 12.2.0) and the latest Clang built from 
trunk (LLVM revision 169652). Could you check if your test case works on the 
newest Clang (http://clang.llvm.org/get_started.html)?

Original comment by samso...@google.com on 9 Dec 2012 at 11:34

GoogleCodeExporter commented 9 years ago
Also, please try -mllvm -asan-realign-stack=0 and let us know if it helps. 

Original comment by konstant...@gmail.com on 10 Dec 2012 at 4:59

GoogleCodeExporter commented 9 years ago
"-mllvm -asan-realign-stack=0" does not make any difference on my version of 
clang. It working in trunk for you is encouraging then. I may not have the 
patience to test this with trunk anytime soon though. My code did build with 
trunk from 6 months ago or so though.

Original comment by arvid.no...@gmail.com on 15 Dec 2012 at 4:16

GoogleCodeExporter commented 9 years ago
Stack realignment in presence of dynamic allocas is supported by LLVM/Clang 
starting from r158087 (with significant fixes in later patches). Hopefully this 
would work for you in LLVM 3.2 and in the next Apple clang release.

Original comment by samso...@google.com on 17 Dec 2012 at 6:47