<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 1/19/2017 9:11 AM, Peter Bel via
llvm-dev wrote:<br>
</div>
<blockquote
cite="mid:CAKzDyZuKGHxBwOXPqEtuC3_HZwreDvmnJU7iqquZA6q7vHJOGw@mail.gmail.com"
type="cite">
<div dir="ltr">
<p class="gmail-MsoPlainText">Hi all,</p>
<p class="gmail-MsoPlainText"> </p>
<p class="gmail-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="gmail-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="gmail-MsoPlainText">In short, what I'm doing:</p>
<p class="gmail-MsoPlainText">- Pattern (br bb:$addr) is
selected using
EpiphanyInstrInfo.td as BNONE32(ins jmptarget:$addr), Branch32
class</p>
<p class="gmail-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="gmail-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="gmail-MsoPlainText">- Fixup is called
fixup_Epiphany_PCREL24, and is defined
in EpiphanyFixupKinds and EpiphanyAsmBackend, with FKF_IsPCRel
flag.</p>
<p class="gmail-MsoPlainText"> </p>
<p class="gmail-MsoPlainText">Can someone please tell me if I am
missing something?<br>
</p>
</div>
</blockquote>
<br>
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.<br>
<br>
-Eli<br>
<pre class="moz-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>
</body>
</html>