<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,</div><div dir="ltr">I'll try to give you more context through an example.<br><div>What I need is to extract the value of a variable (aka a label) inside an assembly file; for example given the following assembly (compiled with armv7-a clang 10.0.0):</div><div><br></div><div>---------------------------------------------</div><div><div>main:</div><div>        sub     sp, sp, #12</div><div>        mov     r2, #0</div><div>        str     r2, [sp, #8]</div><div>        str     r0, [sp, #4]</div><div>        str     r1, [sp]</div><div>        ldr     r0, .LCPI0_0</div><div>        ldr     r1, [r0, #4]</div><div>        ldr     r0, [r0, #8]</div><div>        mul     r2, r1, r0</div><div>        mov     r0, r2</div><div>        add     sp, sp, #12</div><div>        bx      lr</div><div>.LCPI0_0:</div><div>        .long   myvar</div><div>myvar:</div><div>        .long   0                       @ 0x0</div><div>        .long   1                       @ 0x1</div><div>        .long   2                       @ 0x2</div><div>        .long   3                       @ 0x3</div></div><div>---------------------------------------------<br></div><div><br></div><div>As you can see there's a label, namely "myvar", which is a variable in the C program. What I'm trying to achieve is, while parsing with the Asm Parser, get the parsed value of "myvar" out of the asm file (i.e. get the values of 0x0, 0x1, 0x2, 0x3). Is this possible?</div><div><br></div><div>Thanks a lot!</div></div></div></div></div><div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br> <table style="border-top:1px solid #d3d4de">
        <tr>
      <td style="width:55px;padding-top:18px"><a href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" target="_blank"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-green-avg-v1.png" alt="" width="46" height="29" style="width: 46px; height: 29px;"></a></td>
                <td style="width:470px;padding-top:17px;color:#41424e;font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px">Mail priva di virus. <a href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" target="_blank" style="color:#4453ea">www.avg.com</a>                 </td>
        </tr>
</table>
<a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"></a></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno mar 9 feb 2021 alle ore 03:01 Brian Cain <<a href="mailto:brian.cain@gmail.com">brian.cain@gmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I don't quite know exactly, but I suppose one way would be to modify ELFWriter::writeSymbol() to emit something when a symbol appears that matches your criteria.  I'm taking some liberty here assuming you can use an ELF object file.  I imagine there's something similar for macho/coff.<div><br></div><div>Then again, that information is present in the object file too.  You could use llvm-readelf or obj2yaml to extract what you want.<br></div><div><div><br></div><div>Maybe you could give a little more context about how you plan to use the info and the community could offer a better answer.<br><div><br></div><div><br></div><div><br></div><div> </div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 8, 2021 at 5:03 PM Pietro D'Ettole <<a href="mailto:progettoiotpolimi2019@gmail.com" target="_blank">progettoiotpolimi2019@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Brian, thanks for your reply.<div><br></div><div>My goal is to be able to extract from an assembly file (i.e. source compiled to assembly, directly) the static global vars declared in the source. So far I haven't found any API in the llvm asm parser to serve my purpose. Do you know if/ how I can accomplish that?<div><br></div><div>Thank you.<br><div><br><br>Il giorno sabato 6 febbraio 2021, Brian Cain <<a href="mailto:brian.cain@gmail.com" target="_blank">brian.cain@gmail.com</a>> ha scritto:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>You need to extract it from the source?  Is it possible to use the resulting object file instead?</div><div dir="auto"><br></div><div dir="auto">Note that there's no way to get an 'address' but you can get a section offset. The section offset for both code and data are available in the object file and from the assembler as it writes the object file.</div><div dir="auto"><br></div><div dir="auto">The contents of the assembly file - instructions and directives - contribute to the resulting layout.  The AsmParser can find tokens and build instructions but shouldn't know how it will get layed out.<br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Sat, Feb 6, 2021, 3:16 AM Pietro D'Ettole via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi all,<div><br></div><div>I'm a little bit stuck in code reading right now. Maybe some of you can help me to understand fast if what I need is feasible or not.</div><div>I was trying to understand if currently asm parser in llvm allows to easily extract from an asm file variable names alongside with their values and their addresses.</div><div><br></div><div>Thanks for the help!</div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" rel="noreferrer" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div></div>
</blockquote></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr">-Brian</div>
</blockquote></div>