1# REQUIRES: x86 2# RUN: rm -rf %t; split-file %s %t 3# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/aliases.s -o %t/aliases.o 4# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/definitions.s -o %t/definitions.o 5# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-extern-alias-to-weak.s -o %t/weak-extern-alias-to-weak.o 6# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-extern-alias-to-strong.s -o %t/weak-extern-alias-to-strong.o 7 8# RUN: %lld -lSystem %t/aliases.o %t/definitions.o -o %t/out 9# RUN: llvm-objdump --macho --syms %t/out | FileCheck %s 10 11## local aliases should be dropped entirely. --implicit-check-not doesn't seem 12## to work well with -DAG matches, so we check for _local_alias' absence in a 13## separate step. 14# RUN: llvm-objdump --macho --syms %t/out | FileCheck /dev/null --implicit-check-not _local_alias 15 16# CHECK-DAG: [[#%.16x,STRONG:]] g F __TEXT,__text _strong 17# CHECK-DAG: [[#%.16x,WEAK_1:]] w F __TEXT,__text _weak_1 18# CHECK-DAG: [[#%.16x,PEXT:]] l F __TEXT,__text .hidden _pext 19# CHECK-DAG: [[#%.16x,DEAD:]] g F __TEXT,__text _dead 20# CHECK-DAG: [[#STRONG]] l F __TEXT,__text .hidden _pext_alias 21# CHECK-DAG: [[#PEXT]] l F __TEXT,__text .hidden _alias_to_pext 22# CHECK-DAG: [[#STRONG]] g F __TEXT,__text _extern_alias_to_strong 23# CHECK-DAG: [[#WEAK_1]] w F __TEXT,__text _weak_extern_alias_to_weak 24# CHECK-DAG: [[#DEAD]] g F __TEXT,__text _no_dead_strip_alias 25# CHECK-DAG: [[#STRONG]] g F __TEXT,__text _weak_extern_alias_to_strong 26 27# RUN: %lld -lSystem -dead_strip %t/aliases.o %t/definitions.o -o %t/dead-stripped 28# RUN: llvm-objdump --macho --syms %t/dead-stripped | FileCheck %s --check-prefix=STRIPPED 29 30# STRIPPED: SYMBOL TABLE: 31# STRIPPED-NEXT: g F __TEXT,__text _main 32# STRIPPED-NEXT: g F __TEXT,__text __mh_execute_header 33# STRIPPED-NEXT: *UND* dyld_stub_binder 34# STRIPPED-EMPTY: 35 36# RUN: not %lld -lSystem %t/aliases.o %t/definitions.o \ 37# RUN: %t/weak-extern-alias-to-strong.o -o /dev/null 2>&1 38 39## Verify that we preserve the file names of the aliases, rather than using the 40## filename of the aliased symbols. 41# DUP: error: duplicate symbol: _weak_extern_alias_to_weak 42# DUP-NEXT: >>> defined in {{.*}}aliases.o 43# DUP-NEXT: >>> defined in {{.*}}weak-extern-alias-to-weak.o 44 45## The following cases are actually all dup symbol errors under ld64. Alias 46## symbols are treated like strong extern symbols by ld64 even if the symbol they alias 47## is actually weak. LLD OTOH does not check for dup symbols until after 48## resolving the aliases; this makes for a simpler implementation. 49## The following test cases are meant to elucidate what LLD's behavior is, but 50## we should feel free to change it in the future should it be helpful for the 51## implementation. 52 53# RUN: %lld -lSystem %t/aliases.o %t/definitions.o \ 54# RUN: %t/weak-extern-alias-to-weak.o -o %t/alias-clash-1 55# RUN: llvm-objdump --macho --syms %t/alias-clash-1 | FileCheck %s --check-prefix WEAK-1 56 57# RUN: %lld -lSystem %t/weak-extern-alias-to-weak.o %t/aliases.o \ 58# RUN: %t/definitions.o -o %t/alias-clash-2 59# RUN: llvm-objdump --macho --syms %t/alias-clash-2 | FileCheck %s --check-prefix WEAK-2 60 61# RUN: %lld -lSystem %t/aliases.o %t/definitions.o \ 62# RUN: -alias _weak_2 _weak_extern_alias_to_weak -o %t/opt-vs-symbol 63# RUN: llvm-objdump --macho --syms %t/opt-vs-symbol | FileCheck %s --check-prefix WEAK-2 64 65# RUN: %lld -lSystem -alias _weak_2 _weak_extern_alias_to_weak %t/aliases.o \ 66# RUN: %t/definitions.o -o %t/opt-vs-symbol 67# RUN: llvm-objdump --macho --syms %t/opt-vs-symbol | FileCheck %s --check-prefix WEAK-2 68 69# WEAK-1-DAG: [[#%.16x,WEAK_1:]] w F __TEXT,__text _weak_1 70# WEAK-1-DAG: [[#WEAK_1]] w F __TEXT,__text _weak_extern_alias_to_weak 71 72# WEAK-2-DAG: [[#%.16x,WEAK_2:]] w F __TEXT,__text _weak_2 73# WEAK-2-DAG: [[#WEAK_2]] w F __TEXT,__text _weak_extern_alias_to_weak 74 75#--- aliases.s 76.globl _extern_alias_to_strong, _weak_extern_alias_to_weak 77.weak_definition _weak_extern_alias_to_weak 78 79## Private extern aliases result in local symbols in the output (i.e. it is as 80## if the aliased symbol is also private extern.) 81.private_extern _pext_alias 82 83## This test case demonstrates that it doesn't matter whether the alias itself 84## is strong or weak. Rather, what matters is whether the aliased symbol is 85## strong or weak. 86.globl _weak_extern_alias_to_strong 87.weak_definition _weak_extern_alias_to_strong 88 89## no_dead_strip doesn't retain the aliased symbol if it is dead 90.globl _no_dead_strip_alias 91.no_dead_strip _no_dead_strip_alias 92 93.globl _alias_to_pext 94_alias_to_pext = _pext 95 96_extern_alias_to_strong = _strong 97_weak_extern_alias_to_weak = _weak_1 98_weak_extern_alias_to_strong = _strong 99 100_pext_alias = _strong 101_local_alias = _strong 102_no_dead_strip_alias = _dead 103 104.subsections_via_symbols 105 106#--- weak-extern-alias-to-weak.s 107.globl _weak_extern_alias_to_weak 108.weak_definition _weak_extern_alias_to_weak 109_weak_extern_alias_to_weak = _weak_2 110 111#--- weak-extern-alias-to-strong.s 112.globl _weak_extern_alias_to_strong 113.weak_definition _weak_extern_alias_to_strong 114_weak_extern_alias_to_strong = _strong 115 116#--- definitions.s 117.globl _strong, _weak_1, _weak_2, _dead 118.private_extern _pext 119.weak_definition _weak_1 120.weak_definition _weak_2 121 122_strong: 123 .space 1 124_weak_1: 125 .space 1 126_weak_2: 127 .space 1 128_dead: 129 .space 1 130_pext: 131 .space 1 132 133.globl _main 134_main: 135 136.subsections_via_symbols 137