Gentoo Archives: gentoo-hardened

From: Alexander Gabert <a.gabert@××××××××.de>
To: pageexec@××××××××.hu
Cc: cbergstrom@×××××××××.com, gentoo-hardened@l.g.o
Subject: [gentoo-hardened] text relocations in mono (and threading in general?)
Date: Wed, 17 Jan 2007 19:39:20
Message-Id: 45AE7A94.9050102@fh-trier.de
1 hi pipacs,
2
3 // #include <stdio.h>
4 #include <pthread.h>
5
6 __thread int v;
7 __thread int o;
8
9 int main(void) {
10 v = 2342;
11 o = 0;
12 // printf("hullo wurld: var:%d off:%d\n", v, o);
13
14 #if 0
15
16 do {
17 __asm ("pushl %%ebx; call 1f; 1: popl %%ebx; addl
18 $_GLOBAL_OFFSET_TABLE_+[.-1b], %%ebx; movl " "v"
19 "@gotntpoff(%%ebx), %0; popl %%ebx;" : "=r" (o));
20 } while (0);
21
22 #endif
23
24 // printf("hullo wurld: var:%d off:%d\n", v, o);
25
26 return(0);
27 }
28
29
30 creates two text relocations:
31
32 0000068d 0000000e R_386_TLS_TPOFF
33 00000698 0000000e R_386_TLS_TPOFF
34
35 when compiled with gcc -c -fPIE -o test2.o test2.c && gcc -lpthread -pie
36 -o test2 test2.o && ./test2 2>&1
37
38 689: 51 push %ecx
39 68a: 65 c7 05 00 00 00 00 movl $0x926,%gs:0x0
40 691: 26 09 00 00
41 695: 65 c7 05 04 00 00 00 movl $0x0,%gs:0x4
42 69c: 00 00 00 00
43 6a0: b8 00 00 00 00 mov $0x0,%eax
44
45
46 as you can see the text relocations come from assigning the values to
47 the thread variables.
48
49 question 1) am i doing something wrong with compiling this?
50 question 2) if i am not doing something wrong, is the threading causzing
51 deliberate text relocations?
52
53 question 3) if you could fix the compilation, can you fix the stuff
54 between the #if 0 so that it doesn't cause a text relocation too?
55
56 the original macro is this:
57
58 #define MONO_THREAD_VAR_OFFSET(var,offset) do { int tmp; __asm ("call
59 1f; 1: popl %0; addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %0; movl " #var
60 "@gotntpoff(%0), %1" : "=r" (tmp), "=r" (offset)); } while (0)
61
62 int main(void) {
63 printf("hullo wurld: var:%d off:%d\n", v, o);
64
65 MONO_THREAD_VAR_OFFSET(v,o);
66
67 // printf("hullo wurld: var:%d off:%d\n", v, o);
68 return(0);
69 }
70
71 you can find it in the current mono sources:
72 mono-project.com (or org?)
73 source/trunk/mono/mono/utils/mono-compiler.h
74
75 the relocations are described here:
76 http://docsun.cites.uiuc.edu/sun_docs/C/solaris_9/SUNWdev/LLM/p62.html
77
78 Thanks for your help,
79
80
81 Alex
82 --
83 gentoo-hardened@g.o mailing list