Divlaker
Divlaker

Reputation: 419

where can I find the reference of gcc extended attribute

In Linux kernel, compiler.h, I found definition of __iomem

# define __iomem __attribute__((noderef, address_space(2)))

Then I knew that __attribute__(()) is an extension of GCC. But I can't find reference of noderef or address_space in GCC.GNU.Org

I only find address_space is extended attribute in the manual page of sparse

Upvotes: 2

Views: 1450

Answers (2)

Andrew Falanga
Andrew Falanga

Reputation: 2484

I recently ran across this in the Linux Kernel sources and was also mystified. Tracking down an answer was not the simplest and I'm providing an answer to this question with the hope that, in the future, someone will see the answer for what it is and not miss the answer in the comments.

As @MarcGlisse correctly stated, you cannot find noderef or _address_space_ in the GCC docs because they are not GCC attributes. They have meaning only for Sparse. This why things like __iomem are defined thusly

#ifdef __CHECKER__
#define __iomem __attribute__((noderef, address_space(2)))
#else
#define __iomem
#endif

Under "normal" compilation, the macro is defined but effectively ignored. If the checker, i.e. Sparse, is enabled, it is meticulously scrutinized.

@alk commented some time ago by providing a link to this LKML article in which Linus explains things quite well. I first ran across this article linked in this Linux Questions thread asked in 2006. Strangely, my browser refused to open the link for "security reasons" and I had to find it the hard way in the LKML archives.

I hope this helps in understanding what is happening. Since you've asked this question ~2.5 years ago, you've likely found this to be the case.


EDIT The answer was down-voted. Thinking that it may be because I neglected to offer a meaning for noderef, I'm going to offer one now. As I mentioned in the answer, it is a signal to sparse to check for something: the dereference of a pointer. Consider this simple program:

#include <stdio.h>

#ifdef __CHECKER__
#define __void_region __attribute__((noderef, address_space(2)))
#else
#define __void_region
#endif

int main(void)
{
    int i;
    void * __void_region pMemory = NULL;
    pMemory = &i;

    printf("i is: %d\n", *(int*)pMemory);

    return 0;
}

When using sparse to check this, I get the following:

$ sparse foo.c
foo.c:14:9: warning: dereference of noderef expression
foo.c:16:37: warning: dereference of noderef expression

Basically, the definition informs sparse to signal occurances of a dereference of pMemory. This is a meaningless program but in the kernel, __iomem should never be dereferenced but accessed only through the appropriate I/O Kernel API.

Upvotes: 5

Sumit Gemini
Sumit Gemini

Reputation: 1836

"#define iomem __attribute((noderef, address_space(2)))"

Browsing the internet I could find the following detail:

"iomem" means two separate things: it means that sparse should complain if the pointer is ever dereferenced (it's a "noderef" pointer) directly, and it's in "address space 2" as opposed to the normal address space (0).

This address_space(2) or address_space(0) mean this use to difference kernel space or user space or iomem like cpu ring 0 to ring 3.

For more detail you can go through below link :-

What is the use of __iomem in linux while writing device drivers?

Upvotes: 0

Related Questions