Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the glibc GLRO macro?

Tags:

c

glibc

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?

like image 555
rick Avatar asked Oct 08 '13 22:10

rick


3 Answers

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

like image 170
gregory.0xf0 Avatar answered Nov 01 '22 13:11

gregory.0xf0


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.

like image 40
Kerrek SB Avatar answered Nov 01 '22 11:11

Kerrek SB


#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;
like image 3
ouah Avatar answered Nov 01 '22 12:11

ouah