hi, configuration: [mathieu@mathieu-laptop test]$ gcc -dumpmachine x86_64-redhat-linux [mathieu@mathieu-laptop test]$ gcc --version gcc (GCC) 4.4.0 20090506 (Red Hat 4.4.0-4) [mathieu@mathieu-laptop test]$ uname -a Linux mathieu-laptop 2.6.29.5-191.fc11.x86_64 #1 SMP Tue Jun 16 23:23:21 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux testcase: [mathieu@mathieu-laptop test]$ cat >test.c __thread int g_a; int main (int argc, char *argv[]) { g_a = 0; return 0; } [mathieu@mathieu-laptop test]$ gcc -c -fpie ./test.c -o test.o [mathieu@mathieu-laptop test]$ objdump -d ./test.o 0000000000000000 <main>: 0: 55 push %rbp 1: 48 89 e5 mov %rsp,%rbp 4: 89 7d fc mov %edi,-0x4(%rbp) 7: 48 89 75 f0 mov %rsi,-0x10(%rbp) b: 64 c7 04 25 00 00 00 movl $0x0,%fs:0x0 12: 00 00 00 00 00 17: b8 00 00 00 00 mov $0x0,%eax 1c: c9 leaveq 1d: c3 retq hrm, this code appears to be use a static tls model and, now: [mathieu@mathieu-laptop test]$ gcc -c -fpic ./test.c -o test.o [mathieu@mathieu-laptop test]$ objdump -d ./test.o 0000000000000000 <main>: 0: 55 push %rbp 1: 48 89 e5 mov %rsp,%rbp 4: 48 83 ec 10 sub $0x10,%rsp 8: 89 7d fc mov %edi,-0x4(%rbp) b: 48 89 75 f0 mov %rsi,-0x10(%rbp) f: 66 48 8d 3d 00 00 00 lea 0x0(%rip),%rdi # 17 <main+0x17> 16: 00 17: 66 66 48 e8 00 00 00 callq 1f <main+0x1f> 1e: 00 1f: c7 00 00 00 00 00 movl $0x0,(%rax) 25: b8 00 00 00 00 mov $0x0,%eax 2a: c9 leaveq 2b: c3 retq This code is using a dynamic tls model (the callq instruction is calling __tls_get_addr) I am pretty happy because I think that this is the first time I actually see a difference between -fpic and -fpie so, I feel I understand better what -fpie really does but what I get is not really what I was hoping for. i.e., I was hoping that -fpie would not require the use of the static tls model. I tried passing -ftls-model=global-dynamic with -fpie but that did not help in any way. Hence, my questions: 1) is this (which tls model to use by default) the gist of the difference between -fpie and -fpic ? Are there other subtle differences between the two ? 2) is there a way to make -fpie still use a dynamic tls model (short of hacking the code to add a tls_model("global-dynamic") attribute to my __thread variable declaration ? I tried some more experimentation: [mathieu@mathieu-laptop test]$ gcc -fpie -pie ./test.c -o test /usr/bin/ld: /tmp/ccsIE4YR.o: relocation R_X86_64_TPOFF32 against `g_a' can not be used when making a shared object; recompile with -fPIC /tmp/ccsIE4YR.o: could not read symbols: Bad value collect2: ld returned 1 exit status [mathieu@mathieu-laptop test]$ gcc -fpie ./test.c -o test [mathieu@mathieu-laptop test]$ readelf -h ./test |grep Type Type: EXEC (Executable file) [mathieu@mathieu-laptop test]$ gcc -pie -fpic ./test.c -o test [mathieu@mathieu-laptop test]$ readelf -h ./test |grep Type Type: DYN (Shared object file) Which brings me to more questions: 1) why does "gcc -fpie -pie" fail to work ? Is this not the recommended way to use -fpie and -pie ? Could it be that -fpie is using the static tls model when it should not ? 2) is "gcc -fpic -pie" expected to do anything sensible ? (as it appears to be doing) 3) is "gcc -fpie" really unsupported ? -- Mathieu Lacage <mathieu.lacage@xxxxxxxxx>