llvm/llvm/test/tools/llvm-readobj/ELF/mips-got.test

## Check that we are able to dump MIPS GOT entries using -A properly.

## Check how we dump 64-bit inputs.

# RUN: yaml2obj --docnum=1 -DTYPE=ET_REL %s -o %t.got.o
# RUN: yaml2obj --docnum=1 -DTYPE=ET_DYN %s -o %t.got.so
# RUN: yaml2obj --docnum=1 -DTYPE=ET_EXEC %s -o %t.got.exe

# RUN: llvm-readobj -A %t.got.o 2>&1 | FileCheck %s -DOTHERNUM=0 -check-prefix=BASIC-LLVM
# RUN: llvm-readobj -A %t.got.so 2>&1 | FileCheck %s -DOTHERNUM=0 -check-prefix=BASIC-LLVM
# RUN: llvm-readobj -A %t.got.exe 2>&1 | FileCheck %s -DOTHERNUM=0 -check-prefix=BASIC-LLVM
# RUN: llvm-readelf -A %t.got.o 2>&1 | FileCheck %s -check-prefix=BASIC-GNU \
# RUN:   --implicit-check-not="Number of" --strict-whitespace --match-full-lines
# RUN: llvm-readelf -A %t.got.so 2>&1 | FileCheck %s -check-prefix=BASIC-GNU \
# RUN:   --implicit-check-not="Number of" --strict-whitespace --match-full-lines
# RUN: llvm-readelf -A %t.got.exe 2>&1 | FileCheck %s -check-prefix=BASIC-GNU \
# RUN:   --implicit-check-not="Number of" --strict-whitespace --match-full-lines

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    [[TYPE=ET_EXEC]]
  Machine: EM_MIPS
Sections:
  - Name:    .got
    Type:    SHT_PROGBITS
    Address: 0x1122
    ContentArray: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  ## Lazy resolver.
                    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,  ## Module pointer (GNU extension)
                    0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,  ## Local entry 1
                    0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,  ## Local entry 2
                    0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,  ## Global entry 1
                    0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB ] ## Global entry 2
    Size: [[SIZE=<none>]]
  - Name:   .dynamic
    Type:   SHT_DYNAMIC
    ShType: [[DYNAMICTYPE=<none>]]
    Entries:
      - Tag:   DT_MIPS_LOCAL_GOTNO
        Value: 4
      - Tag:   DT_MIPS_GOTSYM
        Value: 1
      - Tag:   DT_PLTGOT
        Value: 0x1122
DynamicSymbols:
  - Name: foo
  - Name: bar
    Type: STT_FUNC

# BASIC-LLVM:      Primary GOT {
# BASIC-LLVM-NEXT:   Canonical gp value: 0x9112
# BASIC-LLVM-NEXT:   Reserved entries [
# BASIC-LLVM-NEXT:     Entry {
# BASIC-LLVM-NEXT:       Address: 0x1122
# BASIC-LLVM-NEXT:       Access: -32752
# BASIC-LLVM-NEXT:       Initial: 0x0
# BASIC-LLVM-NEXT:       Purpose: Lazy resolver
# BASIC-LLVM-NEXT:     }
# BASIC-LLVM-NEXT:     Entry {
# BASIC-LLVM-NEXT:       Address: 0x112A
# BASIC-LLVM-NEXT:       Access: -32744
# BASIC-LLVM-NEXT:       Initial: 0xFFFFFFFFFFFFFFFF
# BASIC-LLVM-NEXT:       Purpose: Module pointer (GNU extension)
# BASIC-LLVM-NEXT:     }
# BASIC-LLVM-NEXT:   ]
# BASIC-LLVM-NEXT:   Local entries [
# BASIC-LLVM-NEXT:     Entry {
# BASIC-LLVM-NEXT:       Address: 0x1132
# BASIC-LLVM-NEXT:       Access: -32736
# BASIC-LLVM-NEXT:       Initial: 0x1111111111111111
# BASIC-LLVM-NEXT:     }
# BASIC-LLVM-NEXT:     Entry {
# BASIC-LLVM-NEXT:       Address: 0x113A
# BASIC-LLVM-NEXT:       Access: -32728
# BASIC-LLVM-NEXT:       Initial: 0x2222222222222222
# BASIC-LLVM-NEXT:     }
# BASIC-LLVM-NEXT:   ]
# BASIC-LLVM-NEXT:   Global entries [
# BASIC-LLVM-NEXT:     Entry {
# BASIC-LLVM-NEXT:       Address: 0x1142
# BASIC-LLVM-NEXT:       Access: -32720
# BASIC-LLVM-NEXT:       Initial: 0xAAAAAAAAAAAAAAAA
# BASIC-LLVM-NEXT:       Value: 0x0
# BASIC-LLVM-NEXT:       Type: None (0x0)
# BASIC-LLVM-NEXT:       Section: Undefined (0x0)
# BASIC-LLVM-NEXT:       Name: foo (5)
# BASIC-LLVM-NEXT:     }
# BASIC-LLVM-NEXT:     Entry {
# BASIC-LLVM-NEXT:       Address: 0x114A
# BASIC-LLVM-NEXT:       Access: -32712
# BASIC-LLVM-NEXT:       Initial: 0xBBBBBBBBBBBBBBBB
# BASIC-LLVM-NEXT:       Value: 0x0
# BASIC-LLVM-NEXT:       Type: Function (0x2)
# BASIC-LLVM-NEXT:       Section: Undefined (0x0)
# BASIC-LLVM-NEXT:       Name: bar (1)
# BASIC-LLVM-NEXT:     }
# BASIC-LLVM-NEXT:   ]
# BASIC-LLVM-NEXT:   Number of TLS and multi-GOT entries: [[OTHERNUM]]
# BASIC-LLVM-NEXT: }

