Skip to content

Commit eeb7b3d

Browse files
authored
Merge pull request swiftlang#31955 from compnerd/weak-link
test: add a test to prevent weak symbol leakage
2 parents 7c5a5e5 + 017d99d commit eeb7b3d

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Ensure that we do not export any weak symbols from the dylibs.
2+
//
3+
// Weak symbols require additional work from the loader to resolve the symbol at
4+
// load time and can cause ODR violations as well as unexpected symbol
5+
// satisfaction because the weak symbol may be used from a separate module.
6+
7+
// RUN: %empty-directory(%t)
8+
9+
// RUN: %llvm-nm --defined-only --extern-only --demangle %platform-dylib-dir/%target-library-name(swiftCore) > %t/swiftCore-all.txt
10+
// RUN: %llvm-nm --defined-only --extern-only --no-weak --demangle %platform-dylib-dir/%target-library-name(swiftCore) > %t/swiftCore-no-weak.txt
11+
// RUN: diff -u %t/swiftCore-all.txt %t/swiftCore-no-weak.txt
12+
13+
// RUN: %llvm-nm --defined-only --extern-only --demangle %platform-dylib-dir/%target-library-name(swiftRemoteMirror) > %t/swiftRemoteMirror-all.txt
14+
// RUN: %llvm-nm --defined-only --extern-only --no-weak --demangle %platform-dylib-dir/%target-library-name(swiftRemoteMirror) > %t/swiftRemoteMirror-no-weak.txt
15+
// RUN: diff -u %t/swiftRemoteMirror-all.txt %t/swiftRemoteMirror-no-weak.txt
16+
17+
// NOTE: swiftDemanging is not checked because it is incorportated into
18+
// swiftCore and swiftRemoteMirror. Both of those checks ensure that the
19+
// symbols are handled properly.
20+
21+
// REQUIRES: VENDOR=apple
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Ensure that we do not export any weak symbols from the dylibs.
2+
//
3+
// Weak symbols require additional work from the loader to resolve the symbol at
4+
// load time and can cause ODR violations as well as unexpected symbol
5+
// satisfaction because the weak symbol may be used from a separate module.
6+
7+
// NOTE: this test is fragile. It is dependent on the specifics of the GNU C++
8+
// runtime. The C++ headers from the runtime explicitly force the weak symbols
9+
// to be publicly visible without allowing the user to control the visibility.
10+
// We explicitly filter out the ones that we see being leaked after manually
11+
// validating that they are being leaked because of the forceful nature of
12+
// libstdc++.
13+
14+
// RUN: %empty-directory(%t)
15+
16+
// RUN: %llvm-nm --defined-only --extern-only %platform-dylib-dir/%target-library-name(swiftCore) \
17+
// RUN: | grep -v -e _ZNSt6vectorIjSaIjEE6insertEN9__gnu_cxx17__normal_iteratorIPKjS1_EERS4_ \
18+
// RUN: -e _ZNSt6vectorIjSaIjEE13_M_insert_auxIJRKjEEEvN9__gnu_cxx17__normal_iteratorIPjS1_EEDpOT_ \
19+
// RUN: -e _ZNSt6vectorIjSaIjEE13_M_insert_auxIJjEEEvN9__gnu_cxx17__normal_iteratorIPjS1_EEDpOT_ \
20+
// RUN: -e _ZNSt6vectorISt10unique_ptrIKvSt8functionIFvPS1_EEESaIS6_EE19_M_emplace_back_auxIJS6_EEEvDpOT_ \
21+
// RUN: -e _ZNSt6vectorISt10unique_ptrIKvSt8functionIFvPS1_EEESaIS6_EE17_M_realloc_insertIJS6_EEEvN9__gnu_cxx17__normal_iteratorIPS6_S8_EEDpOT_ \
22+
// RUN: -e _ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z \
23+
// RUN: -e _ZZNSt19_Sp_make_shared_tag5_S_tiEvE5__tag \
24+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEDnEEEvv \
25+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEPA1_cEEEvv \
26+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEPA8_cEEEvv \
27+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEPA24_cEEEvv \
28+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEPA32_cEEEvv \
29+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEPA40_cEEEvv \
30+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEPA88_cEEEvv \
31+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEPA104_cEEEvv \
32+
// RUN: > %t/swiftCore-all.txt
33+
// RUN: %llvm-nm --defined-only --extern-only --no-weak %platform-dylib-dir/%target-library-name(swiftCore) > %t/swiftCore-no-weak.txt
34+
// RUN: diff -u %t/swiftCore-all.txt %t/swiftCore-no-weak.txt
35+
36+
// RUN: %llvm-nm --defined-only --extern-only %platform-dylib-dir/%target-library-name(swiftRemoteMirror) \
37+
// RUN: | grep -v -e _ZNSt6vectorIjSaIjEE6insertEN9__gnu_cxx17__normal_iteratorIPKjS1_EERS4_ \
38+
// RUN: -e _ZNSt6vectorIjSaIjEE13_M_insert_auxIJRKjEEEvN9__gnu_cxx17__normal_iteratorIPjS1_EEDpOT_ \
39+
// RUN: -e _ZNSt6vectorIjSaIjEE13_M_insert_auxIJjEEEvN9__gnu_cxx17__normal_iteratorIPjS1_EEDpOT_ \
40+
// RUN: -e _ZNSt6vectorISt10unique_ptrIKvSt8functionIFvPS1_EEESaIS6_EE19_M_emplace_back_auxIJS6_EEEvDpOT_ \
41+
// RUN: -e _ZNSt6vectorISt10unique_ptrIKvSt8functionIFvPS1_EEESaIS6_EE17_M_realloc_insertIJS6_EEEvN9__gnu_cxx17__normal_iteratorIPS6_S8_EEDpOT_ \
42+
// RUN: -e _ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z \
43+
// RUN: -e _ZZNSt19_Sp_make_shared_tag5_S_tiEvE5__tag \
44+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEDnEEEvv \
45+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEPA1_cEEEvv \
46+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEPA8_cEEEvv \
47+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEPA24_cEEEvv \
48+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEPA32_cEEEvv \
49+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEPA40_cEEEvv \
50+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEPA88_cEEEvv \
51+
// RUN: -e _ZSt16__once_call_implISt12_Bind_simpleIFPFvPvEPA104_cEEEvv \
52+
// RUN: > %t/swiftRemoteMirror-all.txt
53+
// RUN: %llvm-nm --defined-only --extern-only --no-weak %platform-dylib-dir/%target-library-name(swiftRemoteMirror) > %t/swiftRemoteMirror-no-weak.txt
54+
// RUN: diff -u %t/swiftRemoteMirror-all.txt %t/swiftRemoteMirror-no-weak.txt
55+
56+
// NOTE: swiftDemanging is not checked because it is incorportated into
57+
// swiftCore and swiftRemoteMirror. Both of those checks ensure that the
58+
// symbols are handled properly.
59+
60+
// REQUIRES: OS=linux-gnu

0 commit comments

Comments
 (0)