diff --git a/lld/test/MachO/common-symbol-resolution.s b/lld/test/MachO/common-symbol-resolution.s --- a/lld/test/MachO/common-symbol-resolution.s +++ b/lld/test/MachO/common-symbol-resolution.s @@ -13,6 +13,7 @@ # RUN: llvm-ar rcs %t/defined.a %t/defined.o # RUN: llvm-ar rcs %t/weak-defined-and-common.a %t/weak-defined.o %t/common.o +# RUN: llvm-ar rcs %t/common-and-weak-defined.a %t/common.o %t/weak-defined.o ## The weak attribute appears to have no effect on common symbols. Given two ## common symbols of the same name, we always pick the one with the larger size, @@ -41,12 +42,11 @@ # RUN: %lld -lSystem -order_file %t/order %t/weak-common.o %t/defined.a %t/test.o -o %t/test # RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON -## If an archive has both a common and a defined symbol, the defined one should -## win. +## Defined symbols have the same precedence as common symbols within an archive. # RUN: %lld -lSystem -order_file %t/order %t/weak-defined-and-common.a %t/calls-foo.o -o %t/calls-foo # RUN: llvm-objdump --syms %t/calls-foo | FileCheck %s --check-prefix=WEAK-DEFINED -# RUN: %lld -lSystem -order_file %t/order %t/calls-foo.o %t/weak-defined-and-common.a -o %t/calls-foo -# RUN: llvm-objdump --syms %t/calls-foo | FileCheck %s --check-prefix=WEAK-DEFINED +# RUN: %lld -lSystem -order_file %t/order %t/calls-foo.o %t/common-and-weak-defined.a -o %t/calls-foo +# RUN: llvm-objdump --syms %t/calls-foo | FileCheck %s --check-prefix=COMMON ## Common symbols take precedence over dylib symbols. # RUN: %lld -lSystem -order_file %t/order %t/libfoo.dylib %t/weak-common.o %t/test.o -o %t/test @@ -54,14 +54,11 @@ # RUN: %lld -lSystem -order_file %t/order %t/weak-common.o %t/libfoo.dylib %t/test.o -o %t/test # RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON -# LARGER-COMMON-LABEL: SYMBOL TABLE: # LARGER-COMMON-DAG: [[#%x, FOO_ADDR:]] g O __DATA,__common _foo # LARGER-COMMON-DAG: [[#FOO_ADDR + 2]] g O __DATA,__common _foo_end -# DEFINED-LABEL: SYMBOL TABLE: +# COMMON: g O __DATA,__common _foo # DEFINED: g F __TEXT,__text _foo - -# WEAK-DEFINED-LABEL: SYMBOL TABLE: # WEAK-DEFINED: w F __TEXT,__text _foo #--- order diff --git a/lld/test/MachO/weak-definition-direct-fetch.s b/lld/test/MachO/weak-definition-direct-fetch.s --- a/lld/test/MachO/weak-definition-direct-fetch.s +++ b/lld/test/MachO/weak-definition-direct-fetch.s @@ -57,26 +57,31 @@ ## The remaining lines test symbol pairs of different types. +## (Weak) archive symbols take precedence over weak dylib symbols. # RUN: %lld -lSystem -o %t/weak-dylib-weak-ar -L%t -lweakfoo %t/weakfoo.a %t/test.o # RUN: llvm-objdump --macho --lazy-bind --syms %t/weak-dylib-weak-ar | FileCheck %s --check-prefix=PREFER-WEAK-OBJECT # RUN: %lld -lSystem -o %t/weak-ar-weak-dylib -L%t %t/weakfoo.a -lweakfoo %t/test.o # RUN: llvm-objdump --macho --lazy-bind --syms %t/weak-ar-weak-dylib | FileCheck %s --check-prefix=PREFER-WEAK-OBJECT +## (Weak) archive symbols have the same precedence as dylib symbols. # RUN: %lld -lSystem -o %t/weak-ar-nonweak-dylib -L%t %t/weakfoo.a -lfoo %t/test.o # RUN: llvm-objdump --macho --lazy-bind --syms %t/weak-ar-nonweak-dylib | FileCheck %s --check-prefix=PREFER-WEAK-OBJECT # RUN: %lld -lSystem -o %t/nonweak-dylib-weak-ar -L%t -lfoo %t/weakfoo.a %t/test.o # RUN: llvm-objdump --macho --lazy-bind --syms %t/nonweak-dylib-weak-ar | FileCheck %s --check-prefix=PREFER-NONWEAK-DYLIB +## Weak defined symbols take precedence over weak dylib symbols. # RUN: %lld -lSystem -o %t/weak-dylib-weak-obj -L%t -lweakfoo %t/weakfoo.o %t/test.o # RUN: llvm-objdump --macho --lazy-bind --syms %t/weak-dylib-weak-obj | FileCheck %s --check-prefix=PREFER-WEAK-OBJECT # RUN: %lld -lSystem -o %t/weak-obj-weak-dylib -L%t %t/weakfoo.o -lweakfoo %t/test.o # RUN: llvm-objdump --macho --lazy-bind --syms %t/weak-obj-weak-dylib | FileCheck %s --check-prefix=PREFER-WEAK-OBJECT +## Weak defined symbols take precedence over dylib symbols. # RUN: %lld -lSystem -o %t/weak-obj-nonweak-dylib -L%t %t/weakfoo.o -lfoo %t/test.o # RUN: llvm-objdump --macho --lazy-bind --syms %t/weak-obj-nonweak-dylib | FileCheck %s --check-prefix=PREFER-WEAK-OBJECT # RUN: %lld -lSystem -o %t/nonweak-dylib-weak-obj -L%t -lfoo %t/weakfoo.o %t/test.o # RUN: llvm-objdump --macho --lazy-bind --syms %t/nonweak-dylib-weak-obj | FileCheck %s --check-prefix=PREFER-WEAK-OBJECT +## Weak defined symbols take precedence over archive symbols. # RUN: %lld -lSystem -o %t/weak-obj-nonweak-ar %t/weakfoo.o %t/foo.a %t/test.o # RUN: llvm-objdump --macho --lazy-bind --syms %t/weak-obj-nonweak-ar | FileCheck %s --check-prefix=PREFER-WEAK-OBJECT # RUN: %lld -lSystem -o %t/nonweak-ar-weak-obj %t/foo.a %t/weakfoo.o %t/test.o