#            BASIC-GNU:Primary GOT:
#       BASIC-GNU-NEXT: Canonical gp value: 0000000000009112
#      BASIC-GNU-EMPTY:
#       BASIC-GNU-NEXT: Reserved entries:
#       BASIC-GNU-NEXT:           Address     Access          Initial Purpose
#       BASIC-GNU-NEXT:  0000000000001122 -32752(gp) 0000000000000000 Lazy resolver
#       BASIC-GNU-NEXT:  000000000000112a -32744(gp) ffffffffffffffff Module pointer (GNU extension)
#      BASIC-GNU-EMPTY:
#       BASIC-GNU-NEXT: Local entries:
#       BASIC-GNU-NEXT:           Address     Access          Initial
#       BASIC-GNU-NEXT:  0000000000001132 -32736(gp) 1111111111111111 {{$}}
#       BASIC-GNU-NEXT:  000000000000113a -32728(gp) 2222222222222222 {{$}}
#      BASIC-GNU-EMPTY:
#       BASIC-GNU-NEXT: Global entries:
#       BASIC-GNU-NEXT:           Address     Access          Initial         Sym.Val. Type    Ndx Name
#       BASIC-GNU-NEXT:  0000000000001142 -32720(gp) aaaaaaaaaaaaaaaa 0000000000000000 NOTYPE  UND foo
#       BASIC-GNU-NEXT:  000000000000114a -32712(gp) bbbbbbbbbbbbbbbb 0000000000000000 FUNC    UND bar
#      BASIC-GNU-EMPTY:
# BASIC-GNU-OTHER-NEXT: Number of TLS and multi-GOT entries [[OTHERNUM]]

## Check we are able to print the number of TLS and multi-GOT entries properly.

# RUN: yaml2obj --docnum=1 %s -DSIZE=56 -o %t.other.entries1.exe
# RUN: yaml2obj --docnum=1 %s -DSIZE=64 -o %t.other.entries2.exe
# RUN: llvm-readobj -A %t.other.entries1.exe 2>&1 | FileCheck %s -DOTHERNUM=1 --check-prefix=BASIC-LLVM
# RUN: llvm-readobj -A %t.other.entries2.exe 2>&1 | FileCheck %s -DOTHERNUM=2 -check-prefix=BASIC-LLVM
# RUN: llvm-readelf -A %t.other.entries1.exe 2>&1 | FileCheck %s -DOTHERNUM=1 \
# RUN:   --check-prefixes=BASIC-GNU,BASIC-GNU-OTHER --strict-whitespace --match-full-lines
# RUN: llvm-readelf -A %t.other.entries2.exe 2>&1 | FileCheck %s -DOTHERNUM=2 \
# RUN:   --check-prefixes=BASIC-GNU,BASIC-GNU-OTHER --strict-whitespace --match-full-lines

## Check how we print static GOT. Our code assumes that the GOT is static when there
## is no .dynamic section, so we change its type to hide it.

# RUN: yaml2obj --docnum=1 -DDYNAMICTYPE=SHT_PROGBITS %s -o %t.got-static.exe
# RUN: llvm-readobj -A %t.got-static.exe | FileCheck %s --check-prefix=STATIC-GOT-LLVM
# RUN: llvm-readelf -A %t.got-static.exe | FileCheck %s --check-prefix=STATIC-GOT-GNU

