hi pipacs,
// #include <stdio.h>
#include <pthread.h>
__thread int v;
__thread int o;
int main(void) {
v = 2342;
o = 0;
// printf("hullo wurld: var:%d off:%dn", v,
o);
#if 0
do {
__asm ("pushl %%ebx; call 1f; 1: popl %%ebx; addl
$_GLOBAL_OFFSET_TABLE_+[.-1b], %%ebx; movl "
"v"
" gotntpoff(%%ebx), %0; popl %%ebx;" :
"=r" (o));
} while (0);
#endif
// printf("hullo wurld: var:%d off:%dn", v,
o);
return(0);
}
creates two text relocations:
0000068d 0000000e R_386_TLS_TPOFF
00000698 0000000e R_386_TLS_TPOFF
when compiled with gcc -c -fPIE -o test2.o test2.c
&& gcc -lpthread -pie
-o test2 test2.o && ./test2 2>&1
689: 51 push %ecx
68a: 65 c7 05 00 00 00 00 movl $0x926,%gs:0x0
691: 26 09 00 00
695: 65 c7 05 04 00 00 00 movl $0x0,%gs:0x4
69c: 00 00 00 00
6a0: b8 00 00 00 00 mov $0x0,%eax
as you can see the text relocations come from assigning the
values to
the thread variables.
question 1) am i doing something wrong with compiling this?
question 2) if i am not doing something wrong, is the
threading causzing
deliberate text relocations?
question 3) if you could fix the compilation, can you fix
the stuff
between the #if 0 so that it doesn't cause a text relocation
too?
the original macro is this:
#define MONO_THREAD_VAR_OFFSET(var,offset) do { int tmp;
__asm ("call
1f; 1: popl %0; addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %0; movl
" #var
" gotntpoff(%0), %1" : "=r" (tmp),
"=r" (offset)); } while (0)
int main(void) {
printf("hullo wurld: var:%d off:%dn", v, o);
MONO_THREAD_VAR_OFFSET(v,o);
// printf("hullo wurld: var:%d off:%dn", v,
o);
return(0);
}
you can find it in the current mono sources:
mono-project.com (or org?)
source/trunk/mono/mono/utils/mono-compiler.h
the relocations are described here:
http://docsun.cites.uiuc.edu/sun_docs/C/so
laris_9/SUNWdev/LLM/p62.html
Thanks for your help,
Alex
--
gentoo-hardened gentoo.org mailing list
|