<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-GB link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>IIRC, reads of the PC must behave as they did when ARM processors had three-stage pipelines, regardless of the length of the actual pipeline. The consequence is that, when using PC in this way, it's value will be 2 instructions ahead of the address of the current instruction. This is so that software remains portable across cores.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Ashi [mailto:ashi08104@gmail.com] <br><b>Sent:</b> 08 March 2013 04:44<br><b>To:</b> Tim Northover<br><b>Cc:</b> Bernard Ogden; LLVM List<br><b>Subject:</b> Re: [LLVMdev] ARM assembler's syntax in clang<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>> And be warned that the PC doesn't point at the next instruction when you use it like this - I believe you don't need to modify it at all if you swap the pop and the .long.</span><br>Bernie, is it related to ARM pipeline? I'm interesting in this, is there any other additional information?<o:p></o:p></p><div><p class=MsoNormal>On Fri, Mar 8, 2013 at 4:59 AM, Tim Northover <<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>> wrote:<o:p></o:p></p><p class=MsoNormal>Hi Ashi,<o:p></o:p></p><div><p class=MsoNormal style='margin-bottom:12.0pt'><br>> ld: illegal text-relocation to _data_table in table.o from foo in<br>> use_table.o for architecture armv7<o:p></o:p></p></div><p class=MsoNormal>It looks like you're using iOS. I'm not familiar with the exact<br>workings of that platform, but I think a similar message would occur<br>in ELF-land.<br><br>If iOS *is* comparable, your issue is that symbols in dynamically<br>loaded objects can't (usually) be referenced directly because the code<br>section (and any embedded litpools) need to be identical no matter<br>where everything is loaded in memory. This is most of the point of<br>.dylib files: the instructions only have to exist once in memory and<br>can be shared. If the bytes would be different for each user that's<br>not possible -- the linker spots places where that happens and gives<br>an error.<br><br>My advice would be to compile a .c file (with "-S" to view the<br>assembly) which makes accesses like you're trying to do and copy its<br>code. There's no shame in it: I had a good idea of what ELF did but<br>still got the syntactic details wrong when I tried to write similar<br>code off the top of my head.<br><br>In this case, for example, I'd compile the C code (with "-fPIC" in<br>principle, though it seems to make no difference here. Actually, I'm<br>rather disturbed that you're trying to compile the C part of a .dylib<br>without "-fPIC". In the Linux world that's a no-no. Could be valid for<br>iOS, but I'd suggest you make sure if you don't know):<br><br>extern int data_table[];<br><br>int *wheres_data_table(void) {<br> return &data_table[0];<br>}<br><br>(N.b. "armv7" uses a movw/movt pair which is perfectly valid. If you<br>want to see how to do it using litpools, you need to compile for<br>"armv6" which doesn't have those instructions).<br><br>Cheers.<br><span style='color:#888888'><br>Tim.</span><o:p></o:p></p></div><p class=MsoNormal style='margin-bottom:12.0pt'>Thanks for all your great reply! Finally, I got it work by several ways, compiler's assembly output would help a lot(thanks Tim) and a linker option:-Wl,-read_only_relocs,suppress would also help.<br>And here is a similar problem under powerPC :<a href="http://lists.apple.com/archives/unix-porting/2008/Jan/msg00027.html">http://lists.apple.com/archives/unix-porting/2008/Jan/msg00027.html</a><br><br>here is my summary:<br>*** problem ***<br>LDR Rx, =Label is not supported under Clang<br><br>*** solution ***<br>replace LDR pseudo-instruction by manually loading Label. 2 methods are used, they are shown in use_table_m1.s and use_table_m2.s respectively. There are 7 targets in my Makefile, include several different option test(details are all in Makefile).<br>Test environment is Xcode4.6. The test_d_m1_1 can't be generated due to illegal text-relocation error and others can be generated, they are 3 dynamic targets and 3 static targets, the test_s_m1_2 have a warning due to -mdynamic-no-pic option. however I haven't test them on iOS device, I'm not sure whether the "-Wl,-read_only_relocs,suppress" option would really work.<br><br><br><br>/* ==begin table.c== */<br>int data_table[] = {0xff, 0xff};<br>/* ==end table.c== */<br><br>/* ==begin use_table_m1.s==<br> * use table by LDR <br> */<br> .text<br> .syntax unified<br> .align 4<br> .global foo<br> .thumb <br> .thumb_func<br><br>foo:<br> LDR r0,[PC,#4]<br> BX lr<br> .long _data_table <br>/* ==end use_table_m1.s== */<br><br>/* ==begin use_table_m2.s==<br> * use table by code from compiler's assembly out put <br> */<br> .text<br> .syntax unified<br> .align 4<br> .global foo<br> .thumb <br> .thumb_func<br><br>foo:<br> /* these lines are from compiler's assembly output($(CC) -S):<br> * extern int data_table[];<br> * int *wheres_data_table(void) {<br> * return &data_table[0];<br> * }<br> */<br> movw r1, :lower16:(L_data_table$non_lazy_ptr-(LPC0_0+4))<br> movt r1, :upper16:(L_data_table$non_lazy_ptr-(LPC0_0+4))<br>LPC0_0: <br> add r1, pc<br> ldr r1, [r1]<br> bx lr<br><br> .section __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers<br> .align 2<br>L_data_table$non_lazy_ptr:<br> .indirect_symbol _data_table<br> .long 0<br> <br> .subsections_via_symbols<br>/* ==end use_table_m2.s== */<br><br>/* ==begin test.c ==*/<br>extern int data_table[];<br>int main(void)<br>{<br> int a = data_table[0];<br> return 0;<br>}<br>/* ==end test.c ==*/<br><br><br>/* ==Makefile== */<br><br>CC = /Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang<br>AR = /Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar<br>CFLAG = -fPIC -Wall -arch armv7 -mcpu=cortex-a9 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk <br><br>all:dynamic static<br><br>dynamic:test_d_m1_1 test_d_m1_2 test_d_m2_1 test_d_m2_2<br><br>static:test_s_m1_1 test_s_m1_2 test_s_m2_1<br><br>test_d_m1_1:test.c libtest_m1_1.dylib<br> $(CC) $(CFLAG) test.c ./libtest_m1_1.dylib -o $@<br><br>test_d_m1_2:test.c libtest_m1_2.dylib<br> $(CC) $(CFLAG) test.c ./libtest_m1_2.dylib -o $@<br><br>test_d_m2_1:test.c libtest_m2_2.dylib<br> $(CC) $(CFLAG) test.c ./libtest_m2_2.dylib -o $@<br><br>test_d_m2_2:test.c libtest_m2_2.dylib<br> $(CC) $(CFLAG) test.c ./libtest_m2_2.dylib -o $@<br><br>test_s_m1_1:test.c libtest_m1_1.a<br> $(CC) $(CFLAG) $^ -o $@<br><br>test_s_m1_2:test.c libtest_m1_1.a<br> $(CC) $(CFLAG) -mdynamic-no-pic $^ -o $@<br><br>test_s_m2_1:test.o libtest_m2_1.a<br> $(CC) $(CFLAG) $^ -o $@<br><br>libtest_m1_1.dylib:table.o use_table_m1.o<br> $(CC) -dynamiclib $(CFLAG) $^ -o $@<br><br>libtest_m1_2.dylib:table.o use_table_m1.o<br> $(CC) -dynamiclib -Wl,-read_only_relocs,suppress $(CFLAG) $^ -o $@<br><br>libtest_m2_1.dylib:table.o use_table_m2.o<br> $(CC) -dynamiclib $(CFLAG) $^ -o $@<br><br>libtest_m2_2.dylib:table.o use_table_m2.o<br> $(CC) -dynamiclib -Wl,-read_only_relocs,suppress $(CFLAG) $^ -o $@<br><br>libtest_m1_1.a:table.o use_table_m1.o<br> $(AR) rcs $@ $^ <br><br>libtest_m2_1.a:table.o use_table_m2.o<br> $(AR) rcs $@ $^ <br><br>table.o:table.c<br> $(CC) -c $(CFLAG) $^ -o $@<br><br>test.o:test.c<br> $(CC) -c $(CFLAG) $^ -o $@<br><br>use_table_m1.o:use_table_m1.s<br> $(CC) -c -integrated-as $(CFLAG) $^ -o $@<br><br>use_table_m2.o:use_table_m2.s<br> $(CC) -c -integrated-as $(CFLAG) $^ -o $@<br><br>clean:<br> rm -f *.o libtest* test_d_m* *~ test_s_m*<br><br>/* == end Makefile == */<br><br>(all of these files are also available at <a href="http://dl.dropbox.com/u/13855163/ill_text_relocation_test.tar.gz">http://dl.dropbox.com/u/13855163/ill_text_relocation_test.tar.gz</a>)<br><br>Best Regards,<br>Ashi<o:p></o:p></p></div></div></div></div></body></html>