# STATIC-GOT-LLVM:      Static GOT {
# STATIC-GOT-LLVM-NEXT:   Canonical gp value: 0x9112
# STATIC-GOT-LLVM-NEXT:   Reserved entries [
# STATIC-GOT-LLVM-NEXT:     Entry {
# STATIC-GOT-LLVM-NEXT:       Address: 0x1122
# STATIC-GOT-LLVM-NEXT:       Access: -32752
# STATIC-GOT-LLVM-NEXT:       Initial: 0x0
# STATIC-GOT-LLVM-NEXT:       Purpose: Lazy resolver
# STATIC-GOT-LLVM-NEXT:     }
# STATIC-GOT-LLVM-NEXT:     Entry {
# STATIC-GOT-LLVM-NEXT:       Address: 0x112A
# STATIC-GOT-LLVM-NEXT:       Access: -32744
# STATIC-GOT-LLVM-NEXT:       Initial: 0xFFFFFFFFFFFFFFFF
# STATIC-GOT-LLVM-NEXT:       Purpose: Module pointer (GNU extension)
# STATIC-GOT-LLVM-NEXT:     }
# STATIC-GOT-LLVM-NEXT:   ]
# STATIC-GOT-LLVM-NEXT:   Local entries [
# STATIC-GOT-LLVM-NEXT:     Entry {
# STATIC-GOT-LLVM-NEXT:       Address: 0x1132
# STATIC-GOT-LLVM-NEXT:       Access: -32736
# STATIC-GOT-LLVM-NEXT:       Initial: 0x1111111111111111
# STATIC-GOT-LLVM-NEXT:     }
# STATIC-GOT-LLVM-NEXT:     Entry {
# STATIC-GOT-LLVM-NEXT:       Address: 0x113A
# STATIC-GOT-LLVM-NEXT:       Access: -32728
# STATIC-GOT-LLVM-NEXT:       Initial: 0x2222222222222222
# STATIC-GOT-LLVM-NEXT:     }
# STATIC-GOT-LLVM-NEXT:     Entry {
# STATIC-GOT-LLVM-NEXT:       Address: 0x1142
# STATIC-GOT-LLVM-NEXT:       Access: -32720
# STATIC-GOT-LLVM-NEXT:       Initial: 0xAAAAAAAAAAAAAAAA
# STATIC-GOT-LLVM-NEXT:     }
# STATIC-GOT-LLVM-NEXT:     Entry {
# STATIC-GOT-LLVM-NEXT:       Address: 0x114A
# STATIC-GOT-LLVM-NEXT:       Access: -32712
# STATIC-GOT-LLVM-NEXT:       Initial: 0xBBBBBBBBBBBBBBBB
# STATIC-GOT-LLVM-NEXT:     }
# STATIC-GOT-LLVM-NEXT:   ]
# STATIC-GOT-LLVM-NEXT: }

# STATIC-GOT-GNU:       Static GOT:
# STATIC-GOT-GNU-NEXT:   Canonical gp value: 0000000000009112
# STATIC-GOT-GNU-EMPTY:
# STATIC-GOT-GNU-NEXT:   Reserved entries:
# STATIC-GOT-GNU-NEXT:             Address     Access          Initial Purpose
# STATIC-GOT-GNU-NEXT:    0000000000001122 -32752(gp) 0000000000000000 Lazy resolver
# STATIC-GOT-GNU-NEXT:    000000000000112a -32744(gp) ffffffffffffffff Module pointer (GNU extension)
# STATIC-GOT-GNU-EMPTY:
# STATIC-GOT-GNU-NEXT:   Local entries:
# STATIC-GOT-GNU-NEXT:             Address     Access          Initial
# STATIC-GOT-GNU-NEXT:    0000000000001132 -32736(gp) 1111111111111111
# STATIC-GOT-GNU-NEXT:    000000000000113a -32728(gp) 2222222222222222
# STATIC-GOT-GNU-NEXT:    0000000000001142 -32720(gp) aaaaaaaaaaaaaaaa
# STATIC-GOT-GNU-NEXT:    000000000000114a -32712(gp) bbbbbbbbbbbbbbbb
# STATIC-GOT-GNU-EMPTY:
# STATIC-GOT-GNU-NOT:   {{.}}

## Check how we dump 32-bit inputs.

