rick
rick

Reputation: 165

What is the glibc GLRO macro?

I'm currently trying to understand how the glibc startup routines (__libc_start_main) process Elf Auxiliary vector types (auxv_t).

Browsing through the source code for glibc, I find references to some function named GLRO. In trying to track down the definition for this function, the closest I can find is

#define GLRO(x) _##x

When I search for "##x", all I find is other similar "#define" directives, which leaves me confused. What does this definition mean? Is "##x" some kind of compiler directive?

Upvotes: 7

Views: 3064

Answers (3)

gregory.0xf0
gregory.0xf0

Reputation: 91

Kerrek SB's answer provides what it does, but not the macro's purpose. So here it is:

"The GLRO() macro is used to access global or local read-only data, see sysdeps/generic/ldsodefs.h."

Source: http://cygwin.com/ml/libc-help/2012-03/msg00006.html

Upvotes: 9

ouah
ouah

Reputation: 145889

#define GLRO(x) _##x

## is the token pasting operator and it concatenates its two operands.

e.g., a ## b yields ab and _ ## x yields _x.

So for example:

GLRO(my_symbol) = 0;

would result in:

_my_symbol = 0;

Upvotes: 3

Kerrek SB
Kerrek SB

Reputation: 477268

This is a preprocessor macro.

You can see for yourself what it does by running the preprocessor. Just make a sample file, like this:

// foo.c
#include <some_glibc_header.h>

GLRO(hello)

Now run the preprocessor:

gcc -E foo.c

You'll see that the macro creates a new token by putting an underscore in front of the given token; in our example we obtain _hello. The ## preprocessor operator concatenates tokens.

Upvotes: 5

Related Questions