GCC generate Canary or not?

血红的双手。 提交于 2019-12-05 02:14:55

OK, I guess we know the answer from comments, so I'll post it here to state it explicitly.

Putting canaries in a lot of functions can result in performance degradation. That's why there are several ways to tell GCC we want to use them, which are described well here. Main ideas:

  1. Canaries are not used by default, one needs to pass one of flags that enable them.
  2. To save execution time, GCC uses simple heuristic with -fstack-protector flag: add canaries for functions that use alloca or local buffers larger than 8 bytes (by default).
  3. The heuristic can be tweaked with ssp-buffer-size parameter: --param ssp-buffer-size=4.

Apparently Ubuntu ships version of GCC with size of buffer changed to 4, so buffers less than that don't trigger generation of a canary. I confirm (and anyone else should be able to repeat) that by compiling two examples with --param ssp-buffer-size=4, which produces assembly with canaries for only one of them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!