0
votes

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

1
You're looking for documented, universally available, convenient, unused storage. Sorry. There is no such thing. A little extra storage can help with performance, and people have been trying to boost performance for decades. I'm afraid that your only option is alloca, which is quite a bit less convenient.arnt

1 Answers

0
votes

What ABI are you using? Check this out https://www.codemachine.com/article_x64deepdive.html "... but on the X64, it is the GS register that points to the TEB while in user mode ..."

I would say that this is not possible with the X64 ABI.