How to compile an executable using the clang flag and safe-stack

I am trying to compile a simple hello-world executable using clang-3.7 (also tried 3.8 (dev)) with the -fsanitize = safe-stack flag. As explained here ( http://clang.llvm.org/docs/SafeStack.html ), I need to pass this flag to the compiler and linker.

"To enable SafeStack, simply pass the -fsanitize = safe-stack flag for both compiling and linking commands."

I tried the following command to compile the executable:

clang-3.7 -fsanitize=safe-stack -o a.out -Wl,-fsanitize=safe-stack test.c

But the linker tells me that I need to compile it as a shared library (-shared) if I pass the -f flag to the linker.

/usr/bin/ld: -f may not be used without -shared

How to compile executable using the -fsanitize = safe-stack flag?

+4
source share
1 answer

By "passing it to both compilation command line commands and the link" the documentation means passing it both during compilation and when linking. This does not mean using -Wlone that passes it directly to the linker - it -fmeans something completely unrelated to the linker.

In this case

clang-3.7 -fsanitize=safe-stack -o a.out test.c

. If you used separate commands for compilation and linking, you need to pass them to both:

clang-3.7 -fsanitize=safe-stack -c -o test.o test.c
clang-3.7 -fsanitize=safe-stack -o a.out test.o
+2
source

Source: https://habr.com/ru/post/1615144/


All Articles