This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

How do values get into the %gs:0x0 location?


Hi! I have a minimal C program that prints a double-precision floating-point number to stdout:


#include <stdio.h>


int main(int argc, char ** argv) {
  printf("%f\n", 3.1416);
  return 0;
}

I've compiled it with GCC for an Intel i686 machine under Linux using the -static flag, so that I can see all the compiled glibc code. The glibc printf, in this case, calls ___printf_fp. Now, at one point in ___printf_fp, I see an instruction that gets the value from the 0 offset within the TLS segment, whose selector is stored in the %gs register:

mov %gs:0x0,%ebx

This value turns to be important: it's used to compute an address to find another value, which I think is the original floating-point expression to be printed. I've determined from GDB that it holds a nonzero value that looks like a plausible memory address within my program's address space. (I did that by checking the value of %ebx right after the above instruction.) My question is how this value every got there.

I have searched through a representation of the object code that I had gotten with objdump -D, and there are many, many instances of moving the value from %gs:0x0 to a register, as above -- and some instances of moving a value from a register to some location at a nonzero offset from %gs, such as %gs:0xc -- but not a single instruction in the whole object code dump that moves a value into %gs:0x0. Does anybody have any idea how this works? It's important to me right now, because I'm debugging a virtual execution environment (a sort of lightweight virtual OS) with a code translator, and it's failing on the printing of floating-point numbers. It looks as if the value is remaining 0 at my virtual %gs:0x0, whereas it should be a number that serves as an address a few instructions later. Thanks!


Amittai Aviram Graduate Student in Computer Science Yale University 646 483 2639 amittai.aviram@yale.edu http://www.amittai.com

Amittai Aviram
Graduate Student in Computer Science
Yale University
646 483 2639
amittai.aviram@yale.edu
http://www.amittai.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]