Home | History | Annotate | Download | only in Mips
      1 // RUN: llvm-mc -triple mips-unknown-linux < %s -show-encoding \
      2 // RUN:     | FileCheck -check-prefix=ENCBE -check-prefix=FIXUP %s
      3 // RUN: llvm-mc -triple mipsel-unknown-linux < %s -show-encoding \
      4 // RUN:     | FileCheck -check-prefix=ENCLE -check-prefix=FIXUP %s
      5 // RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux < %s \
      6 // RUN:     | llvm-readobj -r | FileCheck -check-prefix=RELOC %s
      7 
      8 // Test that we produce the correct relocation.
      9 // FIXME: move more relocation only tests here.
     10 
     11 // Check prefixes:
     12 // RELOC - Check the relocation in the object.
     13 // FIXUP - Check the fixup on the instruction.
     14 // ENCBE - Check the big-endian encoding on the instruction.
     15 // ENCLE - Check the little-endian encoding on the instruction.
     16 // ????? - Placeholder. Relocation is defined but the way of generating it is
     17 //         unknown.
     18 // FIXME - Placeholder. Generation method is known but doesn't work.
     19 
     20         .short foo                         // RELOC: R_MIPS_16 foo
     21 
     22         .long foo                          // RELOC: R_MIPS_32 foo
     23 
     24                                            // ?????: R_MIPS_REL32 foo
     25 
     26         jal foo                            // RELOC: R_MIPS_26 foo
     27                                            // ENCBE: jal foo # encoding: [0b000011AA,A,A,A]
     28                                            // ENCLE: jal foo # encoding: [A,A,A,0b000011AA]
     29                                            // FIXUP: # fixup A - offset: 0, value: foo, kind: fixup_Mips_26
     30 
     31         addiu $2, $3, %hi(foo)             // RELOC: R_MIPS_HI16 foo
     32                                            // ENCBE: addiu $2, $3, %hi(foo) # encoding: [0x24,0x62,A,A]
     33                                            // ENCLE: addiu $2, $3, %hi(foo) # encoding: [A,A,0x62,0x24]
     34                                            // FIXUP: # fixup A - offset: 0, value: foo@ABS_HI, kind: fixup_Mips_HI16
     35 
     36         addiu $2, $3, %lo(foo)             // RELOC: R_MIPS_LO16 foo
     37                                            // ENCBE: addiu $2, $3, %lo(foo) # encoding: [0x24,0x62,A,A]
     38                                            // ENCLE: addiu $2, $3, %lo(foo) # encoding: [A,A,0x62,0x24]
     39                                            // FIXUP: # fixup A - offset: 0, value: foo@ABS_LO, kind: fixup_Mips_LO16
     40 
     41         addiu $2, $3, %gp_rel(foo)         // RELOC: R_MIPS_GPREL16 foo
     42                                            // ENCBE: addiu $2, $3, %gp_rel(foo) # encoding: [0x24,0x62,A,A]
     43                                            // ENCLE: addiu $2, $3, %gp_rel(foo) # encoding: [A,A,0x62,0x24]
     44                                            // FIXUP: # fixup A - offset: 0, value: foo@GPREL, kind: fixup_Mips_GPREL
     45 
     46                                            // ?????: R_MIPS_LITERAL foo
     47 
     48         addiu $2, $3, %got(foo)            // RELOC: R_MIPS_GOT16 foo
     49                                            // ENCBE: addiu $2, $3, %got(foo) # encoding: [0x24,0x62,A,A]
     50                                            // ENCLE: addiu $2, $3, %got(foo) # encoding: [A,A,0x62,0x24]
     51                                            // FIXUP: # fixup A - offset: 0, value: foo@GOT, kind: fixup_Mips_GOT_Local
     52 
     53         .short foo-.                       // RELOC: R_MIPS_PC16 foo
     54 
     55         addiu $2, $3, %call16(foo)         // RELOC: R_MIPS_CALL16 foo
     56                                            // ENCBE: addiu $2, $3, %call16(foo) # encoding: [0x24,0x62,A,A]
     57                                            // ENCLE: addiu $2, $3, %call16(foo) # encoding: [A,A,0x62,0x24]
     58                                            // FIXUP: # fixup A - offset: 0, value: foo@GOT_CALL, kind: fixup_Mips_CALL16
     59 
     60         .quad foo                          // RELOC: R_MIPS_64 foo
     61 
     62                                            // ?????: R_MIPS_GPREL32 foo
     63                                            // ?????: R_MIPS_UNUSED1 foo
     64                                            // ?????: R_MIPS_UNUSED2 foo
     65                                            // ?????: R_MIPS_UNUSED3 foo
     66                                            // ?????: R_MIPS_SHIFT5 foo
     67                                            // ?????: R_MIPS_SHIFT6 foo
     68 
     69         addiu $2, $3, %got_disp(foo)       // RELOC: R_MIPS_GOT_DISP foo
     70                                            // ENCBE: addiu $2, $3, %got_disp(foo) # encoding: [0x24,0x62,A,A]
     71                                            // ENCLE: addiu $2, $3, %got_disp(foo) # encoding: [A,A,0x62,0x24]
     72                                            // FIXUP: # fixup A - offset: 0, value: foo@GOT_DISP, kind: fixup_Mips_GOT_DISP
     73 
     74         addiu $2, $3, %got_page(foo)       // RELOC: R_MIPS_GOT_PAGE foo
     75                                            // ENCBE: addiu $2, $3, %got_page(foo) # encoding: [0x24,0x62,A,A]
     76                                            // ENCLE: addiu $2, $3, %got_page(foo) # encoding: [A,A,0x62,0x24]
     77                                            // FIXUP: # fixup A - offset: 0, value: foo@GOT_PAGE, kind: fixup_Mips_GOT_PAGE
     78 
     79         addiu $2, $3, %got_ofst(foo)       // RELOC: R_MIPS_GOT_OFST foo
     80                                            // ENCBE: addiu $2, $3, %got_ofst(foo) # encoding: [0x24,0x62,A,A]
     81                                            // ENCLE: addiu $2, $3, %got_ofst(foo) # encoding: [A,A,0x62,0x24]
     82                                            // FIXUP: # fixup A - offset: 0, value: foo@GOT_OFST, kind: fixup_Mips_GOT_OFST
     83 
     84         addiu $2, $3, %got_hi(foo)         // RELOC: R_MIPS_GOT_HI16 foo
     85                                            // ENCBE: addiu $2, $3, %got_hi(foo) # encoding: [0x24,0x62,A,A]
     86                                            // ENCLE: addiu $2, $3, %got_hi(foo) # encoding: [A,A,0x62,0x24]
     87                                            // FIXUP: # fixup A - offset: 0, value: foo@GOT_HI16, kind: fixup_Mips_GOT_HI16
     88 
     89         addiu $2, $3, %got_lo(foo)         // RELOC: R_MIPS_GOT_LO16 foo
     90                                            // ENCBE: addiu $2, $3, %got_lo(foo) # encoding: [0x24,0x62,A,A]
     91                                            // ENCLE: addiu $2, $3, %got_lo(foo) # encoding: [A,A,0x62,0x24]
     92                                            // FIXUP: # fixup A - offset: 0, value: foo@GOT_LO16, kind: fixup_Mips_GOT_LO16
     93 
     94 //      addiu $2, $3, %neg(foo)            // FIXME: R_MIPS_SUB foo
     95                                            // ?????: R_MIPS_INSERT_A
     96                                            // ?????: R_MIPS_INSERT_B
     97                                            // ?????: R_MIPS_DELETE
     98 
     99         .set mips64
    100         daddiu $2, $3, %higher(foo)        // RELOC: R_MIPS_HIGHER foo
    101                                            // ENCBE: daddiu $2, $3, %higher(foo) # encoding: [0x64,0x62,A,A]
    102                                            // ENCLE: daddiu $2, $3, %higher(foo) # encoding: [A,A,0x62,0x64]
    103                                            // FIXUP: # fixup A - offset: 0, value: foo@HIGHER, kind: fixup_Mips_HIGHER
    104 
    105         daddiu $2, $3, %highest(foo)       // RELOC: R_MIPS_HIGHEST foo
    106                                            // ENCBE: daddiu $2, $3, %highest(foo) # encoding: [0x64,0x62,A,A]
    107                                            // ENCLE: daddiu $2, $3, %highest(foo) # encoding: [A,A,0x62,0x64]
    108                                            // FIXUP: # fixup A - offset: 0, value: foo@HIGHEST, kind: fixup_Mips_HIGHEST
    109 
    110         .set mips0
    111         addiu $2, $3, %call_hi(foo)        // RELOC: R_MIPS_CALL_HI16 foo
    112                                            // ENCBE: addiu $2, $3, %call_hi(foo) # encoding: [0x24,0x62,A,A]
    113                                            // ENCLE: addiu $2, $3, %call_hi(foo) # encoding: [A,A,0x62,0x24]
    114                                            // FIXUP: # fixup A - offset: 0, value: foo@CALL_HI16, kind: fixup_Mips_CALL_HI16
    115 
    116         addiu $2, $3, %call_lo(foo)        // RELOC: R_MIPS_CALL_LO16 foo
    117                                            // ENCBE: addiu $2, $3, %call_lo(foo) # encoding: [0x24,0x62,A,A]
    118                                            // ENCLE: addiu $2, $3, %call_lo(foo) # encoding: [A,A,0x62,0x24]
    119                                            // FIXUP: # fixup A - offset: 0, value: foo@CALL_LO16, kind: fixup_Mips_CALL_LO16
    120 
    121                                            // ?????: R_MIPS_SCN_DISP foo
    122                                            // ?????: R_MIPS_REL16 foo
    123                                            // ?????: R_MIPS_ADD_IMMEDIATE foo
    124                                            // ?????: R_MIPS_PJUMP foo
    125                                            // ?????: R_MIPS_RELGOT foo
    126 //      jalr $25                           // ?????: R_MIPS_JALR foo
    127 
    128                                            // ?????: R_MIPS_TLS_DTPMOD32 foo
    129 //      .dtprelword foo                    // FIXME: R_MIPS_TLS_DTPREL32 foo
    130                                            // ?????: R_MIPS_TLS_DTPMOD64 foo
    131 //      .dtpreldword foo                   // FIXME: R_MIPS_TLS_DTPREL64 foo
    132         addiu $2, $3, %tlsgd(foo)          // RELOC: R_MIPS_TLS_GD foo
    133                                            // ENCBE: addiu $2, $3, %tlsgd(foo) # encoding: [0x24,0x62,A,A]
    134                                            // ENCLE: addiu $2, $3, %tlsgd(foo) # encoding: [A,A,0x62,0x24]
    135                                            // FIXUP: # fixup A - offset: 0, value: foo@TLSGD, kind: fixup_Mips_TLSGD
    136 
    137         addiu $2, $3, %tlsldm(foo)         // RELOC: R_MIPS_TLS_LDM foo
    138                                            // ENCBE: addiu $2, $3, %tlsldm(foo) # encoding: [0x24,0x62,A,A]
    139                                            // ENCLE: addiu $2, $3, %tlsldm(foo) # encoding: [A,A,0x62,0x24]
    140                                            // FIXUP: # fixup A - offset: 0, value: foo@TLSLDM, kind: fixup_Mips_TLSLDM
    141 
    142         addiu $2, $3, %dtprel_hi(foo)      // RELOC: R_MIPS_TLS_DTPREL_HI16 foo
    143                                            // ENCBE: addiu $2, $3, %dtprel_hi(foo) # encoding: [0x24,0x62,A,A]
    144                                            // ENCLE: addiu $2, $3, %dtprel_hi(foo) # encoding: [A,A,0x62,0x24]
    145                                            // FIXUP: # fixup A - offset: 0, value: foo@DTPREL_HI, kind: fixup_Mips_DTPREL_HI
    146 
    147         addiu $2, $3, %dtprel_lo(foo)      // RELOC: R_MIPS_TLS_DTPREL_LO16 foo
    148                                            // ENCBE: addiu $2, $3, %dtprel_lo(foo) # encoding: [0x24,0x62,A,A]
    149                                            // ENCLE: addiu $2, $3, %dtprel_lo(foo) # encoding: [A,A,0x62,0x24]
    150                                            // FIXUP: # fixup A - offset: 0, value: foo@DTPREL_LO, kind: fixup_Mips_DTPREL_LO
    151 
    152         addiu $2, $3, %gottprel(foo)       // RELOC: R_MIPS_TLS_GOTTPREL foo
    153                                            // ENCBE: addiu $2, $3, %gottprel(foo) # encoding: [0x24,0x62,A,A]
    154                                            // ENCLE: addiu $2, $3, %gottprel(foo) # encoding: [A,A,0x62,0x24]
    155                                            // FIXUP: # fixup A - offset: 0, value: foo@GOTTPREL, kind: fixup_Mips_GOTTPREL
    156 
    157 //      .tprelword foo                     // FIXME: R_MIPS_TLS_TPREL32 foo
    158 //      .tpreldword foo                    // FIXME: R_MIPS_TLS_TPREL64 foo
    159         addiu $2, $3, %tprel_hi(foo)       // RELOC: R_MIPS_TLS_TPREL_HI16 foo
    160                                            // ENCBE: addiu $2, $3, %tprel_hi(foo) # encoding: [0x24,0x62,A,A]
    161                                            // ENCLE: addiu $2, $3, %tprel_hi(foo) # encoding: [A,A,0x62,0x24]
    162                                            // FIXUP: # fixup A - offset: 0, value: foo@TPREL_HI, kind: fixup_Mips_TPREL_HI
    163 
    164         addiu $2, $3, %tprel_lo(foo)       // RELOC: R_MIPS_TLS_TPREL_LO16 foo
    165                                            // ENCBE: addiu $2, $3, %tprel_lo(foo) # encoding: [0x24,0x62,A,A]
    166                                            // ENCLE: addiu $2, $3, %tprel_lo(foo) # encoding: [A,A,0x62,0x24]
    167                                            // FIXUP: # fixup A - offset: 0, value: foo@TPREL_LO, kind: fixup_Mips_TPREL_LO
    168 
    169                                            // ?????: R_MIPS_GLOB_DAT foo
    170         .set mips32r6
    171         beqzc $2, foo                      // RELOC: R_MIPS_PC21_S2 foo
    172                                            // ENCBE: beqzc $2, foo # encoding: [0xd8,0b010AAAAA,A,A]
    173                                            // ENCLE: beqzc $2, foo # encoding: [A,A,0b010AAAAA,0xd8]
    174                                            // FIXUP: # fixup A - offset: 0, value: foo-4, kind: fixup_MIPS_PC21_S2
    175 
    176         bc foo                             // RELOC: R_MIPS_PC26_S2 foo
    177                                            // ENCBE: bc foo # encoding: [0b110010AA,A,A,A]
    178                                            // ENCLE: bc foo # encoding: [A,A,A,0b110010AA]
    179                                            // FIXUP: # fixup A - offset: 0, value: foo-4, kind: fixup_MIPS_PC26_S2
    180 
    181         .set mips64r6
    182         ldpc $2, foo                       // RELOC: R_MIPS_PC18_S3 foo
    183                                            // ENCBE: ldpc $2, foo # encoding: [0xec,0b010110AA,A,A]
    184                                            // ENCLE: ldpc $2, foo # encoding: [A,A,0b010110AA,0xec]
    185                                            // FIXUP: # fixup A - offset: 0, value: foo, kind: fixup_Mips_PC18_S3
    186 
    187         .set mips32r6
    188         lwpc $2, foo                       // RELOC: R_MIPS_PC19_S2 foo
    189                                            // ENCBE: lwpc $2, foo # encoding: [0xec,0b01001AAA,A,A]
    190                                            // ENCLE: lwpc $2, foo # encoding: [A,A,0b01001AAA,0xec]
    191                                            // FIXUP: # fixup A - offset: 0, value: foo, kind: fixup_MIPS_PC19_S2
    192 
    193         addiu $2, $3, %pcrel_hi(foo)       // RELOC: R_MIPS_PCHI16 foo
    194                                            // ENCBE: addiu $2, $3, %pcrel_hi(foo) # encoding: [0x24,0x62,A,A]
    195                                            // ENCLE: addiu $2, $3, %pcrel_hi(foo) # encoding: [A,A,0x62,0x24]
    196                                            // FIXUP: # fixup A - offset: 0, value: foo@PCREL_HI16, kind: fixup_MIPS_PCHI16
    197 
    198         addiu $2, $3, %pcrel_lo(foo)       // RELOC: R_MIPS_PCLO16 foo
    199                                            // ENCBE: addiu $2, $3, %pcrel_lo(foo) # encoding: [0x24,0x62,A,A]
    200                                            // ENCLE: addiu $2, $3, %pcrel_lo(foo) # encoding: [A,A,0x62,0x24]
    201                                            // FIXUP: # fixup A - offset: 0, value: foo@PCREL_LO16, kind: fixup_MIPS_PCLO16
    202 
    203         .set mips0
    204                                            // FIXME: R_MIPS16_*
    205                                            // ?????: R_MIPS_COPY foo
    206                                            // ?????: R_MIPS_JUMP_SLOT foo
    207                                            // FIXME: R_MICROMIPS_*
    208         .long foo-.                        // RELOC: R_MIPS_PC32 foo
    209 //      .ehword foo                        // FIXME: R_MIPS_EH foo
    210