I am trying to use %gs
register to save a temporary value in my program. I am using LLVM pass to insert assembly code that writes to and reads the registers. When I use %fs
, everything works. But %fs
is used by a few programs/libraries, while %gs
is not.
When I replace %fs
by %gs
, even simple instructions like mov %eax, %gs:0x0
fail.
mov %rbx,%fs:0x0 //Works
mov %rbx,%gs:0x0 //Segmentation Fault.
(On the other hand, mov %rbx, %gs
works as long as value in %eax
is less than 4. Any value more than 4, gives segmentation fault)
How can I create segment and use its segment selector in %gs
that I can use further in the program.
Machine Desc: 64 bit Ubuntu 16.04. llvm-7.0.1