Compiler projects using llvm
# The binary blobs in this file were created like this:
# llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu Inputs/elf-packed-relocs1.s -o - | obj2yaml | grep Content:

# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-readobj --relocations %t1 | FileCheck --check-prefix=LLVM1 %s
# LLVM1:      Section (1) .rela.dyn {
# LLVM1-NEXT:   0x1100 R_X86_64_RELATIVE - 0x0
# LLVM1-NEXT:   0x1180 R_X86_64_RELATIVE - 0x0
# LLVM1-NEXT:   0x1188 R_X86_64_64 sym1 0x0
# LLVM1-NEXT:   0x1190 R_X86_64_64 sym2 0x0
# LLVM1-NEXT:   0x1191 R_X86_64_64 sym1 0x8
# LLVM1-NEXT:   0x1193 R_X86_64_64 sym2 0xC
# LLVM1-NEXT:   0x1197 R_X86_64_64 sym1 0xA
# LLVM1-NEXT:   0x119F R_X86_64_64 sym2 0xA
# LLVM1-NEXT: }

# RUN: llvm-readelf --relocations %t1 | FileCheck --check-prefix=GNU1 %s
# GNU1:      Relocation section '.rela.dyn' at offset 0x40 contains 8 entries:
# GNU1:      0000000000001100  0000000000000008 R_X86_64_RELATIVE                 0
# GNU1-NEXT: 0000000000001180  0000000000000008 R_X86_64_RELATIVE                 0
# GNU1-NEXT: 0000000000001188  0000000100000001 R_X86_64_64            0000000000000000 sym1 + 0
# GNU1-NEXT: 0000000000001190  0000000200000001 R_X86_64_64            0000000000000000 sym2 + 0
# GNU1-NEXT: 0000000000001191  0000000100000001 R_X86_64_64            0000000000000000 sym1 + 8
# GNU1-NEXT: 0000000000001193  0000000200000001 R_X86_64_64            0000000000000000 sym2 + c
# GNU1-NEXT: 0000000000001197  0000000100000001 R_X86_64_64            0000000000000000 sym1 + a
# GNU1-NEXT: 000000000000119f  0000000200000001 R_X86_64_64            0000000000000000 sym2 + a

# elf-packed-relocs1.s
--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_DYN
  Machine: EM_X86_64
Sections:
  - Name:     .rela.dyn
    Type:     SHT_ANDROID_RELA
    Flags:    [ SHF_ALLOC ]
    Link:     [[LINK=.symtab]]
    Content:  41505332088020020108800280010202088180808010818080802002080181808080100802818080802004020C7E048180808010088180808020
    ShOffset: [[SHOFFSET=<none>]]
Symbols:
  - Name:    sym1
    Binding: STB_GLOBAL
  - Name:    sym2
    Binding: STB_GLOBAL

## Check we report a warning when we are unable to dump relocations for a SHT_ANDROID_RELA section.

# RUN: yaml2obj --docnum=1 -DSHOFFSET=0xffffffff %s -o %t1.broken
# RUN: llvm-readobj --relocations %t1.broken 2>&1 | FileCheck -DFILE=%t1.broken --check-prefix=BROKEN-RELA-LLVM %s
# RUN: llvm-readelf --relocations %t1.broken 2>&1 | FileCheck -DFILE=%t1.broken --check-prefix=BROKEN-RELA-GNU %s

# BROKEN-RELA-LLVM:      Relocations [
# BROKEN-RELA-LLVM-NEXT:   Section (1) .rela.dyn {
# BROKEN-RELA-LLVM-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_ANDROID_RELA section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x3a) that is greater than the file size (0x238)
# BROKEN-RELA-LLVM-NEXT:   }
# BROKEN-RELA-LLVM-NEXT: ]

# BROKEN-RELA-GNU:      warning: '[[FILE]]': unable to get the number of relocations in SHT_ANDROID_RELA section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x3a) that is greater than the file size (0x238)
# BROKEN-RELA-GNU:      Relocation section '.rela.dyn' at offset 0xffffffff contains <?> entries:
# BROKEN-RELA-GNU-NEXT:     Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
# BROKEN-RELA-GNU-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_ANDROID_RELA section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x3a) that is greater than the file size (0x238)

## Check we report a warning when the sh_link field of the SHT_ANDROID_RELA section is broken.

