brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.8 KiB · ff72cc3 Raw
179 lines · plain
1# REQUIRES: x862# RUN: rm -rf %t; split-file %s %t3# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libfoo.s -o %t/libfoo.o4# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/strongref.s -o %t/strongref.o5# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o6# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/invalid.s -o %t/invalid.o7# RUN: %lld -lSystem -dylib %t/libfoo.o -o %t/libfoo.dylib8 9# RUN: %lld -lSystem %t/test.o %t/libfoo.dylib -o %t/test10# RUN: %lld -fixup_chains -lSystem %t/test.o %t/libfoo.dylib -o %t/chained11# RUN: llvm-objdump --macho --syms --bind --lazy-bind %t/test | FileCheck %s --check-prefixes=SYMS,BIND12# RUN: llvm-objdump --macho --syms --dyld-info %t/chained | FileCheck %s --check-prefixes=CHAINED13## llvm-objdump doesn't print out all the flags info for lazy & weak bindings,14## so we use obj2yaml instead to test them.15# RUN: obj2yaml %t/test | FileCheck %s --check-prefix=YAML16 17# RUN: %lld -lSystem %t/libfoo.dylib %t/test.o -o %t/test18# RUN: llvm-objdump --macho --syms --bind --lazy-bind %t/test | FileCheck %s --check-prefixes=SYMS,BIND19# RUN: obj2yaml %t/test | FileCheck %s --check-prefix=YAML20 21# SYMS:     SYMBOL TABLE:22# SYMS-DAG: 0000000000000000  w  *UND* _foo23# SYMS-DAG: 0000000000000000  w  *UND* _foo_fn24# SYMS-DAG: 0000000000000000  w  *UND* _foo_tlv25# SYMS-DAG: 0000000000000000  w  *UND* _weak_foo26# SYMS-DAG: 0000000000000000  w  *UND* _weak_foo_fn27 28# BIND:      Bind table:29# BIND-NEXT: segment       section          address         type     addend dylib   symbol30# BIND-DAG:  __DATA        __data           0x{{[0-9a-f]+}} pointer       0 libfoo  _foo (weak_import)31# BIND-DAG:  __DATA_CONST  __got            0x{{[0-9a-f]+}} pointer       0 libfoo  _foo (weak_import)32# BIND-DAG:  __DATA        __thread_ptrs    0x{{[0-9a-f]+}} pointer       0 libfoo  _foo_tlv (weak_import)33# BIND-DAG:  __DATA        __data           0x{{[0-9a-f]+}} pointer       0 libfoo  _weak_foo (weak_import)34# BIND-DAG:  __DATA        __la_symbol_ptr  0x{{[0-9a-f]+}} pointer       0 libfoo  _weak_foo_fn (weak_import)35# BIND:      Lazy bind table:36# BIND-NEXT: segment       section          address                         dylib   symbol37# BIND-DAG:  __DATA        __la_symbol_ptr  0x{{[0-9a-f]+}}                  libfoo  _foo_fn38 39# CHAINED:      dyld information:40# CHAINED-NEXT: segment      section       address pointer type  addend dylib    symbol/vm address41# CHAINED-DAG:  __DATA_CONST __got             {{.*}}      bind  0x0    libfoo   _foo (weak import)42# CHAINED-DAG:  __DATA       __data            {{.*}}      bind  0x0    libfoo   _foo (weak import)43# CHAINED-DAG:  __DATA       __thread_ptrs     {{.*}}      bind  0x0    libfoo   _foo_tlv (weak import)44# CHAINED-DAG:  __DATA_CONST __got             {{.*}}      bind  0x0    libfoo   _foo_fn (weak import)45# CHAINED-DAG:  __DATA       __data            {{.*}}      bind  0x0    weak     _weak_foo (weak import)46# CHAINED-DAG:  __DATA_CONST __got             {{.*}}      bind  0x0    weak     _weak_foo_fn (weak import)47 48# YAML-LABEL: WeakBindOpcodes:49# YAML:        - Opcode:          BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM50# YAML-NEXT:     Imm:             051# YAML-NEXT:     Symbol:          _weak_foo_fn52# YAML:        - Opcode:          BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM53# YAML-NEXT:     Imm:             054# YAML-NEXT:     Symbol:          _weak_foo55# YAML-LABEL: LazyBindOpcodes:56# YAML:        - Opcode:          BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM57# YAML-NEXT:     Imm:             158# YAML-NEXT:     Symbol:          _foo_fn59 60## Check that if both strong & weak references are present in inputs, the weak61## reference takes priority. NOTE: ld64 actually emits a strong reference if62## the reference is to a function symbol or a TLV. I'm not sure if there's a63## good reason for that, so I'm deviating here for a simpler implementation.64# RUN: %lld -lSystem %t/test.o %t/strongref.o %t/libfoo.dylib -o %t/with-strong65# RUN: %lld -fixup_chains -lSystem %t/test.o %t/strongref.o %t/libfoo.dylib -o %t/with-strong-chained66# RUN: llvm-objdump --macho --bind %t/with-strong | FileCheck %s --check-prefix=STRONG-BIND67# RUN: llvm-objdump --macho --dyld-info %t/with-strong-chained | FileCheck %s --check-prefix=STRONG-CHAINED68# RUN: obj2yaml %t/with-strong | FileCheck %s --check-prefix=STRONG-YAML69# RUN: %lld -lSystem %t/strongref.o %t/test.o %t/libfoo.dylib -o %t/with-strong70# RUN: %lld -fixup_chains -lSystem %t/strongref.o %t/test.o %t/libfoo.dylib -o %t/with-strong-chained71# RUN: llvm-objdump --macho --bind %t/with-strong | FileCheck %s --check-prefix=STRONG-BIND72# RUN: llvm-objdump --macho --dyld-info %t/with-strong-chained | FileCheck %s --check-prefix=STRONG-CHAINED73# RUN: obj2yaml %t/with-strong | FileCheck %s --check-prefix=STRONG-YAML74# RUN: %lld -lSystem %t/libfoo.dylib %t/strongref.o %t/test.o -o %t/with-strong75# RUN: %lld -fixup_chains -lSystem %t/libfoo.dylib %t/strongref.o %t/test.o -o %t/with-strong-chained76# RUN: llvm-objdump --macho --bind %t/with-strong | FileCheck %s --check-prefix=STRONG-BIND77# RUN: llvm-objdump --macho --dyld-info %t/with-strong-chained | FileCheck %s --check-prefix=STRONG-CHAINED78# RUN: obj2yaml %t/with-strong | FileCheck %s --check-prefix=STRONG-YAML79# RUN: %lld -lSystem %t/libfoo.dylib %t/test.o %t/strongref.o -o %t/with-strong80# RUN: %lld -fixup_chains -lSystem %t/libfoo.dylib %t/test.o %t/strongref.o -o %t/with-strong-chained81# RUN: llvm-objdump --macho --bind %t/with-strong | FileCheck %s --check-prefix=STRONG-BIND82# RUN: llvm-objdump --macho --dyld-info %t/with-strong-chained | FileCheck %s --check-prefix=STRONG-CHAINED83# RUN: obj2yaml %t/with-strong | FileCheck %s --check-prefix=STRONG-YAML84# RUN: %lld -lSystem %t/test.o %t/libfoo.dylib %t/strongref.o -o %t/with-strong85# RUN: %lld -fixup_chains -lSystem %t/test.o %t/libfoo.dylib %t/strongref.o -o %t/with-strong-chained86# RUN: llvm-objdump --macho --bind %t/with-strong | FileCheck %s --check-prefix=STRONG-BIND87# RUN: llvm-objdump --macho --dyld-info %t/with-strong-chained | FileCheck %s --check-prefix=STRONG-CHAINED88# RUN: obj2yaml %t/with-strong | FileCheck %s --check-prefix=STRONG-YAML89# RUN: %lld -lSystem %t/strongref.o %t/libfoo.dylib %t/test.o -o %t/with-strong90# RUN: %lld -fixup_chains -lSystem %t/strongref.o %t/libfoo.dylib %t/test.o -o %t/with-strong-chained91# RUN: llvm-objdump --macho --bind %t/with-strong | FileCheck %s --check-prefix=STRONG-BIND92# RUN: llvm-objdump --macho --dyld-info %t/with-strong-chained | FileCheck %s --check-prefix=STRONG-CHAINED93# RUN: obj2yaml %t/with-strong | FileCheck %s --check-prefix=STRONG-YAML94 95# STRONG-BIND:      Bind table:96# STRONG-BIND-NEXT: segment       section          address         type       addend dylib   symbol97# STRONG-BIND-DAG:  __DATA        __data           0x{{[0-9a-f]+}} pointer         0 libfoo  _foo{{$}}98# STRONG-BIND-DAG:  __DATA        __data           0x{{[0-9a-f]+}} pointer         0 libfoo  _foo{{$}}99# STRONG-BIND-DAG:  __DATA_CONST  __got            0x{{[0-9a-f]+}} pointer         0 libfoo  _foo{{$}}100# STRONG-BIND-DAG:  __DATA        __thread_ptrs    0x{{[0-9a-f]+}} pointer         0 libfoo  _foo_tlv{{$}}101# STRONG-BIND-DAG:  __DATA        __data           0x{{[0-9a-f]+}} pointer         0 libfoo  _weak_foo{{$}}102# STRONG-BIND-DAG:  __DATA        __data           0x{{[0-9a-f]+}} pointer         0 libfoo  _weak_foo{{$}}103# STRONG-BIND-DAG:  __DATA        __la_symbol_ptr  0x{{[0-9a-f]+}} pointer         0 libfoo  _weak_foo_fn{{$}}104 105# STRONG-CHAINED:      dyld information:106# STRONG-CHAINED-NEXT: segment      section      address pointer type  addend dylib   symbol/vm address107# STRONG-CHAINED-DAG:  __DATA_CONST __got            {{.*}}      bind  0x0    weak    _weak_foo_fn{{$}}108# STRONG-CHAINED-DAG:  __DATA_CONST __got            {{.*}}      bind  0x0    libfoo  _foo_fn{{$}}109# STRONG-CHAINED-DAG:  __DATA_CONST __got            {{.*}}      bind  0x0    libfoo  _foo{{$}}110# STRONG-CHAINED-DAG:  __DATA       __data           {{.*}}      bind  0x0    libfoo  _foo{{$}}111# STRONG-CHAINED-DAG:  __DATA       __data           {{.*}}      bind  0x0    libfoo  _foo{{$}}112# STRONG-CHAINED-DAG:  __DATA       __data           {{.*}}      bind  0x0    weak    _weak_foo{{$}}113# STRONG-CHAINED-DAG:  __DATA       __data           {{.*}}      bind  0x0    weak    _weak_foo{{$}}114# STRONG-CHAINED-DAG:  __DATA       __thread_ptrs    {{.*}}      bind  0x0    libfoo  _foo_tlv{{$}}115 116# STRONG-YAML-LABEL: WeakBindOpcodes:117# STRONG-YAML:        - Opcode:          BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM118# STRONG-YAML-NEXT:     Imm:             0119# STRONG-YAML-NEXT:     Symbol:          _weak_foo_fn120# STRONG-YAML:        - Opcode:          BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM121# STRONG-YAML-NEXT:     Imm:             0122# STRONG-YAML-NEXT:     Symbol:          _weak_foo123# STRONG-YAML-LABEL: LazyBindOpcodes:124# STRONG-YAML:        - Opcode:          BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM125# STRONG-YAML-NEXT:     Imm:             0126# STRONG-YAML-NEXT:     Symbol:          _foo_fn127 128## Weak references must still be satisfied at link time.129# RUN: not %lld -lSystem %t/invalid.o -o /dev/null 2>&1 | FileCheck %s \130# RUN:   --check-prefix=INVALID -DDIR=%t131# INVALID: error: undefined symbol: _missing132 133#--- libfoo.s134.globl _foo, _foo_fn, _weak_foo, _weak_foo_fn135.weak_definition _weak_foo, _weak_foo_fn136_foo:137_foo_fn:138_weak_foo:139_weak_foo_fn:140 141.section __DATA,__thread_vars,thread_local_variables142.globl _foo_tlv143_foo_tlv:144 145#--- test.s146.globl _main147.weak_reference _foo_fn, _foo, _weak_foo, _weak_foo_fn, _foo_tlv148 149_main:150  mov _foo@GOTPCREL(%rip), %rax151  mov _foo_tlv@TLVP(%rip), %rax152  callq _foo_fn153  callq _weak_foo_fn154  ret155 156.data157  .quad _foo158  .quad _weak_foo159 160#--- strongref.s161.globl _strongref162_strongref:163  mov _foo@GOTPCREL(%rip), %rax164  mov _foo_tlv@TLVP(%rip), %rax165  callq _foo_fn166  callq _weak_foo_fn167  ret168 169.data170  .quad _foo171  .quad _weak_foo172 173#--- invalid.s174.globl _main175.weak_reference _missing176_main:177  callq _missing178  ret179