# RUN: yaml2obj --docnum=2 %s -o %t.got32.exe
# RUN: llvm-readobj -A %t.got32.exe 2>&1 | FileCheck %s -check-prefix=BASIC32-LLVM
# RUN: llvm-readelf -A %t.got32.exe 2>&1 | FileCheck %s -check-prefix=BASIC32-GNU \
# RUN:   --strict-whitespace --match-full-lines

# BASIC32-LLVM:      Primary GOT {
# BASIC32-LLVM-NEXT:   Canonical gp value: 0x9112
# BASIC32-LLVM-NEXT:   Reserved entries [
# BASIC32-LLVM-NEXT:     Entry {
# BASIC32-LLVM-NEXT:       Address: 0x1122
# BASIC32-LLVM-NEXT:       Access: -32752
# BASIC32-LLVM-NEXT:       Initial: 0x0
# BASIC32-LLVM-NEXT:       Purpose: Lazy resolver
# BASIC32-LLVM-NEXT:     }
# BASIC32-LLVM-NEXT:     Entry {
# BASIC32-LLVM-NEXT:       Address: 0x1126
# BASIC32-LLVM-NEXT:       Access: -32748
# BASIC32-LLVM-NEXT:       Initial: 0xFFFFFFFF
# BASIC32-LLVM-NEXT:       Purpose: Module pointer (GNU extension)
# BASIC32-LLVM-NEXT:     }
# BASIC32-LLVM-NEXT:   ]
# BASIC32-LLVM-NEXT:   Local entries [
# BASIC32-LLVM-NEXT:     Entry {
# BASIC32-LLVM-NEXT:       Address: 0x112A
# BASIC32-LLVM-NEXT:       Access: -32744
# BASIC32-LLVM-NEXT:       Initial: 0x11111111
# BASIC32-LLVM-NEXT:     }
# BASIC32-LLVM-NEXT:     Entry {
# BASIC32-LLVM-NEXT:       Address: 0x112E
# BASIC32-LLVM-NEXT:       Access: -32740
# BASIC32-LLVM-NEXT:       Initial: 0x22222222
# BASIC32-LLVM-NEXT:     }
# BASIC32-LLVM-NEXT:   ]
# BASIC32-LLVM-NEXT:   Global entries [
# BASIC32-LLVM-NEXT:     Entry {
# BASIC32-LLVM-NEXT:       Address: 0x1132
# BASIC32-LLVM-NEXT:       Access: -32736
# BASIC32-LLVM-NEXT:       Initial: 0xAAAAAAAA
# BASIC32-LLVM-NEXT:       Value: 0x0
# BASIC32-LLVM-NEXT:       Type: None (0x0)
# BASIC32-LLVM-NEXT:       Section: Undefined (0x0)
# BASIC32-LLVM-NEXT:       Name: foo (5)
# BASIC32-LLVM-NEXT:     }
# BASIC32-LLVM-NEXT:     Entry {
# BASIC32-LLVM-NEXT:       Address: 0x1136
# BASIC32-LLVM-NEXT:       Access: -32732
# BASIC32-LLVM-NEXT:       Initial: 0xBBBBBBBB
# BASIC32-LLVM-NEXT:       Value: 0x0
# BASIC32-LLVM-NEXT:       Type: Function (0x2)
# BASIC32-LLVM-NEXT:       Section: Undefined (0x0)
# BASIC32-LLVM-NEXT:       Name: bar (1)
# BASIC32-LLVM-NEXT:     }
# BASIC32-LLVM-NEXT:   ]
# BASIC32-LLVM-NEXT:   Number of TLS and multi-GOT entries: 1
# BASIC32-LLVM-NEXT: }

#       BASIC32-GNU:Primary GOT:
#  BASIC32-GNU-NEXT: Canonical gp value: 00009112
# BASIC32-GNU-EMPTY:
#  BASIC32-GNU-NEXT: Reserved entries:
#  BASIC32-GNU-NEXT:   Address     Access  Initial Purpose
#  BASIC32-GNU-NEXT:  00001122 -32752(gp) 00000000 Lazy resolver
#  BASIC32-GNU-NEXT:  00001126 -32748(gp) ffffffff Module pointer (GNU extension)
# BASIC32-GNU-EMPTY:
#  BASIC32-GNU-NEXT: Local entries:
#  BASIC32-GNU-NEXT:   Address     Access  Initial
#  BASIC32-GNU-NEXT:  0000112a -32744(gp) 11111111 {{$}}
#  BASIC32-GNU-NEXT:  0000112e -32740(gp) 22222222 {{$}}
# BASIC32-GNU-EMPTY:
#  BASIC32-GNU-NEXT: Global entries:
#  BASIC32-GNU-NEXT:   Address     Access  Initial Sym.Val. Type    Ndx Name
#  BASIC32-GNU-NEXT:  00001132 -32736(gp) aaaaaaaa 00000000 NOTYPE  UND foo
#  BASIC32-GNU-NEXT:  00001136 -32732(gp) bbbbbbbb 00000000 FUNC    UND bar
# BASIC32-GNU-EMPTY:
#  BASIC32-GNU-NEXT: Number of TLS and multi-GOT entries 1

