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?

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. 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__)) 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. Commented Jan 18 at 20:52

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.