<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body bgcolor=white lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>So I think I’ve figured out my issue, which maybe isn’t an issue at all. So now I understand that the relocations happen as you’re writing the file (during write() in SectionChunks.h). But I think the issue is not that the section is necessarily wrong, but that both __tls_get_addr and _start are both at the same location. So objdump is simply telling me the first symbol at that address <i>(</i>__tls_get_addr) instead of the _start symbol. It seems like __tls_get_addr should indeed actually be of length 0. So that part of the code I think is actually correct.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I still need to figure out the GOT. The call_weak_fn routine is not properly accessing the Global Offset Table.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Daniel<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:windowtext'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:windowtext'> llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu] <b>On Behalf Of </b>Daniel Stewart<br><b>Sent:</b> Monday, July 28, 2014 5:43 PM<br><b>To:</b> 'Shankar Easwaran'; llvmdev@cs.uiuc.edu<br><b>Subject:</b> Re: [LLVMdev] [lld] question on ELF section formating<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Wouldn’t all the relocations already be processed by the time we get to writing a file? Since it appears YAML is correct and the actual executable is not, I thought that the relocations wouldn’t be an issue. But I can go back and check the relocations again. <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>What do you mean by “writing content overlapped”? Does this refer to a particular process that lld does? I haven’t modified the ELF writing at all (at least I don’t think I have!). I thought that OutputELFWriter.h was doing all (or at least the bulk) of the work. I have an AARch64ExecutbaleWriter.cpp, but it just creates a few got files, it doesn’t actually do any writing that I can tell.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Daniel<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:windowtext'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:windowtext'> Shankar Easwaran [<a href="mailto:shankare@codeaurora.org">mailto:shankare@codeaurora.org</a>] <br><b>Sent:</b> Monday, July 28, 2014 5:31 PM<br><b>To:</b> Daniel Stewart; <a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a><br><b>Subject:</b> Re: [LLVMdev] [lld] question on ELF section formating<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>It could be any of the following issues :-<br><br>a) When writing content overlapped ...<br>b) The way relocations are applied in X86_64 would be different from AARCH64, so could be in the place how relocations are being processed.<br><br>Thanks<br><br>Shankar Easwaran<br><br>On 7/28/2014 3:53 PM, Daniel Stewart wrote:<o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>I've been adding ELF/AArch64 support to lld based off the existing x86_64<o:p></o:p></pre><pre>code that is already there in lld. I've been able to compile and link a<o:p></o:p></pre><pre>simple "Hello World"-type program. However, I'm getting what appears to be a<o:p></o:p></pre><pre>misplacement/name change of the _start atom. When I do the link, the _start<o:p></o:p></pre><pre>section gets named __tls_get_addr. The code inside this section appears to<o:p></o:p></pre><pre>be correct, just the name is wrong. If I output in YAML, it appears to have<o:p></o:p></pre><pre>the correct name. <o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Since I know this is new code that no one has seen, I was just wondering if<o:p></o:p></pre><pre>anyone might give me a hint as to why this might happen or a good place to<o:p></o:p></pre><pre>start looking. I'm new to the linker and only have been looking into lld for<o:p></o:p></pre><pre>about a week. <o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>The output in YAML for the section in question is:<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  - name:            _start<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>    scope:           global<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>    content:         [ 1D, 00, 80, D2, 1E, 00, 80, D2, FD, 03, 00, 91, <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>                       E5, 03, 00, AA, E1, 03, 40, F9, E2, 23, 00, 91, <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>                       E6, 03, 00, 91, A0, 00, 00, 58, C3, 00, 00, 58, <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>                       E4, 00, 00, 58, 00, 00, 00, 94, 00, 00, 00, 94 ]<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>    alignment:       2^3<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>    section-name:    .text<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>    references:      <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>      - kind:            R_AARCH64_CALL26<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>        offset:          40<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>        target:          __plt___libc_start_main<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>      - kind:            R_AARCH64_CALL26<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>        offset:          44<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>        target:          __plt_abort<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>      - kind:            in-group<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>        offset:          0<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>        target:          L030<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>      - kind:            layout-after<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>        offset:          0<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>        target:          '$d.010'<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>The output during objdump of that section is:<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>00000000004006d0 <__tls_get_addr>:<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  4006d0:              d280001d             mov       x29, #0x0<o:p></o:p></pre><pre>// #0<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  4006d4:              d280001e             mov       x30, #0x0<o:p></o:p></pre><pre>// #0<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  4006d8:              910003fd              mov       x29, sp<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  4006dc:               aa0003e5             mov       x5, x0<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  4006e0:              f94003e1              ldr           x1, [sp]<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  4006e4:              910023e2             add        x2, sp, #0x8<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  4006e8:              910003e6             mov       x6, sp<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  4006ec:               580000a0             ldr           x0, 400700<o:p></o:p></pre><pre><__tls_get_addr+0x30><o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  4006f0:               580000c3              ldr           x3, 400708<o:p></o:p></pre><pre><__tls_get_addr+0x38><o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  4006f4:               580000e4             ldr           x4, 400710<o:p></o:p></pre><pre><__tls_get_addr+0x40><o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  4006f8:               97ffffe6                bl            400690<o:p></o:p></pre><pre><__libc_start_main@plt><o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  4006fc:                97ffffe9                bl            4006a0<o:p></o:p></pre><pre><abort@plt><o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  400700:               004008a0             .inst       0x004008a0 ;<o:p></o:p></pre><pre>undefined<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  400704:               00000000             .inst       0x00000000 ;<o:p></o:p></pre><pre>undefined<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  400708:               00400934             .inst       0x00400934 ;<o:p></o:p></pre><pre>undefined<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  40070c:               00000000             .inst       0x00000000 ;<o:p></o:p></pre><pre>undefined<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  400710:               004009ac              .inst       0x004009ac ;<o:p></o:p></pre><pre>undefined<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>  400714:               00000000             .inst       0x00000000 ;<o:p></o:p></pre><pre>undefined<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Daniel<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>--<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by<o:p></o:p></pre><pre>The Linux Foundation<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre><p class=MsoNormal style='margin-bottom:12.0pt'><br><br><o:p></o:p></p><pre>_______________________________________________<o:p></o:p></pre><pre>LLVM Developers mailing list<o:p></o:p></pre><pre><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a><o:p></o:p></pre><pre><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><o:p></o:p></pre></blockquote><p class=MsoNormal style='margin-bottom:12.0pt'><br><br><o:p></o:p></p><pre>-- <o:p></o:p></pre><pre>Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by the Linux Foundation<o:p></o:p></pre></div></body></html>