如何在makefile中添加“ -fstack-protector-all”?

时间:2019-01-21 07:03:39

标签: linux gcc makefile

我的代码有错误:     *** stack smashing detected ***: ./mummergpu terminated 我在stackoverflow中搜索它,一种解决方案是将-fno-stack-protector添加到环境变量,但是我不知道如何添加它?谁能帮我 ? nakefile遵循:

all: clean mummergpu
.SUFFIXES : .cu .cu_dbg_o .c_dbg_o .cpp_dbg_o .cu_rel_o .c_rel_o .cpp_rel_o .cubin
## Reenable this for testing all variations
#include ../experiments/test_rule.mk
CUDA_INSTALL_PATH := /usr/local/cuda-8.0
# Compilers
NVCC       := $(CUDA_INSTALL_PATH)/bin/nvcc 
CXX        := g++ $(PROFILE)
CC         := gcc 
LINK       := g++ $(PROFILE)

# Add source files here
STATIC_LIB := libmummergpu.a
# Cuda source files (compiled with cudacc)
CUFILES     := mummergpu.cu
# C/C++ source files (compiled with gcc / c++)
CCFILES     := \
 mummergpu_gold.cpp suffix-tree.cpp PoolMalloc.cpp

1 个答案:

答案 0 :(得分:0)

请考虑使用“ -fstack-protector-strong”而不是“ all”。 使用“ -fstack-protector-all”,它将对所有功能应用保护,无论它们实际上是否需要此保护,从而对性能产生更大的影响。

在此处查找更多详细信息:https://lwn.net/Articles/584225/

“强大”堆栈保护器旨在仅向那些实际上可能需要此保护的功能添加堆栈保护。

您可以在./configure命令中使用其他参数以包括堆栈保护:

./configure [options] CFLAGS='-fstack-protector-strong' CXXFLAGS='-fstack-protector-strong'

但是,某些软件包可能稍后会覆盖它。

以下是在Makefile中为CFLAGS应用堆栈保护的命令: 运行:

sed '/^.*CFLAGS = / s/$/ -fstack-protector-strong' /path/to/Makefile

一旦验证了输出并且可以接受对-i开关sed运行的Makefile进行更改,则如下所示:

sed -i '/^.*CFLAGS = / s/$/ -fstack-protector-strong' /path/to/Makefile