<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - -z rel breaks aarch64 TLSDESC relocs"
   href="https://bugs.llvm.org/show_bug.cgi?id=47009">47009</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-z rel breaks aarch64 TLSDESC relocs
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>ELF
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>roland@hack.frob.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, maskray@google.com, phosek@chromium.org, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Take this assembly file:

```
        .text                                                                   
        .file   "a.c"                                                           
        .globl  foo                             // -- Begin function foo        
        .p2align        2                                                       
        .type   foo,@function                                                   
foo:                                    // @foo                                 
        .cfi_startproc                                                          
// %bb.0:                                                                       
        str     x30, [x18], #8                                                  
        stp     x29, x30, [sp, #-16]!           // 16-byte Folded Spill         
        mov     x29, sp                                                         
        .cfi_def_cfa w29, 16                                                    
        .cfi_offset w30, -8                                                     
        .cfi_offset w29, -16                                                    
        adrp    x0, :tlsdesc:x                                                  
        ldr     x1, [x0, :tlsdesc_lo12:x]                                       
        add     x0, x0, :tlsdesc_lo12:x                                         
        .tlsdesccall x                                                          
        blr     x1                                                              
        mrs     x8, TPIDR_EL0                                                   
        ldr     w9, [x8, x0]                                                    
        adrp    x0, :tlsdesc:y                                                  
        ldr     x1, [x0, :tlsdesc_lo12:y]                                       
        add     x0, x0, :tlsdesc_lo12:y                                         
        .tlsdesccall y                                                          
        blr     x1                                                              
        ldr     w8, [x8, x0]                                                    
        add     w0, w8, w9                                                      
        ldp     x29, x30, [sp], #16             // 16-byte Folded Reload        
        ldr     x30, [x18, #-8]!                                                
        ret                                                                     
.Lfunc_end0:                                                                    
        .size   foo, .Lfunc_end0-foo                                            
        .cfi_endproc                                                            
                                        // -- End function                      
        .hidden x                               // @x                           
        .type   x,@object                                                       
        .section        .tbss,"awT",@nobits                                     
        .globl  x                                                               
        .p2align        2                                                       
x:                                                                              
.Lx$local:                                                                      
        .word   0                               // 0x0                          
        .size   x, 4                                                            

        .hidden y                               // @y                           
        .type   y,@object                                                       
        .globl  y                                                               
        .p2align        2                                                       
y:                                                                              
.Ly$local:                                                                      
        .word   0                               // 0x0                          
        .size   y, 4                                                            
 ```

Compile it with `clang --target=aarch64-fuchsia -c a.s` and then:

```
$ hack/bin/ld.lld -z max-page-size=4096 -z now -z rodynamic -z
separate-loadable-segments --pack-dyn-relocs=relr -z rela --build-id
--hash-style=gnu --eh-frame-hdr -shared -o a.so.rela a.o                        
$ hack/bin/ld.lld -z max-page-size=4096 -z now -z rodynamic -z
separate-loadable-segments --pack-dyn-relocs=relr -z rel --build-id
--hash-style=gnu --eh-frame-hdr -shared -o a.so.rel a.o                         
$ readelf -Wr -x.got a.so.rel*                                       

File: a.so.rel                                                                  

Relocation section '.rel.dyn' at offset 0x390 contains 2 entries:               
    Offset             Info             Type               Symbol's Value 
Symbol's Name                                                                   
0000000000002000  0000000000000407 R_AARCH64_TLSDESC                            
0000000000002010  0000000000000407 R_AARCH64_TLSDESC                            

Hex dump of section '.got':                                                     
  0x00002000 00000000 00000000 00000000 00000000 ................               
  0x00002010 00000000 00000000 00000000 00000000 ................               


File: a.so.rela                                                                 

Relocation section '.rela.dyn' at offset 0x390 contains 2 entries:              
    Offset             Info             Type               Symbol's Value 
Symbol's Name + Addend                                                          
0000000000002000  0000000000000407 R_AARCH64_TLSDESC                         0  
0000000000002010  0000000000000407 R_AARCH64_TLSDESC                         4  

Hex dump of section '.got':                                                     
  0x00002000 00000000 00000000 00000000 00000000 ................               
  0x00002010 00000000 00000000 00000000 00000000 ................               

```

In the `-z rela` case, the addends survive correctly.  In the `-z rel` case,
nonzero addend (4) should be stored in the generated GOT slot at 0x2008 (i.e.
the second word of the two-word TLSDESC GOT slot).</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>