10c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# RUN: llvm-mc -filetype=obj -arch mipsel %s | llvm-readobj -r | FileCheck %s 20c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 30c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# Test the order of records in the relocation table. 40c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# *HI16 and local *GOT16 relocations should be immediately followed by the 50c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# corresponding *LO16 relocation against the same symbol. 60c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# 70c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# We try to implement the same semantics as gas, ie. to order the relocation 80c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# table the same way as gas. 90c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# 100c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# gnu as command line: 110c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# mips-linux-gnu-as -EL sort-relocation-table.s -o sort-relocation-table.o 120c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# 130c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# TODO: Add mips16 and micromips tests. 140c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# Note: offsets are part of expected output, so it's simpler to add new test 150c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# cases at the bottom of the file. 160c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 170c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK: Relocations [ 180c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: { 190c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 200c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# Put HI before LO. 210c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(sym1) 220c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%hi(sym1) 230c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 240c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x4 R_MIPS_HI16 sym1 250c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x0 R_MIPS_LO16 sym1 260c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 270c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# When searching for a matching LO, ignore LOs against a different symbol. 280c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(sym2) 290c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%hi(sym2) 300c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(sym2_d) 310c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 320c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0xC R_MIPS_HI16 sym2 330c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x8 R_MIPS_LO16 sym2 340c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x10 R_MIPS_LO16 sym2_d 350c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 360c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# Match HI with 2nd LO because it has higher offset (than the 1st LO). 370c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(sym3) 380c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(sym3) 390c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%hi(sym3) 400c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 410c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x14 R_MIPS_LO16 sym3 420c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x1C R_MIPS_HI16 sym3 430c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x18 R_MIPS_LO16 sym3 440c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 450c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# HI is already followed by a matching LO, so don't look further, ie. ignore the 460c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# "free" LO with higher offset. 470c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%hi(sym4) 480c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(sym4) 490c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(sym4) 500c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 510c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x20 R_MIPS_HI16 sym4 520c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x24 R_MIPS_LO16 sym4 530c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x28 R_MIPS_LO16 sym4 540c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 550c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# Match 2nd HI with 2nd LO, since it's the one with highest offset among the 560c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# "free" ones. 570c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(sym5) 580c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(sym5) 590c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%hi(sym5) 600c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(sym5) 610c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%hi(sym5) 620c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 630c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x2C R_MIPS_LO16 sym5 640c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x3C R_MIPS_HI16 sym5 650c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x30 R_MIPS_LO16 sym5 660c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x34 R_MIPS_HI16 sym5 670c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x38 R_MIPS_LO16 sym5 680c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 690c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# When more HIs are matched with one LO, sort them in descending order of 700c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# offset. 710c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(sym6) 720c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%hi(sym6) 730c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%hi(sym6) 740c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 750c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x48 R_MIPS_HI16 sym6 760c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x44 R_MIPS_HI16 sym6 770c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x40 R_MIPS_LO16 sym6 780c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 790c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# sym7 is a local symbol, so GOT relocation against it needs a matching LO. 800c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarsym7: 810c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(sym7) 820c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%got(sym7) 830c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 840c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x50 R_MIPS_GOT16 sym7 850c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x4C R_MIPS_LO16 sym7 860c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 870c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# sym8 is not a local symbol, don't look for a matching LO for GOT. 880c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar.global sym8 890c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(sym8) 900c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%got(sym8) 910c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 920c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x54 R_MIPS_LO16 sym8 930c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x58 R_MIPS_GOT16 sym8 940c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 950c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# A small combination of previous checks. 960c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarsymc1: 970c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(symc1) 980c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(symc1) 990c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(symc1) 1000c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%hi(symc1) 1010c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%got(symc1) 1020c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(symc2) 1030c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%hi(symc1) 1040c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%hi(symc1) 1050c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%got(symc2) 1060c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%hi(symc1) 1070c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(symc1) 1080c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainaraddiu $2,$2,%lo(symc2) 1090c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%hi(symc1) 1100c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarlui $2,%hi(symc1) 1110c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 1120c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x78 R_MIPS_HI16 symc1 1130c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x74 R_MIPS_HI16 symc1 1140c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x6C R_MIPS_GOT16 symc1 1150c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x68 R_MIPS_HI16 symc1 1160c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x5C R_MIPS_LO16 symc1 1170c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x8C R_MIPS_HI16 symc1 1180c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x60 R_MIPS_LO16 symc1 1190c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x90 R_MIPS_HI16 symc1 1200c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x64 R_MIPS_LO16 symc1 1210c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x70 R_MIPS_LO16 symc2 1220c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x7C R_MIPS_GOT16 symc2 1230c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x80 R_MIPS_HI16 symc1 1240c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x84 R_MIPS_LO16 symc1 1250c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar# CHECK-NEXT: 0x88 R_MIPS_LO16 symc2 126