[lld] cafed6f - [lld-macho][nfc] Fix test to reflect that symbol attributes don't matter within an archive

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 23 08:49:17 PDT 2021


Author: Jez Ng
Date: 2021-07-23T11:49:00-04:00
New Revision: cafed6f2923c63410450e80fc8cf1bbc8b63d708

URL: https://github.com/llvm/llvm-project/commit/cafed6f2923c63410450e80fc8cf1bbc8b63d708
DIFF: https://github.com/llvm/llvm-project/commit/cafed6f2923c63410450e80fc8cf1bbc8b63d708.diff

LOG: [lld-macho][nfc] Fix test to reflect that symbol attributes don't matter within an archive

We had a comment that claimed that defined symbols had priority
over common symbols if they occurred in the same archive. In fact, they
appear to have equal precedence. Our implementation already does this,
so I'm just updating the test comment. Also added a few other test
comments along the way for readability.

Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D106595

Added: 
    

Modified: 
    lld/test/MachO/common-symbol-resolution.s
    lld/test/MachO/weak-definition-direct-fetch.s

Removed: 
    


################################################################################
diff  --git a/lld/test/MachO/common-symbol-resolution.s b/lld/test/MachO/common-symbol-resolution.s
index 1dc015816da4..f1d7da4d702a 100644
--- 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
index 5911b9d1a9b8..48f101a18016 100644
--- 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 
diff erent 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


        


More information about the llvm-commits mailing list