<font face="arial" size="2"><div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">When I compile this LLVM IR….</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">
<div>@0 = private constant [19 x i8] c"V4main10Brightness\00", section "__TEXT,__swift3_typeref, regular, no_dead_strip"</div>
<div>@1 = private constant [9 x i8] c"Vs5UInt8\00", section "__TEXT,__swift3_typeref, regular, no_dead_strip"</div>
<div>@2 = private constant [18 x i8] c"currentBrightness\00", section "__TEXT,__swift3_reflstr, regular, no_dead_strip"</div>
<div>@_TMRfV4main10Brightness =</div>
<div>internal constant <{ i32, i16, i16, i32, i32, i32, i32 }></div>
<div>    <{</div>
<div>        i32 trunc</div>
<div>        (i64 sub</div>
<div>        (</div>
<div>            i64 ptrtoint ([19 x i8]* @0 to i64),</div>
<div>            i64 ptrtoint (<{ i32, i16, i16, i32, i32, i32, i32 }>* @_TMRfV4main10Brightness to i64)</div>
<div>            )</div>
<div>        to i32),</div>
<div>        </div>
<div>        i16 0,</div>
<div>        i16 12,</div>
<div>        i32 1,</div>
<div>        i32 0,</div>
<div>        </div>
<div>        i32 trunc</div>
<div>        (i64 sub</div>
<div>        (i64 ptrtoint ([9 x i8]* @1 to i64),</div>
<div>        i64 add (i64 ptrtoint (<{ i32, i16, i16, i32, i32, i32, i32 }>* @_TMRfV4main10Brightness to i64),</div>
<div>            i64 16)</div>
<div>        ) to i32),</div>
<div>        i32 trunc</div>
<div>        (i64 sub</div>
<div>        (</div>
<div>        i64 ptrtoint ([18 x i8]* @2 to i64),</div>
<div>        i64 add</div>
<div>        (i64 ptrtoint (<{ i32, i16, i16, i32, i32, i32, i32 }>* @_TMRfV4main10Brightness to i64),</div>
<div>        i64 20)</div>
<div>        ) to i32)</div>
<div>        }>, section "__TEXT,__swift3_fieldmd, regular, no_dead_strip", align 4</div>
</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">…on a couple of targets, it seems to produce invalid MC graphs that then fail to compile.</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">My chosen platform is AVR but it looks like it probably produces strange fixups on MIPS too.</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">I was initially chatting to the AVR rust team about this but I’m not sure it’s an AVR only problem. I’d like some help with understanding why these fixups are being created.</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">When compiled on AVR, I get the error "LLVM ERROR: expected relocatable expression”.</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">If I compile to asm, I get these fixups…</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">llc -march=avr -mcpu=atmega328p cause-relocation-error.ll -filetype=obj -debug 2>&1|
<div>grep unnamed_4</div>
<div>        Fixups:[</div>
<MCFixup Offset:0 Value:(__unnamed_4&65535)-((_TMRfV4main10Brightness&65535)+16) Kind:2>]>,<br />           (__unnamed_4, Index:0, ),<br />        Fixups:[<MCFixup Offset:0 Value:(__unnamed_4&65535)-((_TMRfV4main10Brightness&65535)+16) Kind:2>]>,<br />           (__unnamed_4, Index:0, ),<br />        Fixups:[<MCFixup Offset:0 Value:(__unnamed_4&65535)-((_TMRfV4main10Brightness&65535)+16) Kind:2>]>,<br />           (__unnamed_4, Index:0, ),</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">The output .s file in assembly:</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">.text<br /> .file "min-3.ll"<br /><br /> .type __unnamed_3,@object     ; @2<br /> .section "__TEXT,__swift3_typeref, regular, no_dead_strip","a",@progbits<br /> .p2align 4<br />__unnamed_3:<br /> .asciz "V4main10Brightness"<br /> .size __unnamed_3, 19<br /><br /> .type __unnamed_4,@object     ; @3<br />__unnamed_4:<br /> .asciz "Vs5UInt8"<br /> .size __unnamed_4, 9<br /><br /> .type __unnamed_5,@object     ; @4<br /> .section "__TEXT,__swift3_reflstr, regular, no_dead_strip","a",@progbits<br /> .p2align 4<br />__unnamed_5:<br /> .asciz "currentBrightness"<br /> .size __unnamed_5, 18<br /><br /> .type _TMRfV4main10Brightness,@object ; @_TMRfV4main10Brightness<br /> .section "__TEXT,__swift3_fieldmd, regular, no_dead_strip","a",@progbits<br /> .p2align 2<br />_TMRfV4main10Brightness:<br /> .long __unnamed_3-_TMRfV4main10Brightness<br /> .short 0                       ; 0x0<br /> .short 12                      ; 0xc<br /> .long 1                       ; 0x1<br /> .long 0                       ; 0x0<br /> .long (__unnamed_4&65535)-((_TMRfV4main10Brightness&65535)+16)<br /> .long (__unnamed_5&65535)-((_TMRfV4main10Brightness&65535)+20)<br /> .size _TMRfV4main10Brightness, 24</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">If I try to compile this file with llvm-mc it doesn’t work, with much the same error.</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">Debugging with lldb, I found that in MCAssembler::evaluateFixup it calls MCExpr::evaluateAsRelocatableImpl and that returns false because it doesn’t accept a fixup like __unnamed_4&65535, binary MC expressions only seem to allow combining symbols using + or - (using EvaluateSymbolicAdd), not and, or, div, mul… etc.</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">On x86 the assembly output is simpler:</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">llc cause-relocation-error.ll -filetype=obj -debug 2>&1|
<div>grep unnamed_4                                              </div>
<div>        Fixups:[</div>
<MCFixup Offset:0 Value:.L__unnamed_4-(_TMRfV4main10Brightness+16) Kind:2>]>
<div>,</div>
<div>           (.L__unnamed_4, Index:0, ),</div>
<div>        Fixups:[</div>
<MCFixup Offset:0 Value:.L__unnamed_4-(_TMRfV4main10Brightness+16) Kind:2>]>
<div>,</div>
<div>           (.L__unnamed_4, Index:0, ),</div>
<div>        Fixups:[</div>
<MCFixup Offset:0 Value:.L__unnamed_4-(_TMRfV4main10Brightness+16) Kind:2>]>
<div>,</div>
<div>           (.L__unnamed_4, Index:0, ),</div>
</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">Which compiles fine because the fixup combines symbols using only + and -, not &.</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">On MIPS, again the & operator is being put into expressions that end up in fixups.</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">llc -march=mips cause-relocation-error.ll -filetype=obj -debug 2>&1|
<div>grep unnamed_4                                 </div>
<div>        Fixups:[</div>
<MCFixup Offset:0 Value:(($__unnamed_4)&4294967295)-((_TMRfV4main10Brightness&4294967295)+16) Kind:2>]>,<br />           ($__unnamed_4, Index:0, ),<br />        Fixups:[<MCFixup Offset:0 Value:(($__unnamed_4)&4294967295)-((_TMRfV4main10Brightness&4294967295)+16) Kind:2>]>,<br />           ($__unnamed_4, Index:0, ),<br />        Fixups:[<MCFixup Offset:0 Value:(($__unnamed_4)&4294967295)-((_TMRfV4main10Brightness&4294967295)+16) Kind:2>]>,<br />           ($__unnamed_4, Index:0, ),</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">Which I don’t think would compile.</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">AVR is an experimental target but I think MIPS is mature?  So I’m trying to get to the bottom of how LLVM is lowering to these expressions in fixups, when they cannot be evaluated by the MC layer?</div>
<div style="caret-color: #000000; color: #000000; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Helvetica; font-size: 12px;">Can anyone give any advice?</div></font>