linux - 如何将 "-fstack-protector-all"添加到 makefile?

标签 linux gcc makefile

我的代码有一个错误: *** 检测到堆栈粉碎 ***: ./mummergpu 终止 我在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

最佳答案

考虑使用“-fstack-protector-strong”而不是“all”。 通过“-fstack-protector-all”,它可以对所有功能应用保护,而不管它们实际上是否需要这种保护,从而对性能产生更大的影响。

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

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

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

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

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

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

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

一旦输出被验证并且可以接受在 Makefile 上应用更改,运行带有 -i 开关的 sed,如下所示:

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

关于linux - 如何将 "-fstack-protector-all"添加到 makefile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54284907/

相关文章:

linux - WSO2 企业移动管理器

c - 如何找到程序的堆内存起始地址和结束地址?

c++ - 两次内联汇编调用与一次内联汇编调用中的内存被破坏?

c - 如何在 gcc 中列出外部标识符?

c++ - omn​​iorb makefile 服务器错误

bash - Makefile 匹配任何目标/任务

c - 在 C linux 中使用命名管道从客户端向服务器发送数据

c - 如何将 int/char 传递给 system() 一个 Linux 系统调用

linux - 如何在 Linux 上使用 gcc 程序集在 x86-64 中设置控制寄存器 0 (cr0) 位

c - 使 : "The system cannot find the path specified" only when compiling with makefile?