Hacker News new | past | comments | ask | show | jobs | submit login

What does this have to do with "one C object span[ing] two symbols"? I'm not sure I get what you're asking



The problem that they are solving with their macro is that

> gcc assumes that if you add something on to the address of a symbol, the resulting address is still inside the bounds of the symbol

I'm asking - how can you write a valid C program which adds something on to the address of a valid symbol and get something outside the bounds of the symbol?


Something that comes up moderately often in low-level stuff is:

You have a bunch of objects, defined in different files, and no code is aware of what the complete list of objects is. You want to iterate over an array of all these objects. How to make the array, with minimal overhead?

A common technique is for each file defining on the these objects to to tell the linker to put it in a special section. The result of this is that there's then an "array" of objects, which according to the C language could be anywhere in memory, but because of how the linker has been told to lay them out, we know that actually they're all consecutive. So any code which wants to iterate over then can do so easily.

Except... this is isn't actually a valid C program, and is actually undefined behaviour, so the compiler might "optimise" things in a way which breaks it. Hence the RELOC_HIDE macro which obscures things from the compiler and prevents it from applying "optimisations" we don't want.


Ah, now I understand.

I am guessing here, but my guess is that they're using C but actually want to do something very low level. As in they believe (correctly?) that they know the exact memory layout relative to something.


Correct. Think control/data registers in some dedicated chip.


    char x[N],*p=x+sizeof x;


You've defined a pointer p, but you aren't actually using it, so what's the point of that?

Reading or writing the pointer p will not be a valid C program.


The question appeared to be simply how one might obtain such an address.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: