Home | History | Annotate | Download | only in ELF
      1 // RUN: llvm-mc -filetype=obj -triple i386-pc-linux-gnu %s -o - | elf-dump | FileCheck  %s
      2 
      3 // Test that we produce the correct relocation types and that the relocations
      4 // correctly point to the section or the symbol.
      5 
      6 // CHECK:      # Relocation 0
      7 // CHECK-NEXT: (('r_offset', 0x00000002)
      8 // CHECK-NEXT:  ('r_sym', 0x000001)
      9 // CHECK-NEXT:  ('r_type', 0x09)
     10 // CHECK-NEXT: ),
     11 // CHECK-NEXT:  # Relocation 1
     12 // CHECK-NEXT: (('r_offset',
     13 // CHECK-NEXT:  ('r_sym',
     14 // CHECK-NEXT:  ('r_type', 0x04)
     15 // CHECK-NEXT: ),
     16 // CHECK-NEXT:  # Relocation 2
     17 // CHECK-NEXT: (('r_offset',
     18 // CHECK-NEXT:  ('r_sym',
     19 // CHECK-NEXT:  ('r_type', 0x0a)
     20 // CHECK-NEXT: ),
     21 
     22 // Relocation 3 (bar3@GOTOFF) is done with symbol 7 (bss)
     23 // CHECK-NEXT:  # Relocation 3
     24 // CHECK-NEXT: (('r_offset',
     25 // CHECK-NEXT:  ('r_sym', 0x000007
     26 // CHECK-NEXT:  ('r_type',
     27 // CHECK-NEXT: ),
     28 
     29 // Relocation 4 (bar2@GOT) is of type R_386_GOT32
     30 // CHECK-NEXT:  # Relocation 4
     31 // CHECK-NEXT: (('r_offset',
     32 // CHECK-NEXT:  ('r_sym',
     33 // CHECK-NEXT:  ('r_type', 0x03
     34 // CHECK-NEXT: ),
     35 
     36 // Relocation 5 (foo@TLSGD) is of type R_386_TLS_GD
     37 // CHECK-NEXT: # Relocation 5
     38 // CHECK-NEXT: (('r_offset', 0x00000020)
     39 // CHECK-NEXT:  ('r_sym', 0x00000d)
     40 // CHECK-NEXT:  ('r_type', 0x12)
     41 // CHECK-NEXT: ),
     42 
     43 // Relocation 6 ($foo@TPOFF) is of type R_386_TLS_LE_32
     44 // CHECK-NEXT: # Relocation 6
     45 // CHECK-NEXT: (('r_offset', 0x00000025)
     46 // CHECK-NEXT:  ('r_sym', 0x00000d)
     47 // CHECK-NEXT:  ('r_type', 0x22)
     48 // CHECK-NEXT: ),
     49 
     50 // Relocation 7 (foo@INDNTPOFF) is of type R_386_TLS_IE
     51 // CHECK-NEXT: # Relocation 7
     52 // CHECK-NEXT: (('r_offset', 0x0000002b)
     53 // CHECK-NEXT:  ('r_sym', 0x00000d)
     54 // CHECK-NEXT:  ('r_type', 0x0f)
     55 // CHECK-NEXT: ),
     56 
     57 // Relocation 8 (foo@NTPOFF) is of type R_386_TLS_LE
     58 // CHECK-NEXT: # Relocation 8
     59 // CHECK-NEXT: (('r_offset', 0x00000031)
     60 // CHECK-NEXT:  ('r_sym', 0x00000d)
     61 // CHECK-NEXT:  ('r_type', 0x11)
     62 // CHECK-NEXT: ),
     63 
     64 // Relocation 9 (foo@GOTNTPOFF) is of type R_386_TLS_GOTIE
     65 // CHECK-NEXT: # Relocation 9
     66 // CHECK-NEXT: (('r_offset', 0x00000037)
     67 // CHECK-NEXT:  ('r_sym', 0x00000d)
     68 // CHECK-NEXT:  ('r_type', 0x10)
     69 // CHECK-NEXT: ),
     70 
     71 // Relocation 10 (foo@TLSLDM) is of type R_386_TLS_LDM
     72 // CHECK-NEXT: # Relocation 10
     73 // CHECK-NEXT: (('r_offset', 0x0000003d)
     74 // CHECK-NEXT:  ('r_sym', 0x00000d)
     75 // CHECK-NEXT:  ('r_type', 0x13)
     76 // CHECK-NEXT: ),
     77 
     78 // Relocation 11 (foo@DTPOFF) is of type R_386_TLS_LDO_32
     79 // CHECK-NEXT: # Relocation 11
     80 // CHECK-NEXT: (('r_offset', 0x00000043)
     81 // CHECK-NEXT:  ('r_sym', 0x00000d)
     82 // CHECK-NEXT:  ('r_type', 0x20)
     83 // CHECK-NEXT: ),
     84 // Relocation 12 (calll 4096) is of type R_386_PC32
     85 // CHECK-NEXT: # Relocation 12
     86 // CHECK-NEXT: (('r_offset', 0x00000048)
     87 // CHECK-NEXT:  ('r_sym', 0x000000)
     88 // CHECK-NEXT:  ('r_type', 0x02)
     89 // CHECK-NEXT: ),
     90 // Relocation 13 (zed@GOT) is of type R_386_GOT32 and uses the symbol
     91 // CHECK-NEXT: # Relocation 13
     92 // CHECK-NEXT: (('r_offset', 0x0000004e)
     93 // CHECK-NEXT:  ('r_sym', 0x000004)
     94 // CHECK-NEXT:  ('r_type', 0x03)
     95 // CHECK-NEXT: ),
     96 // Relocation 14 (zed@GOTOFF) is of type R_386_GOTOFF and uses the symbol
     97 // CHECK-NEXT: # Relocation 14
     98 // CHECK-NEXT: (('r_offset', 0x00000054)
     99 // CHECK-NEXT:  ('r_sym', 0x000004)
    100 // CHECK-NEXT:  ('r_type', 0x09)
    101 // CHECK-NEXT: ),
    102 // Relocation 15 (zed@INDNTPOFF) is of type R_386_TLS_IE and uses the symbol
    103 // CHECK-NEXT: # Relocation 15
    104 // CHECK-NEXT: (('r_offset', 0x0000005a)
    105 // CHECK-NEXT:  ('r_sym', 0x000004)
    106 // CHECK-NEXT:  ('r_type', 0x0f)
    107 // CHECK-NEXT: ),
    108 // Relocation 16 (zed@NTPOFF) is of type R_386_TLS_LE and uses the symbol
    109 // CHECK-NEXT: # Relocation 16
    110 // CHECK-NEXT: (('r_offset', 0x00000060)
    111 // CHECK-NEXT:  ('r_sym', 0x000004)
    112 // CHECK-NEXT:  ('r_type', 0x11)
    113 // CHECK-NEXT: ),
    114 // Relocation 17 (zed@GOTNTPOFF) is of type R_386_TLS_GOTIE and uses the symbol
    115 // CHECK-NEXT: # Relocation 17
    116 // CHECK-NEXT: (('r_offset', 0x00000066)
    117 // CHECK-NEXT:  ('r_sym', 0x000004)
    118 // CHECK-NEXT:  ('r_type', 0x10)
    119 // CHECK-NEXT: ),
    120 // Relocation 18 (zed@PLT) is of type R_386_PLT32 and uses the symbol
    121 // CHECK-NEXT: # Relocation 18
    122 // CHECK-NEXT: (('r_offset', 0x0000006b)
    123 // CHECK-NEXT:  ('r_sym', 0x000004)
    124 // CHECK-NEXT:  ('r_type', 0x04)
    125 // CHECK-NEXT: ),
    126 // Relocation 19 (zed@TLSGD) is of type R_386_TLS_GD and uses the symbol
    127 // CHECK-NEXT: # Relocation 19
    128 // CHECK-NEXT: (('r_offset', 0x00000071)
    129 // CHECK-NEXT:  ('r_sym', 0x000004)
    130 // CHECK-NEXT:  ('r_type', 0x12)
    131 // CHECK-NEXT: ),
    132 // Relocation 20 (zed@TLSLDM) is of type R_386_TLS_LDM and uses the symbol
    133 // CHECK-NEXT: # Relocation 20
    134 // CHECK-NEXT: (('r_offset', 0x00000077)
    135 // CHECK-NEXT:  ('r_sym', 0x000004)
    136 // CHECK-NEXT:  ('r_type', 0x13)
    137 // CHECK-NEXT: ),
    138 // Relocation 21 (zed@TPOFF) is of type R_386_TLS_LE_32 and uses the symbol
    139 // CHECK-NEXT:# Relocation 21
    140 // CHECK-NEXT: (('r_offset', 0x0000007d)
    141 // CHECK-NEXT:  ('r_sym', 0x000004)
    142 // CHECK-NEXT:  ('r_type', 0x22)
    143 // CHECK-NEXT: ),
    144 // Relocation 22 (zed@DTPOFF) is of type R_386_TLS_LDO_32 and uses the symbol
    145 // CHECK-NEXT: Relocation 22
    146 // CHECK-NEXT: (('r_offset', 0x00000083)
    147 // CHECK-NEXT:  ('r_sym', 0x000004)
    148 // CHECK-NEXT:  ('r_type', 0x20)
    149 // CHECK-NEXT: ),
    150 // Relocation 23 ($bar) is of type R_386_32 and uses the section
    151 // CHECK-NEXT: Relocation 23
    152 // CHECK-NEXT: (('r_offset',
    153 // CHECK-NEXT:  ('r_sym',
    154 // CHECK-NEXT:  ('r_type', 0x01)
    155 // CHECK-NEXT: ),
    156 // Relocation 24 (foo@GOTTPOFF(%edx)) is of type R_386_TLS_IE_32 and uses the
    157 // symbol
    158 // CHECK-NEXT: Relocation 24
    159 // CHECK-NEXT: (('r_offset', 0x0000008e)
    160 // CHECK-NEXT:  ('r_sym', 0x00000d)
    161 // CHECK-NEXT:  ('r_type', 0x21)
    162 // CHECK-NEXT: ),
    163 
    164 // Section 4 is bss
    165 // CHECK:      # Section 4
    166 // CHECK-NEXT: (('sh_name', 0x0000000b) # '.bss'
    167 
    168 // CHECK:      # Symbol 1
    169 // CHECK-NEXT: (('st_name', 0x00000005) # '.Lfoo'
    170 
    171 // Symbol 4 is zed
    172 // CHECK:      # Symbol 4
    173 // CHECK-NEXT: (('st_name', 0x00000035) # 'zed'
    174 // CHECK-NEXT:  ('st_value', 0x00000000)
    175 // CHECK-NEXT:  ('st_size', 0x00000000)
    176 // CHECK-NEXT:  ('st_bind', 0x0)
    177 // CHECK-NEXT:  ('st_type', 0x6)
    178 // CHECK-NEXT:  ('st_other', 0x00)
    179 // CHECK-NEXT:  ('st_shndx', 0x0005)
    180 
    181 // Symbol 7 is section 4
    182 // CHECK:      # Symbol 7
    183 // CHECK-NEXT: (('st_name', 0x00000000) # ''
    184 // CHECK-NEXT:  ('st_value', 0x00000000)
    185 // CHECK-NEXT:  ('st_size', 0x00000000)
    186 // CHECK-NEXT:  ('st_bind', 0x0)
    187 // CHECK-NEXT:  ('st_type', 0x3)
    188 // CHECK-NEXT:  ('st_other', 0x00)
    189 // CHECK-NEXT:  ('st_shndx', 0x0004)
    190 
    191 
    192         .text
    193 bar:
    194 	leal	.Lfoo@GOTOFF(%ebx), %eax
    195 
    196         .global bar2
    197 bar2:
    198 	calll	bar2@PLT
    199 	addl	$_GLOBAL_OFFSET_TABLE_, %ebx
    200 	movb	bar3@GOTOFF(%ebx), %al
    201 
    202 	.type	bar3,@object
    203 	.local	bar3
    204 	.comm	bar3,1,1
    205 
    206         movl	bar2j@GOT(%eax), %eax
    207 
    208         leal foo@TLSGD(, %ebx,1), %eax
    209         movl $foo@TPOFF, %edx
    210         movl foo@INDNTPOFF, %ecx
    211         addl foo@NTPOFF(%eax), %eax
    212         addl foo@GOTNTPOFF(%ebx), %ecx
    213         leal foo@TLSLDM(%ebx), %eax
    214         leal foo@DTPOFF(%eax), %edx
    215         calll 4096
    216         movl zed@GOT(%eax), %eax
    217         movl zed@GOTOFF(%eax), %eax
    218         movl zed@INDNTPOFF(%eax), %eax
    219         movl zed@NTPOFF(%eax), %eax
    220         movl zed@GOTNTPOFF(%eax), %eax
    221         call zed@PLT
    222         movl zed@TLSGD(%eax), %eax
    223         movl zed@TLSLDM(%eax), %eax
    224         movl zed@TPOFF(%eax), %eax
    225         movl zed@DTPOFF(%eax), %eax
    226         pushl $bar
    227         addl foo@GOTTPOFF(%edx), %eax
    228 
    229         .section        zedsec,"awT",@progbits
    230 zed:
    231         .long 0
    232 
    233         .section	.rodata.str1.16,"aMS",@progbits,1
    234 .Lfoo:
    235 	.asciz	 "bool llvm::llvm_start_multithreaded()"
    236