# RUN: yaml2obj --docnum=1 -DLINK=0xffffffff %s -o %t1.broken.link
# RUN: llvm-readobj --relocations %t1.broken.link 2>&1 | \
# RUN:   FileCheck -DFILE=%t1.broken.link --check-prefix=BROKEN-RELA-LINK-LLVM %s
# RUN: llvm-readelf --relocations %t1.broken.link 2>&1 | \
# RUN:   FileCheck -DFILE=%t1.broken.link --check-prefix=BROKEN-RELA-LINK-GNU %s

# BROKEN-RELA-LINK-LLVM:      Relocations [
# BROKEN-RELA-LINK-LLVM-NEXT:   Section (1) .rela.dyn {
# BROKEN-RELA-LINK-LLVM-NEXT: warning: '[[FILE]]': unable to locate a symbol table for SHT_ANDROID_RELA section with index 1: invalid section index: 4294967295
# BROKEN-RELA-LINK-LLVM-NEXT:   }
# BROKEN-RELA-LINK-LLVM-NEXT: ]

# BROKEN-RELA-LINK-GNU:      Relocation section '.rela.dyn' at offset 0x40 contains 8 entries:
# BROKEN-RELA-LINK-GNU-NEXT:  Offset   Info  Type  Symbol's Value  Symbol's Name + Addend
# BROKEN-RELA-LINK-GNU-NEXT: warning: '[[FILE]]': unable to locate a symbol table for SHT_ANDROID_RELA section with index 1: invalid section index: 4294967295

# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-readobj --relocations %t2 | FileCheck --check-prefix=LLVM2 %s
# LLVM2:      Section (1) .rel.dyn {
# LLVM2-NEXT:   0x1008 R_386_32 sym1 0x0
# LLVM2-NEXT:   0x1010 R_386_GOT32 sym2 0x0
# LLVM2-NEXT:   0x100C R_386_RELATIVE - 0x0
# LLVM2-NEXT:   0x1008 R_386_RELATIVE - 0x0
# LLVM2-NEXT:   0x1004 R_386_RELATIVE - 0x0
# LLVM2-NEXT:   0x1000 R_386_RELATIVE - 0x0
# LLVM2-NEXT:   0xFFC R_386_RELATIVE - 0x0
# LLVM2-NEXT:   0xFF8 R_386_RELATIVE - 0x0
# LLVM2-NEXT:   0xFF4 R_386_RELATIVE - 0x0
# LLVM2-NEXT:   0xFF0 R_386_RELATIVE - 0x0
# LLVM2-NEXT: }

# RUN: llvm-readelf --relocations %t2 | FileCheck --check-prefix=GNU2 %s
# GNU2:      Relocation section '.rel.dyn' at offset 0x34 contains 10 entries:
# GNU2:      00001008  00000101 R_386_32               00000000   sym1
# GNU2-NEXT: 00001010  00000203 R_386_GOT32            00000000   sym2
# GNU2-NEXT: 0000100c  00000008 R_386_RELATIVE
# GNU2-NEXT: 00001008  00000008 R_386_RELATIVE
# GNU2-NEXT: 00001004  00000008 R_386_RELATIVE
# GNU2-NEXT: 00001000  00000008 R_386_RELATIVE
# GNU2-NEXT: 00000ffc  00000008 R_386_RELATIVE
# GNU2-NEXT: 00000ff8  00000008 R_386_RELATIVE
# GNU2-NEXT: 00000ff4  00000008 R_386_RELATIVE
# GNU2-NEXT: 00000ff0  00000008 R_386_RELATIVE

# elf-packed-relocs2.s
--- !ELF
FileHeader:
  Class:   ELFCLASS32
  Data:    ELFDATA2LSB
  Type:    ET_DYN
  Machine: EM_386
Sections:
  - Name:     .rel.dyn
    Type:     SHT_ANDROID_REL
    Flags:    [ SHF_ALLOC ]
    Link:     [[LINK=.symtab]]
    Content:  415053320A80200202088102830408037C08
    ShOffset: [[SHOFFSET=<none>]]
Symbols:
  - Name:    sym1
    Binding: STB_GLOBAL
  - Name:    sym2
    Binding: STB_GLOBAL

## Check we report a warning when we are unable to dump relocations for a SHT_ANDROID_REL section.

# RUN: yaml2obj --docnum=2 -DSHOFFSET=0xffffffff %s -o %t2.broken
# RUN: llvm-readobj --relocations %t2.broken 2>&1 | FileCheck -DFILE=%t2.broken --check-prefix=BROKEN-REL-LLVM %s
# RUN: llvm-readelf --relocations %t2.broken 2>&1 | FileCheck -DFILE=%t2.broken --check-prefix=BROKEN-REL-GNU %s