--- !ELF
FileHeader:
  Class:   ELFCLASS32
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_MIPS
Sections:
  - Name:    .got
    Type:    SHT_PROGBITS
    Address: 0x1122
    ContentArray: [ 0x00, 0x00, 0x00, 0x00,  ## Lazy resolver.
                    0xFF, 0xFF, 0xFF, 0xFF,  ## Module pointer (GNU extension).
                    0x11, 0x11, 0x11, 0x11,  ## Local entry 1.
                    0x22, 0x22, 0x22, 0x22,  ## Local entry 2.
                    0xAA, 0xAA, 0xAA, 0xAA,  ## Global entry 1.
                    0xBB, 0xBB, 0xBB, 0xBB,  ## Global entry 2.
                    0x00, 0x00, 0x00, 0x00 ] ## Other entry.
  - Name: .dynamic
    Type: SHT_DYNAMIC
    Entries:
      - Tag:   DT_MIPS_LOCAL_GOTNO
        Value: 4
      - Tag:   DT_MIPS_GOTSYM
        Value: 1
      - Tag:   DT_PLTGOT
        Value: 0x1122
DynamicSymbols:
  - Name: foo
  - Name: bar
    Type: STT_FUNC

## Check what we print when there are no local nor global GOT entries.

# RUN: yaml2obj --docnum=3 %s -o %t.got-noentries.exe
# RUN: llvm-readobj -A %t.got-noentries.exe | FileCheck %s --check-prefix=GOT-EMPTY-LLVM
# RUN: llvm-readelf -A %t.got-noentries.exe | FileCheck %s --check-prefix=GOT-EMPTY-GNU

# GOT-EMPTY-LLVM:      Primary GOT {
# GOT-EMPTY-LLVM-NEXT:   Canonical gp value: 0x9112
# GOT-EMPTY-LLVM-NEXT:   Reserved entries [
# GOT-EMPTY-LLVM-NEXT:     Entry {
# GOT-EMPTY-LLVM-NEXT:       Address: 0x1122
# GOT-EMPTY-LLVM-NEXT:       Access: -32752
# GOT-EMPTY-LLVM-NEXT:       Initial: 0x0
# GOT-EMPTY-LLVM-NEXT:       Purpose: Lazy resolver
# GOT-EMPTY-LLVM-NEXT:     }
# GOT-EMPTY-LLVM-NEXT:     Entry {
# GOT-EMPTY-LLVM-NEXT:       Address: 0x112A
# GOT-EMPTY-LLVM-NEXT:       Access: -32744
# GOT-EMPTY-LLVM-NEXT:       Initial: 0xFFFFFFFFFFFFFFFF
# GOT-EMPTY-LLVM-NEXT:       Purpose: Module pointer (GNU extension)
# GOT-EMPTY-LLVM-NEXT:     }
# GOT-EMPTY-LLVM-NEXT:   ]
# GOT-EMPTY-LLVM-NEXT:   Local entries [
# GOT-EMPTY-LLVM-NEXT:   ]
# GOT-EMPTY-LLVM-NEXT:   Global entries [
# GOT-EMPTY-LLVM-NEXT:   ]
# GOT-EMPTY-LLVM-NEXT:   Number of TLS and multi-GOT entries: 0
# GOT-EMPTY-LLVM-NEXT: }

