Skip to content

Commit

Permalink
compiler.h: only use __no_stack_protector if supported by the compiler
Browse files Browse the repository at this point in the history
The __attribute__((no_stack_protector)) was introduced in GCC 11.
Building a TA with a version of GCC older than that would trigger a
-Wattributes warning on the ta/user_ta_header.c file.

Use __has_attribute() to check support of the no_stack_protector
attribute before using it. If not supported, define the
__no_stack_protector alias as a NOP.

Fixes: e3fb2bd ("compiler.h: add __no_stack_protector")
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
vincent-mailhol committed Nov 11, 2024
1 parent 9b2c7a6 commit d93b653
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/libutils/ext/include/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
* the conflicting defines has the same meaning in that environment.
* Surrounding the troublesome defines with #ifndef should be enough.
*/

#ifndef __has_attribute
#define __has_attribute(x) 0
#endif

#define __deprecated __attribute__((deprecated))
#ifndef __packed
#define __packed __attribute__((packed))
Expand All @@ -24,9 +29,15 @@
#ifndef __noreturn
#define __noreturn __attribute__((__noreturn__))
#endif

#ifndef __no_stack_protector
#if __has_attribute(no_stack_protector)
#define __no_stack_protector __attribute__((no_stack_protector))
#else
#define __no_stack_protector
#endif
#endif

#define __pure __attribute__((pure))
#define __aligned(x) __attribute__((aligned(x)))
#define __printf(a, b) __attribute__((format(printf, a, b)))
Expand Down

0 comments on commit d93b653

Please sign in to comment.