Ok, So I understood from you that I need to look for R_386_TLS_GD and/or R_386_TLS_LDM in my library after I compile it with -fpic or -ftls-model=global-dynamic. In a previous post you said "Putting code not compiled with -fPIC in a shared library will slow down program startup, and make the program less secure because the text segment will be writable." Now, If I decide to use -ftls-model, instead of -fpic, is there a way to set the library's text segments read-only like I was using -fpic? Thanks, Saul On Fri, Jan 18, 2013 at 7:46 PM, Ian Lance Taylor <iant@xxxxxxxxxx> wrote: > On Fri, Jan 18, 2013 at 5:31 AM, Saul Tamari <stamari@xxxxxxxxx> wrote: >> On Fri, Jan 18, 2013 at 12:43 AM, Ian Lance Taylor <iant@xxxxxxxxxx> wrote: >>> >>> On Thu, Jan 17, 2013 at 2:11 PM, Saul Tamari <stamari@xxxxxxxxx> wrote: >>> > Is there a way to verify if there are wrongly initialized TLS >>> > variables in some application or I can only detect such cases when the >>> > application fails? >>> >>> You could probably look at the dynamic relocations and see if there >>> are any TLS relocations in the shared library that are not global >>> dynamic. >> >> >> I tried the following: >> [root@vm0 ~]# readelf -s ./mylib.so | grep TLS >> 808: 00000418 4 TLS GLOBAL DEFAULT 16 _ZN24MonitorWorkItemOpera >> 914: 00000008 4 TLS GLOBAL DEFAULT 16 _ZN12TQQQScheduler9_instan >> 1176: 00000414 4 TLS GLOBAL DEFAULT 16 time_monitor_list >> 2577: 00000000 4 TLS WEAK DEFAULT 16 _ZZN6Remote23MultiplexCli >> 2788: 00000004 4 TLS WEAK DEFAULT 16 _ZZN6Remote23MultiplexCli >> 249: 0000000c 4 TLS LOCAL DEFAULT 16 _ZL17pthread_qqq_owner >> 435: 00000010 1 TLS LOCAL DEFAULT 16 _ZL11g_in_syslog >> 436: 00000011 1024 TLS LOCAL DEFAULT 16 _ZL9g_tls_buf >> 2230: 00000418 4 TLS GLOBAL DEFAULT 16 _ZN24MonitorWorkItemOpera >> 2467: 00000000 4 TLS WEAK DEFAULT 16 _ZZN6Remote23MultiplexCli >> 3375: 00000008 4 TLS GLOBAL DEFAULT 16 _ZN12QQQScheduler9_instan >> 3660: 00000414 4 TLS GLOBAL DEFAULT 16 time_monitor_list >> 3766: 00000004 4 TLS WEAK DEFAULT 16 _ZZN6Remote23MultiplexCli >> >> So I see several TLS entries reported as WEAK and LOCAL and they could >> cause the TLS issues I was experiencing? > > Those are the symbols. The issue here is the relocations, displayed > by readelf -r. Dynamic and non-dynamic references to TLS symbols use > different relocations. > > Ian