# GOT-EMPTY-GNU:      Primary GOT:
# GOT-EMPTY-GNU-NEXT:  Canonical gp value: 0000000000009112
# GOT-EMPTY-GNU-EMPTY:
# GOT-EMPTY-GNU-NEXT:  Reserved entries:
# GOT-EMPTY-GNU-NEXT:            Address     Access          Initial Purpose
# GOT-EMPTY-GNU-NEXT:   0000000000001122 -32752(gp) 0000000000000000 Lazy resolver
# GOT-EMPTY-GNU-NEXT:   000000000000112a -32744(gp) ffffffffffffffff Module pointer (GNU extension)
# GOT-EMPTY-GNU-NOT:  {{.}}

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_MIPS
Sections:
  - Name:    .got
    Type:    SHT_PROGBITS
    Address: 0x1122
    ContentArray: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  ## Lazy resolver.
                    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ] ## Module pointer (GNU extension)
    Size: [[SIZE=<none>]]
  - Name: .dynamic
    Type: SHT_DYNAMIC
    Entries:
      - Tag:   DT_MIPS_LOCAL_GOTNO
        Value: 2
      - Tag:   DT_MIPS_GOTSYM
        Value: 1
      - Tag:   DT_PLTGOT
        Value: 0x1122
DynamicSymbols: []

## Check we report errors when dynamic tags, needed for dumping GOT, are missing.

# RUN: yaml2obj --docnum=4 -DTAG1=DT_MIPS_LOCAL_GOTNO -DTAG2=DT_MIPS_GOTSYM %s -o %t.err1.o
# RUN: llvm-readobj -A %t.err1.o 2>&1 | FileCheck %s -DFILE=%t.err1.o -check-prefixes=NO-OUTPUT,ERR1

# RUN: yaml2obj --docnum=4 -DTAG1=DT_PLTGOT -DTAG2=DT_MIPS_GOTSYM %s -o %t.err2.o
# RUN: llvm-readobj -A %t.err2.o 2>&1 | FileCheck %s -DFILE=%t.err2.o -check-prefixes=NO-OUTPUT,ERR2

# RUN: yaml2obj --docnum=4 -DTAG1=DT_PLTGOT -DTAG2=DT_MIPS_LOCAL_GOTNO %s -o %t.err3.o
# RUN: llvm-readobj -A %t.err3.o 2>&1 | FileCheck %s -DFILE=%t.err3.o -check-prefixes=NO-OUTPUT,ERR3

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_MIPS
Sections:
  - Name: .dynamic
    Type: SHT_DYNAMIC
    Entries:
      - Tag:   [[TAG1]]
        Value: 0
      - Tag:   [[TAG2]]
        Value: 0
      - Tag:   DT_NULL
        Value: 0
DynamicSymbols: []

# RUN: yaml2obj --docnum=5 -DVAL1=0xffff %s -o %t.err4.o
# RUN: llvm-readobj -A %t.err4.o 2>&1 | FileCheck %s -DFILE=%t.err4.o -check-prefixes=NO-OUTPUT,ERR4

# RUN: yaml2obj --docnum=5 -DVAL2=0xffff %s -o %t.err5.o
# RUN: llvm-readobj -A %t.err5.o 2>&1 | FileCheck %s -DFILE=%t.err5.o -check-prefixes=NO-OUTPUT,ERR5

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_MIPS
Sections:
  - Name: .dynamic
    Type: SHT_DYNAMIC
    Entries:
      - Tag:   DT_MIPS_LOCAL_GOTNO
        Value: 0
      - Tag:   DT_MIPS_GOTSYM
        Value: [[VAL1=0]]
      - Tag:   DT_PLTGOT
        Value: [[VAL2=0]]
DynamicSymbols: []

# NO-OUTPUT:      LoadName: <Not found>
# NO-OUTPUT-NEXT: There is no .MIPS.abiflags section in the file.
# NO-OUTPUT-NEXT: There is no .MIPS.options section in the file.
# NO-OUTPUT-NEXT: There is no .reginfo section in the file.

# ERR1-NEXT: warning: '[[FILE]]': cannot find PLTGOT dynamic tag
# ERR2-NEXT: warning: '[[FILE]]': cannot find MIPS_LOCAL_GOTNO dynamic tag
# ERR3-NEXT: warning: '[[FILE]]': cannot find MIPS_GOTSYM dynamic tag
# ERR4-NEXT: warning: '[[FILE]]': DT_MIPS_GOTSYM value (65535) exceeds the number of dynamic symbols (1)
# ERR5-NEXT: warning: '[[FILE]]': there is no non-empty GOT section at 0xffff

# NO-OUTPUT-EMPTY:
# NO-OUTPUT-NOT: {{.}}

