Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the __attribute__((force)) do?

This sounds like something I should be able to Google, but I can't find a good reference. What exactly does __attribute__((force)) do? As in:

 return (__attribute__((force)) uint32_t) *p

(this is for an ARM system, cross compiled with clang, but I can't find any reference anywhere on this attribute even in clang/arm specific pages..).

like image 730
HardcoreHenry Avatar asked Nov 02 '18 14:11

HardcoreHenry


1 Answers

__attribute__((force)) is used to suppress warnings in sparse, the c semantics checker of the linux kernel.

The wikipedia article of sparse lists the following attributes as defined by sparse:

  • address_space(num)
  • bitwise
  • force
  • context(expression,in_context,out_context)

If you need more information about these, you can take a look at the man page of sparse

In the linux kernel some these attributes are redefined in linux/include/linux/compiler_types.h. For example __force expands to __attribute__((force)) or __bitwise to __attribute__((bitwise)).

However the linux documentation about sparse tells us, that gcc ignores these attributes:

And with gcc, all the “__bitwise”/”__force stuff” goes away, and it all ends up looking just like integers to gcc.

like image 51
kalehmann Avatar answered Nov 17 '22 06:11

kalehmann