Segment based referencing in c
Posted: Thu Mar 15, 2018 2:21 am
Some xv6 code mirrors have the following line:
[github]
This is a hack using the assembly label attribute available in some compilers which works by accident rather than by design - if at all.
However, having a simple way of automatically referencing an offset from fs/gs is damn convenient, and having it be a variable rather than a function carries a measure of elegance.
Can the same thing somehow be be done The Right Way™?
Code: Select all
extern struct cpu *cpu asm("%gs:0");
This is a hack using the assembly label attribute available in some compilers which works by accident rather than by design - if at all.
However, having a simple way of automatically referencing an offset from fs/gs is damn convenient, and having it be a variable rather than a function carries a measure of elegance.
Can the same thing somehow be be done The Right Way™?