<div dir="ltr"><div><div>Hi,<br><br></div>For the function call - yes, probably. But what about branching inside one function (standard if-then for example)?<br><br>For example:<br>echo "int g() { int a = 1; if (a > 3) return 1; return 0; }" | clang -x c - -o /tmp/a.o -c && objdump -d /tmp/a.o<br><br></div><div>Thanks,<br></div><div>Petr<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 19, 2017 at 8:06 PM, Friedman, Eli <span dir="ltr"><<a href="mailto:efriedma@codeaurora.org" target="_blank">efriedma@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><span class="">
<div class="m_-7483362400191765230moz-cite-prefix">On 1/19/2017 9:11 AM, Peter Bel via
llvm-dev wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<p class="m_-7483362400191765230gmail-MsoPlainText">Hi all,</p>
<p class="m_-7483362400191765230gmail-MsoPlainText"> </p>
<p class="m_-7483362400191765230gmail-MsoPlainText">I'm trying to make an LLVM backend
for the Adapteva's
Epiphany E16 CPU (used in Parallella board), using CPU0 and
some other backends
as examples, and I've got stuck with branching. </p>
<p class="m_-7483362400191765230gmail-MsoPlainText">When I'm printing out asm, all
branch labels are
printed as they should be. But when I'm trying to generate obj
file, I'm
getting zeros instead of PC-related offset in all branch
instructions.<br>
</p>
<p class="m_-7483362400191765230gmail-MsoPlainText">In short, what I'm doing:</p>
<p class="m_-7483362400191765230gmail-MsoPlainText">- Pattern (br bb:$addr) is
selected using
EpiphanyInstrInfo.td as BNONE32(ins jmptarget:$addr), Branch32
class</p>
<p class="m_-7483362400191765230gmail-MsoPlainText">- Branch32 class is defined in
EpiphanyInstrFormats.td
with bits<24> addr, which should go into bits{31-8} of
the MC
instruction. Those bits remain zeros after relaxation for some
reason.<br>
</p>
<p class="m_-7483362400191765230gmail-MsoPlainText">- jmptarget operand has type
OPERAND_PCREL, and uses
EncoderMethod "getJumpTargetOpValue" defined in
EpiphanyMCCodeEmitter.
If this method gets MCExpr, it creates fixup, and I can see
this fixup in
debug.</p>
<p class="m_-7483362400191765230gmail-MsoPlainText">- Fixup is called
fixup_Epiphany_PCREL24, and is defined
in EpiphanyFixupKinds and EpiphanyAsmBackend, with FKF_IsPCRel
flag.</p>
<p class="m_-7483362400191765230gmail-MsoPlainText"> </p>
<p class="m_-7483362400191765230gmail-MsoPlainText">Can someone please tell me if I am
missing something?<br>
</p>
</div>
</blockquote>
<br></span>
Are you sure there's actually a problem? On x86, for example:<br>
<br>
<tt>$ echo "int f(); int g() { return f(); }" | clang -x c - -o
/tmp/a.o -c && objdump -d /tmp/a.o</tt><tt><br>
</tt><tt><br>
</tt><tt>/tmp/a.o: file format elf64-x86-64</tt><tt><br>
</tt><tt><br>
</tt><tt><br>
</tt><tt>Disassembly of section .text:</tt><tt><br>
</tt><tt><br>
</tt><tt>0000000000000000 <g>:</tt><tt><br>
</tt><tt> 0: 55 push %rbp</tt><tt><br>
</tt><tt> 1: 48 89 e5 mov %rsp,%rbp</tt><tt><br>
</tt><tt> 4: b0 00 mov $0x0,%al</tt><tt><br>
</tt><tt> 6: e8 00 00 00 00 callq b <g+0xb></tt><tt><br>
</tt><tt> b: 5d pop %rbp</tt><tt><br>
</tt><tt> c: c3 retq</tt><tt><br>
</tt><br>
It looks like the call isn't calling the right function, but that's
fine: it'll get fixed by the linker.<span class="HOEnZb"><font color="#888888"><br>
<br>
-Eli<br>
<pre class="m_-7483362400191765230moz-signature" cols="72">--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project</pre>
</font></span></div>
</blockquote></div><br></div>