<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Unexpected assmbly output using relative offsets in inline assembler"
href="https://bugs.llvm.org/show_bug.cgi?id=47749">47749</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Unexpected assmbly output using relative offsets in inline assembler
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>10.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Backend: AVR
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>s+llvm@s-ol.nu
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=24025" name="attach_24025" title="Example Program showing the unexpected behaviour">attachment 24025</a> <a href="attachment.cgi?id=24025&action=edit" title="Example Program showing the unexpected behaviour">[details]</a></span>
Example Program showing the unexpected behaviour
While porting C source
(<a href="https://github.com/cpldcpu/light_ws2812/blob/master/light_ws2812_AVR/Light_WS2812/light_ws2812.c">https://github.com/cpldcpu/light_ws2812/blob/master/light_ws2812_AVR/Light_WS2812/light_ws2812.c</a>)
to Zig, which uses LLVM as a backend, I noticed that the "rjmp .+0"
instructions that are used as 2-cycle NOPs under avr-gcc assembled to "rjmp
.-2" (infinite loops) under Zig and LLVM/Clang.
Here is some code to reproduce:
/*
$ clang -target avr-freestanding-eabi -mmcu=atmega32u2 demo_c.c -c -o
demo_c.o
$ avr-gcc -mmcu=atmega32u2 demo_c.o -o demo_c.elf
$ avr-objdump --siassemble=main demo_c.elf
demo_c.elf: file format elf32-avr
Disassembly of section .text:
00000000 <main>:
0: fe cf rjmp .-4 ; 0xfffffffe
<__eeprom_end+0xff7efffe>
2: ff cf rjmp .-2 ; 0x2 <main+0x2>
4: 00 c0 rjmp .+0 ; 0x6 <main+0x6>
6: 80 e0 ldi r24, 0x00 ; 0
8: 90 e0 ldi r25, 0x00 ; 0
a: 08 95 ret
*/
int main() {
asm("rjmp .-2");
asm("rjmp .+0");
asm("rjmp .+2");
}
(this file is also attached as demo_c.c)
Note that just inspecting the object file created using clang will confusingly
show "rjmp .+0" thrice since the actual offset is set using relocation fixups
at that stage.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>