## Check that we do not report a warning about the .got section when we are able to locate it by name.
# RUN: yaml2obj --docnum=6 -DNAME=0xffff %s -o %t.err6.o
# RUN: llvm-readobj -A %t.err6.o 2>&1 | \
# RUN:   FileCheck %s -DFILE=%t.err6.o -check-prefix=NAME-ERR-FOUND --implicit-check-not=warning:
# RUN: llvm-readelf -A %t.err6.o 2>&1 | \
# RUN:   FileCheck %s -DFILE=%t.err6.o -check-prefix=NAME-ERR-FOUND --implicit-check-not=warning:

# NAME-ERR-FOUND:      warning: '[[FILE]]': unable to read the name of SHT_PROGBITS section with index 1: a section [index 1] has an invalid sh_name (0xffff) offset which goes past the end of the section name string table
# NAME-ERR-FOUND-NEXT: warning: '[[FILE]]': unable to read the name of SHT_PROGBITS section with index 3: a section [index 3] has an invalid sh_name (0xffff) offset which goes past the end of the section name string table

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_MIPS
Sections:
  - Type:   SHT_PROGBITS
    ShName: [[NAME=<none>]]
  - Name:   .got
    Type:   SHT_PROGBITS
    ShName: [[GOTNAME=<none>]]
  - Type:   SHT_PROGBITS
    ShName: [[NAME=<none>]]

## Check we report a warning when we are unable to find the .got section due to an error.
# RUN: yaml2obj --docnum=6 -DGOTNAME=0xffff %s -o %t.err7.o
# RUN: llvm-readelf -A %t.err7.o 2>&1 | FileCheck %s -DFILE=%t.err7.o --check-prefix=NAME-ERR-NOTFOUND --implicit-check-not=warning:
# RUN: llvm-readobj -A %t.err7.o 2>&1 | FileCheck %s -DFILE=%t.err7.o --check-prefix=NAME-ERR-NOTFOUND --implicit-check-not=warning:

# NAME-ERR-NOTFOUND:      warning: '[[FILE]]': unable to read the name of SHT_PROGBITS section with index 2: a section [index 2] has an invalid sh_name (0xffff) offset which goes past the end of the section name string table

## Check that we correctly show .got section content when there are some other zero-sized
## sections with the same address as the .got section.
## In this test the empty .data section has the same address as the .got section.

# RUN: yaml2obj --docnum=7 %s -o %t.err7.o
# RUN: llvm-readobj -A %t.err7.o 2>&1 | FileCheck %s -DFILE=%t.err7.o --check-prefix=SAME-ADDR-LLVM
# RUN: llvm-readelf -A %t.err7.o 2>&1 | FileCheck %s -DFILE=%t.err7.o --check-prefix=SAME-ADDR-GNU

# SAME-ADDR-LLVM:      Primary GOT {
# SAME-ADDR-LLVM-NEXT:   Canonical gp value: 0x9112
# SAME-ADDR-LLVM-NEXT:   Reserved entries [
# SAME-ADDR-LLVM-NEXT:     Entry {
# SAME-ADDR-LLVM-NEXT:       Address: 0x1122
# SAME-ADDR-LLVM-NEXT:       Access: -32752
# SAME-ADDR-LLVM-NEXT:       Initial: 0x0
# SAME-ADDR-LLVM-NEXT:       Purpose: Lazy resolver
# SAME-ADDR-LLVM-NEXT:     }
# SAME-ADDR-LLVM-NEXT:   ]
# SAME-ADDR-LLVM-NEXT:   Local entries [
# SAME-ADDR-LLVM-NEXT:   ]
# SAME-ADDR-LLVM-NEXT:   Global entries [
# SAME-ADDR-LLVM-NEXT:     Entry {
# SAME-ADDR-LLVM-NEXT:       Address: 0x112A
# SAME-ADDR-LLVM-NEXT:       Access: -32744
# SAME-ADDR-LLVM-NEXT:       Initial: 0x0
# SAME-ADDR-LLVM-NEXT:       Value: 0x0
# SAME-ADDR-LLVM-NEXT:       Type: None (0x0)
# SAME-ADDR-LLVM-NEXT:       Section: Undefined (0x0)
# SAME-ADDR-LLVM-NEXT:       Name: foo (1)
# SAME-ADDR-LLVM-NEXT:     }
# SAME-ADDR-LLVM-NEXT:   ]
# SAME-ADDR-LLVM-NEXT:   Number of TLS and multi-GOT entries: 0
# SAME-ADDR-LLVM-NEXT: }

