<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 11, 2014 at 4:15 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">----- Original Message -----<br>
> From: "Sean Silva" <<a href="mailto:chisophugis@gmail.com">chisophugis@gmail.com</a>><br>
> To: "Hal Finkel" <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>><br>
> Cc: "Chad Rosier" <<a href="mailto:mcrosier@codeaurora.org">mcrosier@codeaurora.org</a>>, <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> Sent: Tuesday, November 11, 2014 6:03:10 PM<br>
> Subject: Re: [llvm] r221639 - [yaml2obj] Support AArch64 relocations.<br>
><br>
> On Mon, Nov 10, 2014 at 10:42 PM, Hal Finkel < <a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a> ><br>
> wrote:<br>
><br>
><br>
><br>
><br>
> ----- Original Message -----<br>
> > From: "Chad Rosier" < <a href="mailto:mcrosier@codeaurora.org">mcrosier@codeaurora.org</a> ><br>
> > To: <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> > Sent: Monday, November 10, 2014 5:02:04 PM<br>
> > Subject: [llvm] r221639 - [yaml2obj] Support AArch64 relocations.<br>
> ><br>
> > Author: mcrosier<br>
> > Date: Mon Nov 10 17:02:03 2014<br>
> > New Revision: 221639<br>
> ><br>
> > URL: <a href="http://llvm.org/viewvc/llvm-project?rev=221639&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=221639&view=rev</a><br>
> > Log:<br>
> > [yaml2obj] Support AArch64 relocations.<br>
> ><br>
> > Patch by Daniel Stewart < <a href="mailto:stewartd@codeaurora.org">stewartd@codeaurora.org</a> >!<br>
> > Phabricator Revision: <a href="http://reviews.llvm.org/D6192" target="_blank">http://reviews.llvm.org/D6192</a><br>
> ><br>
> > Added:<br>
> > llvm/trunk/test/Object/AArch64/<br>
> > llvm/trunk/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml<br>
> > Modified:<br>
> > llvm/trunk/lib/Object/ELFYAML.cpp<br>
> ><br>
> > Modified: llvm/trunk/lib/Object/ELFYAML.cpp<br>
> > URL:<br>
> > <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ELFYAML.cpp?rev=221639&r1=221638&r2=221639&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ELFYAML.cpp?rev=221639&r1=221638&r2=221639&view=diff</a><br>
> > ==============================================================================<br>
> > --- llvm/trunk/lib/Object/ELFYAML.cpp (original)<br>
> > +++ llvm/trunk/lib/Object/ELFYAML.cpp Mon Nov 10 17:02:03 2014<br>
> > @@ -672,6 +672,92 @@ void ScalarEnumerationTraits<ELFYAML::EL<br>
> > ECase(R_386_IRELATIVE)<br>
> > ECase(R_386_NUM)<br>
> > break;<br>
><br>
> Is this function supposed to be synchronized with lib/Object/ELF.cpp<br>
> (which has one function: getELFRelocationTypeName). Keeping these in<br>
> synch manually seems error-prone (and somewhat silly). Can we<br>
> refactor this so that we don't have two essentially-identical lists<br>
> of relocation names in the two files?<br>
><br>
><br>
><br>
> Hi Hal, I'm the one that originally wrote the yaml2obj ELF support<br>
> (although Simon did the relocation support). There is a lot of<br>
> duplication with llvm-readobj as well (not just of the relocations,<br>
> but basically everything else; including another whole copy of all<br>
> relocations in test/tools/llvm-readobj/Inputs/relocs.py).<br>
><br>
><br>
> We could improve the state of things by putting stuff in tables of<br>
> `struct { Integer Val; const char *Str; }` static data. That at<br>
> least leaves just one place to update when the header changes.<br>
><br>
><br>
> It might be practical to write a 20-30 line python script to parse<br>
> through ELF.h and generate the tables (might require some changes to<br>
> ELF.h to make it easy to generate, e.g. giving each enum a name from<br>
> which the table name can be derived, and also an explicit type).<br>
> That way we we can instantly refresh all of them with little effort.<br>
> I would suggest using Clang's parser, but I'm not sure we have quite<br>
> gotten to the ease-of-use/ease-of-deployability point where we can<br>
> expect every LLVM developer to run a clang-(AST-)based tool on a<br>
> whim as part of the development process.<br>
<br>
</div></div>I think that an even easier method is to use the preprocessor -- just as Clang does with its .def files (see include/clang/Basic/*.def for examples). If we put these into a .def file, then that file can be included multiple times, and each time the relevant macro can be defined appropriately to do the right thing.<br>
<span class="HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br></div><div>I like it! It's going to leave things pretty ugly, but whatever.</div><div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="HOEnZb"><font color="#888888">
 -Hal<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
><br>
> -- Sean Silva<br>
><br>
><br>
><br>
><br>
><br>
> Thanks again,<br>
> Hal<br>
><br>
><br>
><br>
> > + case ELF::EM_AARCH64:<br>
> > + ECase(R_AARCH64_NONE)<br>
> > + ECase(R_AARCH64_ABS64)<br>
> > + ECase(R_AARCH64_ABS32)<br>
> > + ECase(R_AARCH64_ABS16)<br>
> > + ECase(R_AARCH64_PREL64)<br>
> > + ECase(R_AARCH64_PREL32)<br>
> > + ECase(R_AARCH64_PREL16)<br>
> > + ECase(R_AARCH64_MOVW_UABS_G0)<br>
> > + ECase(R_AARCH64_MOVW_UABS_G0_NC)<br>
> > + ECase(R_AARCH64_MOVW_UABS_G1)<br>
> > + ECase(R_AARCH64_MOVW_UABS_G1_NC)<br>
> > + ECase(R_AARCH64_MOVW_UABS_G2)<br>
> > + ECase(R_AARCH64_MOVW_UABS_G2_NC)<br>
> > + ECase(R_AARCH64_MOVW_UABS_G3)<br>
> > + ECase(R_AARCH64_MOVW_SABS_G0)<br>
> > + ECase(R_AARCH64_MOVW_SABS_G1)<br>
> > + ECase(R_AARCH64_MOVW_SABS_G2)<br>
> > + ECase(R_AARCH64_LD_PREL_LO19)<br>
> > + ECase(R_AARCH64_ADR_PREL_LO21)<br>
> > + ECase(R_AARCH64_ADR_PREL_PG_HI21)<br>
> > + ECase(R_AARCH64_ADD_ABS_LO12_NC)<br>
> > + ECase(R_AARCH64_LDST8_ABS_LO12_NC)<br>
> > + ECase(R_AARCH64_TSTBR14)<br>
> > + ECase(R_AARCH64_CONDBR19)<br>
> > + ECase(R_AARCH64_JUMP26)<br>
> > + ECase(R_AARCH64_CALL26)<br>
> > + ECase(R_AARCH64_LDST16_ABS_LO12_NC)<br>
> > + ECase(R_AARCH64_LDST32_ABS_LO12_NC)<br>
> > + ECase(R_AARCH64_LDST64_ABS_LO12_NC)<br>
> > + ECase(R_AARCH64_LDST128_ABS_LO12_NC)<br>
> > + ECase(R_AARCH64_GOTREL64)<br>
> > + ECase(R_AARCH64_GOTREL32)<br>
> > + ECase(R_AARCH64_ADR_GOT_PAGE)<br>
> > + ECase(R_AARCH64_LD64_GOT_LO12_NC)<br>
> > + ECase(R_AARCH64_TLSLD_MOVW_DTPREL_G2)<br>
> > + ECase(R_AARCH64_TLSLD_MOVW_DTPREL_G1)<br>
> > + ECase(R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC)<br>
> > + ECase(R_AARCH64_TLSLD_MOVW_DTPREL_G0)<br>
> > + ECase(R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC)<br>
> > + ECase(R_AARCH64_TLSLD_ADD_DTPREL_HI12)<br>
> > + ECase(R_AARCH64_TLSLD_ADD_DTPREL_LO12)<br>
> > + ECase(R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC)<br>
> > + ECase(R_AARCH64_TLSLD_LDST8_DTPREL_LO12)<br>
> > + ECase(R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC)<br>
> > + ECase(R_AARCH64_TLSLD_LDST16_DTPREL_LO12)<br>
> > + ECase(R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC)<br>
> > + ECase(R_AARCH64_TLSLD_LDST32_DTPREL_LO12)<br>
> > + ECase(R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC)<br>
> > + ECase(R_AARCH64_TLSLD_LDST64_DTPREL_LO12)<br>
> > + ECase(R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC)<br>
> > + ECase(R_AARCH64_TLSIE_MOVW_GOTTPREL_G1)<br>
> > + ECase(R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC)<br>
> > + ECase(R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21)<br>
> > + ECase(R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC)<br>
> > + ECase(R_AARCH64_TLSIE_LD_GOTTPREL_PREL19)<br>
> > + ECase(R_AARCH64_TLSLE_MOVW_TPREL_G2)<br>
> > + ECase(R_AARCH64_TLSLE_MOVW_TPREL_G1)<br>
> > + ECase(R_AARCH64_TLSLE_MOVW_TPREL_G1_NC)<br>
> > + ECase(R_AARCH64_TLSLE_MOVW_TPREL_G0)<br>
> > + ECase(R_AARCH64_TLSLE_MOVW_TPREL_G0_NC)<br>
> > + ECase(R_AARCH64_TLSLE_ADD_TPREL_HI12)<br>
> > + ECase(R_AARCH64_TLSLE_ADD_TPREL_LO12)<br>
> > + ECase(R_AARCH64_TLSLE_ADD_TPREL_LO12_NC)<br>
> > + ECase(R_AARCH64_TLSLE_LDST8_TPREL_LO12)<br>
> > + ECase(R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC)<br>
> > + ECase(R_AARCH64_TLSLE_LDST16_TPREL_LO12)<br>
> > + ECase(R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC)<br>
> > + ECase(R_AARCH64_TLSLE_LDST32_TPREL_LO12)<br>
> > + ECase(R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC)<br>
> > + ECase(R_AARCH64_TLSLE_LDST64_TPREL_LO12)<br>
> > + ECase(R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC)<br>
> > + ECase(R_AARCH64_TLSDESC_ADR_PAGE)<br>
> > + ECase(R_AARCH64_TLSDESC_LD64_LO12_NC)<br>
> > + ECase(R_AARCH64_TLSDESC_ADD_LO12_NC)<br>
> > + ECase(R_AARCH64_TLSDESC_CALL)<br>
> > + ECase(R_AARCH64_COPY)<br>
> > + ECase(R_AARCH64_GLOB_DAT)<br>
> > + ECase(R_AARCH64_JUMP_SLOT)<br>
> > + ECase(R_AARCH64_RELATIVE)<br>
> > + ECase(R_AARCH64_TLS_DTPREL64)<br>
> > + ECase(R_AARCH64_TLS_DTPMOD64)<br>
> > + ECase(R_AARCH64_TLS_TPREL64)<br>
> > + ECase(R_AARCH64_TLSDESC)<br>
> > + ECase(R_AARCH64_IRELATIVE)<br>
> > + break;<br>
> > default:<br>
> > llvm_unreachable("Unsupported architecture");<br>
> > }<br>
> ><br>
> > Added: llvm/trunk/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml<br>
> > URL:<br>
> > <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml?rev=221639&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml?rev=221639&view=auto</a><br>
> > ==============================================================================<br>
> > --- llvm/trunk/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml<br>
> > (added)<br>
> > +++ llvm/trunk/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml<br>
> > Mon<br>
> > Nov 10 17:02:03 2014<br>
> > @@ -0,0 +1,47 @@<br>
> > +# RUN: yaml2obj -format=elf %s > %t<br>
> > +# RUN: obj2yaml %t | FileCheck %s<br>
> > +<br>
> > +# CHECK: - Name: .rela.text<br>
> > +# CHECK-NEXT: Type: SHT_RELA<br>
> > +# CHECK-NEXT: Link: .symtab<br>
> > +# CHECK-NEXT: AddressAlign: 0x0000000000000008<br>
> > +# CHECK-NEXT: Info: .text<br>
> > +# CHECK-NEXT: Relocations:<br>
> > +# CHECK-NEXT: - Offset: 0x0000000000000000<br>
> > +# CHECK-NEXT: Symbol: main<br>
> > +# CHECK-NEXT: Type: R_AARCH64_ABS64<br>
> > +# CHECK-NEXT: Addend: 0<br>
> > +<br>
> > +FileHeader:<br>
> > + Class: ELFCLASS64<br>
> > + Data: ELFDATA2LSB<br>
> > + Type: ET_REL<br>
> > + Machine: EM_AARCH64<br>
> > +Sections:<br>
> > + - Type: SHT_PROGBITS<br>
> > + Name: .text<br>
> > + Flags: [ SHF_ALLOC, SHF_EXECINSTR ]<br>
> > + AddressAlign: 0x04<br>
> > + Content: 0000000000000000<br>
> > + - Type: SHT_RELA<br>
> > + Name: .rela.text<br>
> > + Link: .symtab<br>
> > + Info: .text<br>
> > + AddressAlign: 0x08<br>
> > + Relocations:<br>
> > + - Offset: 0<br>
> > + Symbol: main<br>
> > + Type: R_AARCH64_ABS64<br>
> > + Addend: 0<br>
> > +<br>
> > +Symbols:<br>
> > + Local:<br>
> > + - Name: .text<br>
> > + Type: STT_SECTION<br>
> > + Section: .text<br>
> > +<br>
> > + Global:<br>
> > + - Name: main<br>
> > + Type: STT_FUNC<br>
> > + Section: .text<br>
> > + Size: 0x08<br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > llvm-commits mailing list<br>
> > <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
> ><br>
><br>
> --<br>
> Hal Finkel<br>
> Assistant Computational Scientist<br>
> Leadership Computing Facility<br>
> Argonne National Laboratory<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br>
><br>
<br>
--<br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory<br>
</div></div></blockquote></div><br></div></div>