137 lines · plain
1# REQUIRES: x862# RUN: rm -rf %t; split-file %s %t3# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/aliases.s -o %t/aliases.o4# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/definitions.s -o %t/definitions.o5# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-extern-alias-to-weak.s -o %t/weak-extern-alias-to-weak.o6# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-extern-alias-to-strong.s -o %t/weak-extern-alias-to-strong.o7 8# RUN: %lld -lSystem %t/aliases.o %t/definitions.o -o %t/out9# RUN: llvm-objdump --macho --syms %t/out | FileCheck %s10 11## local aliases should be dropped entirely. --implicit-check-not doesn't seem12## to work well with -DAG matches, so we check for _local_alias' absence in a13## separate step.14# RUN: llvm-objdump --macho --syms %t/out | FileCheck /dev/null --implicit-check-not _local_alias15 16# CHECK-DAG: [[#%.16x,STRONG:]] g F __TEXT,__text _strong17# CHECK-DAG: [[#%.16x,WEAK_1:]] w F __TEXT,__text _weak_118# CHECK-DAG: [[#%.16x,PEXT:]] l F __TEXT,__text .hidden _pext19# CHECK-DAG: [[#%.16x,DEAD:]] g F __TEXT,__text _dead20# CHECK-DAG: [[#STRONG]] l F __TEXT,__text .hidden _pext_alias21# CHECK-DAG: [[#PEXT]] l F __TEXT,__text .hidden _alias_to_pext22# CHECK-DAG: [[#STRONG]] g F __TEXT,__text _extern_alias_to_strong23# CHECK-DAG: [[#WEAK_1]] w F __TEXT,__text _weak_extern_alias_to_weak24# CHECK-DAG: [[#DEAD]] g F __TEXT,__text _no_dead_strip_alias25# CHECK-DAG: [[#STRONG]] g F __TEXT,__text _weak_extern_alias_to_strong26 27# RUN: %lld -lSystem -dead_strip %t/aliases.o %t/definitions.o -o %t/dead-stripped28# RUN: llvm-objdump --macho --syms %t/dead-stripped | FileCheck %s --check-prefix=STRIPPED29 30# STRIPPED: SYMBOL TABLE:31# STRIPPED-NEXT: g F __TEXT,__text _main32# STRIPPED-NEXT: g F __TEXT,__text __mh_execute_header33# STRIPPED-NEXT: *UND* dyld_stub_binder34# 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>&138 39## Verify that we preserve the file names of the aliases, rather than using the40## filename of the aliased symbols.41# DUP: error: duplicate symbol: _weak_extern_alias_to_weak42# DUP-NEXT: >>> defined in {{.*}}aliases.o43# DUP-NEXT: >>> defined in {{.*}}weak-extern-alias-to-weak.o44 45## The following cases are actually all dup symbol errors under ld64. Alias46## symbols are treated like strong extern symbols by ld64 even if the symbol they alias47## is actually weak. LLD OTOH does not check for dup symbols until after48## resolving the aliases; this makes for a simpler implementation.49## The following test cases are meant to elucidate what LLD's behavior is, but50## we should feel free to change it in the future should it be helpful for the51## 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-155# RUN: llvm-objdump --macho --syms %t/alias-clash-1 | FileCheck %s --check-prefix WEAK-156 57# RUN: %lld -lSystem %t/weak-extern-alias-to-weak.o %t/aliases.o \58# RUN: %t/definitions.o -o %t/alias-clash-259# RUN: llvm-objdump --macho --syms %t/alias-clash-2 | FileCheck %s --check-prefix WEAK-260 61# RUN: %lld -lSystem %t/aliases.o %t/definitions.o \62# RUN: -alias _weak_2 _weak_extern_alias_to_weak -o %t/opt-vs-symbol63# RUN: llvm-objdump --macho --syms %t/opt-vs-symbol | FileCheck %s --check-prefix WEAK-264 65# RUN: %lld -lSystem -alias _weak_2 _weak_extern_alias_to_weak %t/aliases.o \66# RUN: %t/definitions.o -o %t/opt-vs-symbol67# RUN: llvm-objdump --macho --syms %t/opt-vs-symbol | FileCheck %s --check-prefix WEAK-268 69# WEAK-1-DAG: [[#%.16x,WEAK_1:]] w F __TEXT,__text _weak_170# WEAK-1-DAG: [[#WEAK_1]] w F __TEXT,__text _weak_extern_alias_to_weak71 72# WEAK-2-DAG: [[#%.16x,WEAK_2:]] w F __TEXT,__text _weak_273# WEAK-2-DAG: [[#WEAK_2]] w F __TEXT,__text _weak_extern_alias_to_weak74 75#--- aliases.s76.globl _extern_alias_to_strong, _weak_extern_alias_to_weak77.weak_definition _weak_extern_alias_to_weak78 79## Private extern aliases result in local symbols in the output (i.e. it is as80## if the aliased symbol is also private extern.)81.private_extern _pext_alias82 83## This test case demonstrates that it doesn't matter whether the alias itself84## is strong or weak. Rather, what matters is whether the aliased symbol is85## strong or weak.86.globl _weak_extern_alias_to_strong87.weak_definition _weak_extern_alias_to_strong88 89## no_dead_strip doesn't retain the aliased symbol if it is dead90.globl _no_dead_strip_alias91.no_dead_strip _no_dead_strip_alias92 93.globl _alias_to_pext94_alias_to_pext = _pext95 96_extern_alias_to_strong = _strong97_weak_extern_alias_to_weak = _weak_198_weak_extern_alias_to_strong = _strong99 100_pext_alias = _strong101_local_alias = _strong102_no_dead_strip_alias = _dead103 104.subsections_via_symbols105 106#--- weak-extern-alias-to-weak.s107.globl _weak_extern_alias_to_weak108.weak_definition _weak_extern_alias_to_weak109_weak_extern_alias_to_weak = _weak_2110 111#--- weak-extern-alias-to-strong.s112.globl _weak_extern_alias_to_strong113.weak_definition _weak_extern_alias_to_strong114_weak_extern_alias_to_strong = _strong115 116#--- definitions.s117.globl _strong, _weak_1, _weak_2, _dead118.private_extern _pext119.weak_definition _weak_1120.weak_definition _weak_2121 122_strong:123 .space 1124_weak_1:125 .space 1126_weak_2:127 .space 1128_dead:129 .space 1130_pext:131 .space 1132 133.globl _main134_main:135 136.subsections_via_symbols137