<div dir="ltr"><pre class="" style="white-space:pre-wrap;word-wrap:break-word;color:rgb(0,0,0)">> we cannot combine the 2 ldr instructions and litpools because they get added to
> a different pc to form the correct address.
I wonder how we can figure out the reason such as the above statement from the libcoreclr.so (or clsload.s). </pre><pre class="" style="white-space:pre-wrap;word-wrap:break-word;color:rgb(0,0,0)">Actually, I could not find the same assembly code that you commented to r268662 from clsload.s file.
For example,
--------------- with -O1 of clang : clsload-assembly-O1/clsload.s-----------------------------------------------------------------------------------</pre><pre class="" style="word-wrap:break-word"><font color="#000000"><span style="white-space:pre-wrap"> 219 .Ltmp11:
220 @DEBUG_VALUE: ComputeLoaderModuleWorker:pFirstNonSystemSharedModule <- R0
221 mov r11, r0
222 .Ltmp12:
223 @DEBUG_VALUE: ComputeLoaderModuleWorker:pFirstNonSystemSharedModule <- R11
224 @DEBUG_VALUE: ComputeLoaderModuleWorker:pDefinitionModule <- R11
225 ldr r0, .LCPI0_0
226 ldr r5, .LCPI0_1
227 mov r4, r2
228 .Ltmp13:
229 @DEBUG_VALUE: ComputeLoaderModuleWorker:classInst <- R4
230 .LPC0_0:
231 add r0, pc
232 mov r6, r3
233 .Ltmp14:
234 @DEBUG_VALUE: ComputeLoaderModuleWorker:methodInst <- R6
235 mov r9, r1
236 .Ltmp15:
237 @DEBUG_VALUE: ComputeLoaderModuleWorker:token <- R9
238 ldr r0, [r5, r0]
239 ldr r0, [r0]
240 str r0, [sp, #88]
241 .loc 64 98 9 @ /work/dotnet/arm-32/coreclr/src/vm/clsload.cpp:98 :9
</span></font></pre><pre class="" style="word-wrap:break-word"><span style="color:rgb(0,0,0);white-space:pre-wrap;font-family:arial,sans-serif">--------------- with -O2 of clang : </span><font color="#000000" face="arial, sans-serif"><span style="white-space:pre-wrap">clsload-assembly-O2/clsload.s</span></font><span style="color:rgb(0,0,0);font-family:arial,sans-serif;white-space:pre-wrap">-------------------------------------</span></pre><div><div>219 .Ltmp11: </div><div> 220 @DEBUG_VALUE: ComputeLoaderModuleWorker:pFirstNonSystemSharedModule <- R0</div><div> 221 mov r9, r0</div><div> 222 .Ltmp12: </div><div> 223 @DEBUG_VALUE: ComputeLoaderModuleWorker:pFirstNonSystemSharedModule <- R9</div><div> 224 @DEBUG_VALUE: ComputeLoaderModuleWorker:pDefinitionModule <- R9</div><div> 225 ldr.w r0, .LCPI0_0 </div><div> 226 .loc 34 738 50 discriminator 2 @ /work/dotnet/arm-32/coreclr/src/vm/crossg en/../typehandle.h:738:50</div><div> 227 .Ltmp13: </div><div> 228 ldr.w r8, .LCPI0_1</div><div> 229 mov r6, r2</div><div> 230 .Ltmp14: </div><div> 231 @DEBUG_VALUE: ComputeLoaderModuleWorker:classInst <- R6</div><div> 232 .LPC0_0: </div><div> 233 add r0, pc</div><div> 234 mov r5, r3</div><div> 235 .Ltmp15: </div><div> 236 @DEBUG_VALUE: ComputeLoaderModuleWorker:methodInst <- R5</div><div> 237 mov r4, r1</div></div><div><br></div><div><br></div><div><span style="font-size:12.8px">> The inliner was needed in this case because most TLS accesses were </span><span style="font-size:12.8px">hidden away in GetThread. <br>> You could write C code that would fail at </span><span style="font-size:12.8px">-O1 if you tried.<br></span><br>It's strange. I can normally run C# console applications with libcoreclr.so that is built by -O1 such as -O0<br><br><div>---------------------------[ libcoreclr.so: with -O0 ]----------------------------------<br></div><div> 185920 000a221c <GetThread>:</div><div> 185921 a221c: b580 push {r7, lr}</div><div> 185922 a221e: 466f mov r7, sp</div><div> 185923 a2220: e7ff b.n a2222 <GetThread+0x6></div><div> 185924 a2222: 2000 movs r0, #0</div><div> 185925 a2224: 2800 cmp r0, #0</div><div> 185926 a2226: d106 bne.n a2236 <GetThread+0x1a></div><div> 185927 a2228: e7ff b.n a222a <GetThread+0xe></div><div> 185928 a222a: 4803 ldr r0, [pc, #12] ; (a2238 <GetThread+0x1c>)</div><div> 185929 a222c: 4478 add r0, pc</div><div> 185930 a222e: f795 eca0 blx 37b70 <__tls_get_addr@plt></div><div> 185931 a2232: 6800 ldr r0, [r0, #0]</div><div> 185932 a2234: bd80 pop {r7, pc}</div><div> 185933 a2236: defe .short 0xdefe </div><div> 185934 a2238: 00a4f908 .word 0x00a4f908</div><div> 185935 </div><div><br></div><div><br></div><div>---------------------------[ libcoreclr.so: with -O1 ]----------------------------------</div><div> 73533 00066b10 <GetThread>: </div><div> 73534 66b10: b580 push {r7, lr}</div><div> 73535 66b12: 466f mov r7, sp</div><div> 73536 66b14: 4802 ldr r0, [pc, #8] ; (66b20 <GetThread+0x10>)</div><div> 73537 66b16: 4478 add r0, pc</div><div> 73538 66b18: f7d0 ece0 blx 374dc <__tls_get_addr@plt></div><div> 73539 66b1c: 6800 ldr r0, [r0, #0]</div><div> 73540 66b1e: bd80 pop {r7, pc}</div><div> 73541 66b20: 0071bdf6 .word 0x0071bdf6</div><div> 73542 </div><div><br></div><div><br></div><div><br></div><div>---------------------------[ libcoreclr.so: with -O2 ]----------------------------------</div><div> </div><div> 572341 001a37e8 <GetThread>: </div><div> 572342 1a37e8: b580 push {r7, lr}</div><div> 572343 1a37ea: 466f mov r7, sp</div><div> 572344 1a37ec: 4802 ldr r0, [pc, #8] ; (1a37f8 <GetThread+0x10>)</div><div> 572345 1a37ee: 4478 add r0, pc</div><div> 572346 1a37f0: f68d eee4 blx 315bc <__tls_get_addr@plt></div><div> 572347 1a37f4: 6800 ldr r0, [r0, #0]</div><div> 572348 1a37f6: bd80 pop {r7, pc}</div><div> 572349 1a37f8: 0079a2be .word 0x0079a2be</div><div> 572350 </div><div><br></div><div><br></div><div>---------------------------[ libcoreclr.so: with -O3 ]----------------------------------</div><div> 592749 001b12d8 <GetThread>: </div><div> 592750 1b12d8: b580 push {r7, lr}</div><div> 592751 1b12da: 466f mov r7, sp</div><div> 592752 1b12dc: 4802 ldr r0, [pc, #8] ; (1b12e8 <GetThread+0x10>)</div><div> 592753 1b12de: 4478 add r0, pc</div><div> 592754 1b12e0: f680 e950 blx 31584 <__tls_get_addr@plt></div><div> 592755 1b12e4: 6800 ldr r0, [r0, #0]</div><div> 592756 1b12e6: bd80 pop {r7, pc}</div><div> 592757 1b12e8: 007d47ca .word 0x007d47ca</div><div> 592758 </div><div><br></div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 11, 2016 at 11:32 AM, Tim Northover <span dir="ltr"><<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 10 May 2016 at 19:16, Geunsik Lim <<a href="mailto:leemgs@gmail.com">leemgs@gmail.com</a>> wrote:<br>
>> Given something like:<br>
>><br>
>> ldr r0, .LCPI0_0 (== pc-rel var)<br>
>> add r0, pc<br>
>><br>
>> ldr r1, .LCPI0_1 (== pc-rel var)<br>
>> add r1, pc<br>
>><br>
><br>
> Where can we get the above assembly code?<br>
> For example, from clsload.s with "save-temps" flag?<br>
<br>
</span>Clang's -save-temps output is pretty close to this (or alternatively<br>
"clang -S" if you don't want the other files) but I actually just made<br>
up these examples to illustrate what was happening.<br>
<br>
Cheers.<br>
<span class="HOEnZb"><font color="#888888"><br>
Tim.<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><a href="http://leemgs.fedorapeople.org" style="font-family:Tahoma" target="_blank">http://leemgs.fedorapeople.org</a><span style="font-family:Tahoma"> </span></div><div>Don't try to avoid pain if you fail.<br>If you decided to face the challenges in life, <br>you can gain a lot by giving your best.<br>Cheolsang Jeong's Book & life<br>--<br></div></div></div>
</div>