# BROKEN-REL-LLVM:      Relocations [
# BROKEN-REL-LLVM-NEXT:   Section (1) .rel.dyn {
# BROKEN-REL-LLVM-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_ANDROID_REL section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x12) that cannot be represented
# BROKEN-REL-LLVM-NEXT:   }
# BROKEN-REL-LLVM-NEXT: ]

# BROKEN-REL-GNU:      warning: '[[FILE]]': unable to get the number of relocations in SHT_ANDROID_REL section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x12) that cannot be represented
# BROKEN-REL-GNU:      Relocation section '.rel.dyn' at offset 0xffffffff contains <?> entries:
# BROKEN-REL-GNU-NEXT:  Offset     Info    Type                Sym. Value  Symbol's Name
# BROKEN-REL-GNU-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_ANDROID_REL section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x12) that cannot be represented

## Check we report a warning when the sh_link field of the SHT_ANDROID_REL section is broken.

# RUN: yaml2obj --docnum=2 -DLINK=0xffffffff %s -o %t2.broken.link
# RUN: llvm-readobj --relocations %t2.broken.link 2>&1 | \
# RUN:   FileCheck -DFILE=%t2.broken.link --check-prefix=BROKEN-REL-LINK-LLVM %s
# RUN: llvm-readelf --relocations %t2.broken.link 2>&1 | \
# RUN:   FileCheck -DFILE=%t2.broken.link --check-prefix=BROKEN-REL-LINK-GNU %s

# BROKEN-REL-LINK-LLVM:      Relocations [
# BROKEN-REL-LINK-LLVM-NEXT:   Section (1) .rel.dyn {
# BROKEN-REL-LINK-LLVM-NEXT: warning: '[[FILE]]': unable to locate a symbol table for SHT_ANDROID_REL section with index 1: invalid section index: 4294967295
# BROKEN-REL-LINK-LLVM-NEXT:   }
# BROKEN-REL-LINK-LLVM-NEXT: ]

# BROKEN-REL-LINK-GNU:      Relocation section '.rel.dyn' at offset 0x34 contains 10 entries:
# BROKEN-REL-LINK-GNU-NEXT:  Offset  Info  Type  Sym. Value  Symbol's Name
# BROKEN-REL-LINK-GNU-NEXT: warning: '[[FILE]]': unable to locate a symbol table for SHT_ANDROID_REL section with index 1: invalid section index: 4294967295

# RUN: yaml2obj --docnum=3 %s | llvm-readobj --relocations - | FileCheck --check-prefix=LLVM3 %s
#
# LLVM3:      Section (1) .rela.dyn {
# LLVM3-NEXT:   0x1100 R_X86_64_RELATIVE - 0x0
# LLVM3-NEXT:   0x1180 R_X86_64_RELATIVE - 0x8
# LLVM3-NEXT:   0x1200 R_X86_64_64 sym1 0x0
# LLVM3-NEXT:   0x1208 R_X86_64_64 sym2 0x0
# LLVM3-NEXT:   0x1210 R_X86_64_64 sym1 0x0
# LLVM3-NEXT:   0x1218 R_X86_64_64 sym2 0x8
# LLVM3-NEXT: }

# RUN: yaml2obj --docnum=3 %s | llvm-readelf -r - | FileCheck --check-prefix=GNU3 %s
# GNU3:      Relocation section '.rela.dyn' at offset 0x40 contains 6 entries:
# GNU3: 0000000000001100  0000000000000008 R_X86_64_RELATIVE                 0
# GNU3-NEXT: 0000000000001180  0000000000000008 R_X86_64_RELATIVE                 8
# GNU3-NEXT: 0000000000001200  0000000100000001 R_X86_64_64            0000000000000000 sym1 + 0
# GNU3-NEXT: 0000000000001208  0000000200000001 R_X86_64_64            0000000000000000 sym2 + 0
# GNU3-NEXT: 0000000000001210  0000000100000001 R_X86_64_64            0000000000000000 sym1 + 0
# GNU3-NEXT: 0000000000001218  0000000200000001 R_X86_64_64            0000000000000000 sym2 + 8

# elf-packed-relocs3.s
--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_DYN
  Machine: EM_X86_64
Sections:
  - Name:    .rela.dyn
    Type:    SHT_ANDROID_RELA
    Flags:   [ SHF_ALLOC ]
    Link:    .symtab
    Content: 415053320680200208800208008001080802008001818080801008818080802002080881808080100008818080802008
Symbols:
  - Name:    sym1
    Binding: STB_GLOBAL
  - Name:    sym2
    Binding: STB_GLOBAL