llvm/llvm/test/tools/llvm-objdump/MachO/chained-fixups.test

RUN: llvm-objdump -p %p/Inputs/chained-fixups.macho-x86_64 | FileCheck %s
RUN: llvm-otool -l %p/Inputs/chained-fixups.macho-x86_64 | FileCheck %s

CHECK: LC_DYLD_CHAINED_FIXUPS
CHECK: LC_DYLD_EXPORTS_TRIE

RUN: llvm-objdump --macho --chained-fixups %p/Inputs/chained-fixups.macho-x86_64 | \
RUN:     FileCheck --check-prefix=DETAILS -DNAME=%p/Inputs/chained-fixups.macho-x86_64 %s
RUN: llvm-otool -chained_fixups %p/Inputs/chained-fixups.macho-x86_64 | \
RUN:     FileCheck --check-prefix=DETAILS -DNAME=%p/Inputs/chained-fixups.macho-x86_64 %s

DETAILS:      [[NAME]]:
DETAILS-NEXT: chained fixups header (LC_DYLD_CHAINED_FIXUPS)
DETAILS-NEXT:   fixups_version = 0
DETAILS-NEXT:   starts_offset  = 32
DETAILS-NEXT:   imports_offset = 112
DETAILS-NEXT:   symbols_offset = 132
DETAILS-NEXT:   imports_count  = 5
DETAILS-NEXT:   imports_format = 1 (DYLD_CHAINED_IMPORT)
DETAILS-NEXT:   symbols_format = 0
DETAILS-NEXT: chained starts in image
DETAILS-NEXT:   seg_count = 4
DETAILS-NEXT:     seg_offset[0] = 0 (__TEXT)
DETAILS-NEXT:     seg_offset[1] = 24 (__DATA_CONST)
DETAILS-NEXT:     seg_offset[2] = 48 (__DATA)
DETAILS-NEXT:     seg_offset[3] = 0 (__LINKEDIT)
DETAILS-NEXT: chained starts in segment 1 (__DATA_CONST)
DETAILS-NEXT:   size = 24
DETAILS-NEXT:   page_size = 0x1000
DETAILS-NEXT:   pointer_format = 6 (DYLD_CHAINED_PTR_64_OFFSET)
DETAILS-NEXT:   segment_offset = 0x3e0
DETAILS-NEXT:   max_valid_pointer = 0
DETAILS-NEXT:   page_count = 1
DETAILS-NEXT:     page_start[0] = 0
DETAILS-NEXT: chained starts in segment 2 (__DATA)
DETAILS-NEXT:   size = 30
DETAILS-NEXT:   page_size = 0x1000
DETAILS-NEXT:   pointer_format = 6 (DYLD_CHAINED_PTR_64_OFFSET)
DETAILS-NEXT:   segment_offset = 0x3f0
DETAILS-NEXT:   max_valid_pointer = 0
DETAILS-NEXT:   page_count = 4
DETAILS-NEXT:     page_start[0] = 0
DETAILS-NEXT:     page_start[1] = 32
DETAILS-NEXT:     page_start[2] = 65535 (DYLD_CHAINED_PTR_START_NONE)
DETAILS-NEXT:     page_start[3] = 32
DETAILS-NEXT: dyld chained import[0]
DETAILS-NEXT:   lib_ordinal = -2 (flat-namespace)
DETAILS-NEXT:   weak_import = 0
DETAILS-NEXT:   name_offset = 1 (_dynamicLookup)
DETAILS-NEXT: dyld chained import[1]
DETAILS-NEXT:   lib_ordinal = 1 (libdylib)
DETAILS-NEXT:   weak_import = 1
DETAILS-NEXT:   name_offset = 16 (_weakImport)
DETAILS-NEXT: dyld chained import[2]
DETAILS-NEXT:   lib_ordinal = 1 (libdylib)
DETAILS-NEXT:   weak_import = 0
DETAILS-NEXT:   name_offset = 28 (_dylib)
DETAILS-NEXT: dyld chained import[3]
DETAILS-NEXT:   lib_ordinal = -3 (weak)
DETAILS-NEXT:   weak_import = 0
DETAILS-NEXT:   name_offset = 35 (_weakLocal)
DETAILS-NEXT: dyld chained import[4]
DETAILS-NEXT:   lib_ordinal = -3 (weak)
DETAILS-NEXT:   weak_import = 0
DETAILS-NEXT:   name_offset = 46 (_weak)

## This test checks that the output is identical to that of cctools-1001.2 (XCode 14)
## FIXME: Print encoded values of the dyld_chained_import* entries
##
## The input was generated from the following files:
##
## --- dylib.s:
##   .data
##   .globl _weak, _dylib, _weakImport
##   .weak_definition _weak
##   _weak:
##   _dylib:
##   _weakImport:
##
##  $ clang --target=x86_64-apple-macos12 -dynamiclib dylib.s -o libdylib.dylib
##
## --- chained-fixups.s:
##   .global _local, _weak, _weakLocal, _dylib, _weakImport, _dynamicLookup
##   .weak_definition _weakLocal
##   .weak_reference _weakImport
##
##   .data
##   .p2align 4
##   _local:
##   _weakLocal:
##   .quad _local
##   .space 8
##   .quad _weak
##   .space 4096
##   .p2align 4
##   .quad _weakLocal
##   .space 8172
##   .p2align 4
##   .quad _dylib
##   .quad _dylib + 42
##
##   .section __DATA_CONST,__const
##   .p2align 4
##   .quad _weakImport
##   .quad _dynamicLookup
##
## $ clang --target=x86_64-apple-macos12 -dynamiclib -L. -ldylib chained-fixups.s \
##       -o chained-fixups.macho-x86_64 -Wl,-segalign,0x10 -Wl,-U,_dynamicLookup