Artem Dinaburg via llvm-dev
2017-Jan-31 19:34 UTC
[llvm-dev] CFI, Safe-Stack, and -fno-sanitize-trap
Hi, I am using clang++3.9 to build a simple program with both CFI and safe-stack. I am getting linker errors when combining -fsanitize=safe-stack, -fsanitize=cfi, and -fno-sanitize-trap=all. Combining safe-stack and CFI without -fno-sanitize-trap=all works as expected. It looks like clang is attempting to link in two compiler-rt libraries, one for ubsan and one for safestack, and this causes multiply defined symbols. Is this the expected behavior? Can only one sanitizer at a time have trapping disabled? The command line to trigger is below. --- $ clang++-3.9 -flto -fvisibility=default -fsanitize=safe-stack -fsanitize=cfi -fuse-ld=gold -fno-sanitize-trap=all hello.cpp ... lots of multiply defined symbol errors... /usr/bin/ld.gold: error: /usr/lib/llvm-3.9/bin/../lib/clang/3.9.1/lib/linux/libclang_rt.safestack-x86_64.a(sanitizer_common_nolibc.cc.o): multiple definition of '__sanitizer::Abort()' /usr/bin/ld.gold: /usr/lib/llvm-3.9/bin/../lib/clang/3.9.1/lib/linux/libclang_rt.ubsan_standalone-x86_64.a(sanitizer_posix_libcdep.cc.o): previous definition here /usr/bin/ld.gold: error: /usr/lib/llvm-3.9/bin/../lib/clang/3.9.1/lib/linux/libclang_rt.safestack-x86_64.a(sanitizer_common_nolibc.cc.o): multiple definition of '__sanitizer::SleepForSeconds(int)' /usr/bin/ld.gold: /usr/lib/llvm-3.9/bin/../lib/clang/3.9.1/lib/linux/libclang_rt.ubsan_standalone-x86_64.a(sanitizer_posix_libcdep.cc.o): previous definition here clang: error: linker command failed with exit code 1 (use -v to see invocation) --- hello.cpp: --- #include <iostream> int main(int argc, const char* argv[]) { std::cout << "Hello, World\n"; return 0; } --- Thanks, Artem -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3970 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170131/a5afb240/attachment.bin>
Peter Collingbourne via llvm-dev
2017-Feb-04 21:59 UTC
[llvm-dev] CFI, Safe-Stack, and -fno-sanitize-trap
Hi Artem, Thanks for the bug report! It should certainly be possible to use safestack with CFI in non-trapping mode, or indeed with any other sanitizer. I've sent https://reviews.llvm.org/D29545 for review which should fix this bug. Peter On Tue, Jan 31, 2017 at 11:34 AM, Artem Dinaburg via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi, > > I am using clang++3.9 to build a simple program with both CFI and > safe-stack. I am getting linker errors when combining > -fsanitize=safe-stack, -fsanitize=cfi, and -fno-sanitize-trap=all. > Combining safe-stack and CFI without -fno-sanitize-trap=all works as > expected. > > It looks like clang is attempting to link in two compiler-rt libraries, > one for ubsan and one for safestack, and this causes multiply defined > symbols. > > Is this the expected behavior? Can only one sanitizer at a time have > trapping disabled? > > The command line to trigger is below. > > --- > $ clang++-3.9 -flto -fvisibility=default -fsanitize=safe-stack > -fsanitize=cfi -fuse-ld=gold -fno-sanitize-trap=all hello.cpp > ... lots of multiply defined symbol errors... > /usr/bin/ld.gold: error: /usr/lib/llvm-3.9/bin/../lib/ > clang/3.9.1/lib/linux/libclang_rt.safestack-x86_64. > a(sanitizer_common_nolibc.cc.o): multiple definition of > '__sanitizer::Abort()' > /usr/bin/ld.gold: /usr/lib/llvm-3.9/bin/../lib/clang/3.9.1/lib/linux/ > libclang_rt.ubsan_standalone-x86_64.a(sanitizer_posix_libcdep.cc.o): > previous definition here > /usr/bin/ld.gold: error: /usr/lib/llvm-3.9/bin/../lib/ > clang/3.9.1/lib/linux/libclang_rt.safestack-x86_64. > a(sanitizer_common_nolibc.cc.o): multiple definition of > '__sanitizer::SleepForSeconds(int)' > /usr/bin/ld.gold: /usr/lib/llvm-3.9/bin/../lib/clang/3.9.1/lib/linux/ > libclang_rt.ubsan_standalone-x86_64.a(sanitizer_posix_libcdep.cc.o): > previous definition here > clang: error: linker command failed with exit code 1 (use -v to see > invocation) > --- > > hello.cpp: > --- > #include <iostream> > > int main(int argc, const char* argv[]) { > std::cout << "Hello, World\n"; > return 0; > } > --- > > Thanks, > Artem > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-- -- Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170204/fce9ebc2/attachment.html>
Maybe Matching Threads
- SafeStack on ARM platform
- [LLVMdev] Missing libclang_rt.san-x86_64.a file for Compiler-rt
- [RFC] Using Intel MPX to harden SafeStack
- [LLVMdev] [PATCH] Protection against stack-based memory corruption errors using SafeStack
- [cfe-dev] [3.8 Release] We have branched