# SAME-ADDR-GNU:      Primary GOT:
# SAME-ADDR-GNU-NEXT:  Canonical gp value: 0000000000009112
# SAME-ADDR-GNU-EMPTY:
# SAME-ADDR-GNU-NEXT:  Reserved entries:
# SAME-ADDR-GNU-NEXT:            Address     Access          Initial Purpose
# SAME-ADDR-GNU-NEXT:   0000000000001122 -32752(gp) 0000000000000000 Lazy resolver
# SAME-ADDR-GNU-EMPTY:
# SAME-ADDR-GNU-NEXT:  Global entries:
# SAME-ADDR-GNU-NEXT:            Address     Access          Initial         Sym.Val. Type    Ndx Name
# SAME-ADDR-GNU-NEXT:   000000000000112a -32744(gp) 0000000000000000 0000000000000000 NOTYPE  UND foo

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_MIPS
Sections:
  - Name:    .data
    Type:    SHT_PROGBITS
    Address: 0x1122
    Size:    0
  - Name:    .got
    Type:    SHT_PROGBITS
    Address: 0x1122
    Size:    16
  - Name: .dynamic
    Type: SHT_DYNAMIC
    Entries:
      - Tag:   DT_MIPS_LOCAL_GOTNO
        Value: 1
      - Tag:   DT_MIPS_GOTSYM
        Value: 1
      - Tag:   DT_PLTGOT
        Value: 0x1122
DynamicSymbols:
  - Name: foo

## Check how we print global GOT entries when they are unnamed section symbols.
# RUN: yaml2obj --docnum=8 %s -o %t.err8.o
# RUN: llvm-readobj -A %t.err8.o 2>&1 | FileCheck %s -DFILE=%t.err8.o --check-prefix=SEC-SYMS-LLVM
# RUN: llvm-readelf -A %t.err8.o 2>&1 | FileCheck %s -DFILE=%t.err8.o --check-prefix=SEC-SYMS-GNU

# SEC-SYMS-LLVM:      Global entries [
# SEC-SYMS-LLVM-NEXT:   Entry {
# SEC-SYMS-LLVM:          Section: Absolute (0xFFF1)
# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)
# SEC-SYMS-LLVM-NEXT:     Name: <?> (0)
# SEC-SYMS-LLVM-NEXT:   }
# SEC-SYMS-LLVM-NEXT:   Entry {
# SEC-SYMS-LLVM:          Section: .got (0x1)
# SEC-SYMS-LLVM-NEXT:     Name: .got (0)
# SEC-SYMS-LLVM-NEXT:   }
# SEC-SYMS-LLVM-NEXT:   Entry {
# SEC-SYMS-LLVM:          Section: Common (0xFFF2)
# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)
# SEC-SYMS-LLVM-NEXT:     Name: <?> (0)
# SEC-SYMS-LLVM-NEXT:   }
# SEC-SYMS-LLVM-NEXT: Entry {
# SEC-SYMS-LLVM:          Type: Section (0x3)
# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': found an extended symbol index (4), but unable to locate the extended symbol index table
# SEC-SYMS-LLVM-NEXT:     Section: Reserved (0xFFFF)
# SEC-SYMS-LLVM-NEXT:     Name: <?> (0)
# SEC-SYMS-LLVM-NEXT:   }
# SEC-SYMS-LLVM-NEXT: ]

# SEC-SYMS-GNU:      Global entries:
# SEC-SYMS-GNU-NEXT:  {{.*}} Ndx Name
# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)
# SEC-SYMS-GNU-NEXT:  {{.*}} ABS <?>
# SEC-SYMS-GNU-NEXT:  {{.*}}   1 .got
# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)
# SEC-SYMS-GNU-NEXT:  {{.*}} COM <?>
# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': found an extended symbol index (4), but unable to locate the extended symbol index table
# SEC-SYMS-GNU-NEXT:  {{.*}} RSV[0xffff] <?>

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_MIPS
Sections:
  - Name:    .got
    Type:    SHT_PROGBITS
    Address: 0x1122
    Size:    48
  - Name: .dynamic
    Type: SHT_DYNAMIC
    Entries:
      - Tag:   DT_MIPS_LOCAL_GOTNO
        Value: 1
      - Tag:   DT_MIPS_GOTSYM
        Value: 1
      - Tag:   DT_PLTGOT
        Value: 0x1122
DynamicSymbols:
  - Type:    STT_SECTION
    Index:   SHN_ABS
  - Type:    STT_SECTION
    Section: .got
  - Type:    STT_SECTION
    Index:   SHN_COMMON
  - Type:    STT_SECTION
    Index:   SHN_XINDEX