<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=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-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-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
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-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hello,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’m trying to create position-independent ARM assembly code. For armcc I do the following:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> IMPORT foo<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">L_PIC ldr r0, L_FOO<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> add r0, pc, r0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">L_FOO DCD foo - (L_PIC + 8)<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">which for gcc looks similar:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> .extern foo<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">L_PIC: ldr r0, L_FOO<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> add r0, pc, r0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">L_FOO: .word foo - (L_PIC + 8)<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This works fine when using the GNU assembler. But when using Clang I get the following weird error: “symbol ‘_foo’ can not be undefined in a subtraction expression”. Looking at assembly code produced from C by the Clang compiler, it does
things differently, using the directive “.indirect_symbol”, which gcc and armcc don’t support:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> movw r0, :lower16:(L_FOO-(L_PIC+8))<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> movt r0, :upper16:(L_FOO-(L_PIC+8))<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">L_PIC: ldr r0, [pc, r0]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">L_FOO: .indirect_symbol _foo<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This would be fine except that I want to have one code base that can be built on multiple architectures with different tools. In the short term, I’m looking for an approach that will work with both gcc and Clang. In the longer term, it
would be nice if this could be “fixed” in Clang. (I put “fixed” in quotes since I don’t know if Clang has compatibility with armcc/gcc as a goal.) Thanks in advance for any suggestions.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">Jeff Schenck<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<br>
<hr>
<font face="Courier New" color="Black" size="3"><br>
Notice:<br>
This message and any included attachments are intended only for the use of the addressee, and may contain information that is privileged or confidential. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited. If you have received this communication in error, please destroy the original message and any copies or printouts hereof.<br>
</font>
</body>
</html>