[llvm-bugs] [Bug 47009] New: -z rel breaks aarch64 TLSDESC relocs

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 5 15:58:19 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47009

            Bug ID: 47009
           Summary: -z rel breaks aarch64 TLSDESC relocs
           Product: lld
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: roland at hack.frob.com
                CC: llvm-bugs at lists.llvm.org, maskray at google.com,
                    phosek at chromium.org, smithp352 at googlemail.com

Take this assembly file:

```
        .text                                                                   
        .file   "a.c"                                                           
        .globl  foo                             // -- Begin function foo        
        .p2align        2                                                       
        .type   foo, at 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, at object                                                       
        .section        .tbss,"awT", at nobits                                     
        .globl  x                                                               
        .p2align        2                                                       
x:                                                                              
.Lx$local:                                                                      
        .word   0                               // 0x0                          
        .size   x, 4                                                            

        .hidden y                               // @y                           
        .type   y, at 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).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200805/56be482d/attachment-0001.html>


More information about the llvm-bugs mailing list