<div dir="ltr">The size suffix thing is a weird quirk in our assembler I should look into fixing. Instructions in at&t syntax usually have a size suffix that is often optional<div><br></div><div>For example:</div><div>  add %ax, %bx</div><div>and</div><div>  addw %ax, %bx</div><div><br></div><div>Are equivalent because the register name indicates the size.</div><div><br></div><div>but for an instruction like this</div><div>  addw $1, (%ax)</div><div><br></div><div>There is nothing to infer the size from so an explicit suffix is required.</div><div><br></div><div>So for an instruction like "add %ax, %bx" from above, we try to guess the size suffix from the register. In your case, you used a segment register which we couldn't guess the size from. And then we printed a bad error message.</div><div><br></div><div>There's no quick reference as such for the meaning of the various X86::XXXXXX names. But the complete list of them is in lib/Target/X86/X86GenInstrInfo.inc in your build area. The names are meant to be fairly straight forward to understand. The first part of the name should almost always be the instruction name from the Intel/AMD manuals. The lower case letters at the end sort of convey operand types, but often not the number of operands even though it looks that way. <span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">The most common letters are 'r' for register, 'm' for memory and 'i' for immediate. Numbers after 'i' specify the size of the immediate if its important to distinguish from other sizes or different than the size of the instruction. </span>The lower case letters are most useful to distinguish different instructions from each other. So for example, if two instructions only differ in the lower case letters and one says "rr" and one says "rm", the first is the register form and the second is the memory form of the same instruction.</div><div><br></div><div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Jun 23, 2018 at 7:55 PM K Jelesnianski <<a href="mailto:kjski@vt.edu">kjski@vt.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear Craig,<br>
<br>
Thank you super much for the quick reply! Yea I'm still new to working<br>
on the back-end and that sounds great. I already have the raw assembly<br>
of what I want to accomplish so this is perfect. I just tried it and<br>
yea, I will have to break down my assembly even further to more<br>
simpler operations. You're right about my assembly dealing with<br>
segment registers as I'm getting the following error:<br>
"error: unknown use of instruction mnemonic without a size suffix"<br>
<br>
Just curious, what does it mean by size suffix??<br>
<br>
It's super cool to see the equivalent with "-show-inst"!!! Thank you<br>
so much for this help!<br>
<br>
Last note, I know that the definitions (e.g. def SUB32ri) of the<br>
various instructions can be found in the various ****.td, but is there<br>
documentation where the meaning or quick reference of every<br>
X86::XXXXXX llvm instruction macro can found, so I can quickly pick<br>
and choose which actual macro I need to use, to "work forwards" rather<br>
than working backwards by writing the assembly first and using llvm-mc<br>
-show-inst  ??<br>
<br>
Thanks super much again.<br>
<br>
Sincerely,<br>
<br>
Chris Jelesnianski<br>
Graduate Research Assistant<br>
Virginia Tech<br>
<br>
On Sat, Jun 23, 2018 at 8:45 PM, Craig Topper <<a href="mailto:craig.topper@gmail.com" target="_blank">craig.topper@gmail.com</a>> wrote:<br>
> More specifically there is no instruction that can add/subtract segment<br>
> registers. They can only be updated my the mov segment register<br>
> instructions, opcodes 0x8c and 0x8e in x86 assembly.<br>
><br>
> I suggest you write the text version of the assembly you want to generate<br>
> and assemble it with llvm-mc. This will tell you if its even valid. After<br>
> that you can use -show-inst to print the names of the instructions that X86<br>
> uses that you can give to BuildMI.<br>
><br>
> ~Craig<br>
><br>
><br>
> On Sat, Jun 23, 2018 at 5:36 PM Craig Topper <<a href="mailto:craig.topper@gmail.com" target="_blank">craig.topper@gmail.com</a>> wrote:<br>
>><br>
>> The SUB32ri can't instruction can't operate on segment registers. It<br>
>> operates on EAX/EBX/EDX/ECX/EBP, etc. When it gets encoded only 3 or 4 bits<br>
>> of the register value make it into the binary encoding. Objdump just<br>
>> extracts those 3 or 4 bits back out and prints one of the<br>
>> EAX/EBX/EDX/ECX/EBP registers that those bits correspond to.<br>
>><br>
>> ~Craig<br>
>><br>
>><br>
>> On Sat, Jun 23, 2018 at 5:28 PM K Jelesnianski via llvm-dev<br>
>> <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
>>><br>
>>> Dear All,<br>
>>><br>
>>> Currently I am trying to inject custom x86-64 assembly into a<br>
>>> functions entry basic block. More specifically, I am trying to build<br>
>>> assembly in a machine function pass from scratch.<br>
>>><br>
>>> While the dumped machine function instruction info displays that %gs<br>
>>> will be used, when I perform objdump -d on my executable I am see that<br>
>>> %gs is replaced by %ebp? Why is this happening?<br>
>>><br>
>>> I know it probably has something to do with me not specifying operands<br>
>>> properly, but I cannot find enough documentation on this besides<br>
>>> looking through code comments such as X86BaseInfo.cpp. I feel there<br>
>>> isn't enough for me to be able to connect the dots.<br>
>>><br>
>>> Below I have sample code: %gs holds a base address to a memory<br>
>>> location where I am trying to store information. I am trying to update<br>
>>> the %gs register pointer location before saving more values, etc.<br>
>>><br>
>>> LLVM C++ codeMachine Function pass code:<br>
>>> MachineInstrBuilder sss = BuildMI(MBB, MBB.begin(), DL,<br>
>>> TII->get(X86::SUB32ri),X86::GS)<br>
>>>                     .addReg(X86::GS)<br>
>>>                     .addImm(0x8);<br>
>>><br>
>>> machine function pass dump:<br>
>>>  %gs = SUB32ri %gs, 8, implicit-def %eflags<br>
>>><br>
>>> Objdump -d assembly from executable<br>
>>>   400510:   81 ed 04 00 00 00       sub    $0x8,%ebp<br>
>>><br>
>>><br>
>>> TLDR: I am trying to create custom assembly via BuildMI() and manipulate<br>
>>> segment<br>
>>> registers via a MachineFunctionPass.<br>
>>><br>
>>> I have looked at LLVMs safestack implementation, but they are taking a<br>
>>> fairly complicated hybrid approach between an IR Function pass with<br>
>>> Backend support. I would like to stay as a single machinefunction<br>
>>> pass.<br>
>>><br>
>>> Believe me I would do this at the IR level if I didnt need to<br>
>>> specifically use the segment registers.<br>
>>><br>
>>> Thanks for the help in advance!<br>
>>><br>
>>> Sincerely,<br>
>>><br>
>>> Christopher Jelesnianski<br>
>>> Graduate Research Assistant<br>
>>> Virginia Tech<br>
>>> _______________________________________________<br>
>>> LLVM Developers mailing list<br>
>>> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
>>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>