最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

function - What does __fortify_function do under GCC? - Stack Overflow

programmeradmin1浏览0评论

I am working on a program I wrote a while ago and have come across something I can't figure out why I did it.

__fortify_function void DoLog(const char* format,...)

As suggested by the name the function puts a log message out with the destination depending on some status variables.

What I can't figure out is what the "__fortify_function" is for. Searching online makes it clear it has something to do with the "FORTIFY_SOURCE" definition (which this code does not use) but I can't find anything online or off that says what __fortify_function is for. Everywhere I find it, it is just there with no explanation. It is possible that when I wrote DoLog I was cookbooking and so included it simply because the example I was working from did.

So what does "__fortify_function" specifically do?

I am working on a program I wrote a while ago and have come across something I can't figure out why I did it.

__fortify_function void DoLog(const char* format,...)

As suggested by the name the function puts a log message out with the destination depending on some status variables.

What I can't figure out is what the "__fortify_function" is for. Searching online makes it clear it has something to do with the "FORTIFY_SOURCE" definition (which this code does not use) but I can't find anything online or off that says what __fortify_function is for. Everywhere I find it, it is just there with no explanation. It is possible that when I wrote DoLog I was cookbooking and so included it simply because the example I was working from did.

So what does "__fortify_function" specifically do?

Share Improve this question asked Jan 18 at 19:50 epilitimusepilitimus 12 bronze badges 3
  • It's a macro defined in /usr/include/sys/cdefs.h as # define __fortify_function __extern_always_inline __attribute_artificial__, you can definition of the macros used to define it in that file as well. – Arkadiusz Drabczyk Commented Jan 18 at 20:09
  • You can also run gcc with -E flag and get all attributes expanded extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) – Arkadiusz Drabczyk Commented Jan 18 at 20:11
  • Thank you. Now I can go research all those and determine if I really need it to be there. – epilitimus Commented Jan 18 at 20:52
Add a comment  | 

1 Answer 1

Reset to default 0

Arkadiusz Drabczyk (see the comments on my original question) actually answered my question. That answer though led me to a non-obvious conclusion so I thought I would post that here in case it was of use to someone else.

The reason __fortify_function is there is that DoLog uses __va_arg_pack which resolves to __builtin_va_arg_pack which according to the docs:

-- Built-in Function: __builtin_va_arg_pack () This built-in function represents all anonymous arguments of an inline function. It can be used only in inline functions that are always inlined, never compiled as a separate function, such as those using 'attribute ((always_inline))' or 'attribute ((gnu_inline))' extern inline functions. It must be only passed as last argument to some other function with variable arguments. This is useful for writing small wrapper inlines for variable argument functions, when using preprocessor macros is undesirable.

So __fortify_function sets up the correct attributes to use __va_arg_pack.

发布评论

评论列表(0)

  1. 暂无评论