Skip to content

Commit 20b3c06

Browse files
committed
Use llvm-nm and linter changes for abi script
1 parent 13f0ffb commit 20b3c06

File tree

5 files changed

+74
-50
lines changed

5 files changed

+74
-50
lines changed

test/abi/macOS/arm64/stdlib-asserts.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: nm -g --defined-only -f just-symbols %stdlib_dir/arm64/libswiftCore.dylib > %t/symbols
2+
// RUN: %llvm-nm -g --defined-only -f just-symbols %stdlib_dir/arm64/libswiftCore.dylib > %t/symbols
33
// RUN: %abi-symbol-checker %s %t/symbols
44
// RUN: diff -u %S/../../Inputs/macOS/arm64/stdlib/baseline-asserts %t/symbols
55

@@ -36,8 +36,13 @@
3636

3737
// Standard Library Symbols
3838

39+
// Swift._getRetainCount(Swift.AnyObject) -> Swift.UInt
3940
Added: _$ss15_getRetainCountySuyXlF
41+
42+
// Swift._getWeakRetainCount(Swift.AnyObject) -> Swift.UInt
4043
Added: _$ss19_getWeakRetainCountySuyXlF
44+
45+
// Swift._getUnownedRetainCount(Swift.AnyObject) -> Swift.UInt
4146
Added: _$ss22_getUnownedRetainCountySuyXlF
4247

4348
// Runtime Symbols

test/abi/macOS/arm64/stdlib.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: nm -g --defined-only -f just-symbols %stdlib_dir/arm64/libswiftCore.dylib > %t/symbols
2+
// RUN: %llvm-nm -g --defined-only -f just-symbols %stdlib_dir/arm64/libswiftCore.dylib > %t/symbols
33
// RUN: %abi-symbol-checker %s %t/symbols
44
// RUN: diff -u %S/../../Inputs/macOS/arm64/stdlib/baseline %t/symbols
55

@@ -36,8 +36,13 @@
3636

3737
// Standard Library Symbols
3838

39+
// Swift._getRetainCount(Swift.AnyObject) -> Swift.UInt
3940
Added: _$ss15_getRetainCountySuyXlF
41+
42+
// Swift._getWeakRetainCount(Swift.AnyObject) -> Swift.UInt
4043
Added: _$ss19_getWeakRetainCountySuyXlF
44+
45+
// Swift._getUnownedRetainCount(Swift.AnyObject) -> Swift.UInt
4146
Added: _$ss22_getUnownedRetainCountySuyXlF
4247

4348
// Runtime Symbols

test/abi/macOS/x86_64/stdlib-asserts.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: nm -g --defined-only -f just-symbols %stdlib_dir/x86_64/libswiftCore.dylib > %t/symbols
2+
// RUN: %llvm-nm -g --defined-only -f just-symbols %stdlib_dir/x86_64/libswiftCore.dylib > %t/symbols
33
// RUN: %abi-symbol-checker %s %t/symbols
44
// RUN: diff -u %S/../../Inputs/macOS/x86_64/stdlib/baseline-asserts %t/symbols
55

@@ -36,8 +36,13 @@
3636

3737
// Standard Library Symbols
3838

39+
// Swift._getRetainCount(Swift.AnyObject) -> Swift.UInt
3940
Added: _$ss15_getRetainCountySuyXlF
41+
42+
// Swift._getWeakRetainCount(Swift.AnyObject) -> Swift.UInt
4043
Added: _$ss19_getWeakRetainCountySuyXlF
44+
45+
// Swift._getUnownedRetainCount(Swift.AnyObject) -> Swift.UInt
4146
Added: _$ss22_getUnownedRetainCountySuyXlF
4247

4348
// Runtime Symbols

test/abi/macOS/x86_64/stdlib.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: nm -g --defined-only -f just-symbols %stdlib_dir/x86_64/libswiftCore.dylib > %t/symbols
2+
// RUN: %llvm-nm -g --defined-only -f just-symbols %stdlib_dir/x86_64/libswiftCore.dylib > %t/symbols
33
// RUN: %abi-symbol-checker %s %t/symbols
44
// RUN: diff -u %S/../../Inputs/macOS/x86_64/stdlib/baseline %t/symbols
55

@@ -36,8 +36,13 @@
3636

3737
// Standard Library Symbols
3838

39+
// Swift._getRetainCount(Swift.AnyObject) -> Swift.UInt
3940
Added: _$ss15_getRetainCountySuyXlF
41+
42+
// Swift._getWeakRetainCount(Swift.AnyObject) -> Swift.UInt
4043
Added: _$ss19_getWeakRetainCountySuyXlF
44+
45+
// Swift._getUnownedRetainCount(Swift.AnyObject) -> Swift.UInt
4146
Added: _$ss22_getUnownedRetainCountySuyXlF
4247

4348
// Runtime Symbols

utils/swift-abi-symbol-checker.py

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,76 @@
33
import argparse
44
import sys
55

6+
67
def checkSymbols(changesFile, symbolsFile):
7-
changesF = open(changesFile)
8-
# We need to write back to the temporary symbol file for diffing
9-
symbolsF = open(symbolsFile, 'r+')
8+
changesF = open(changesFile)
9+
# We need to write back to the temporary symbol file for diffing
10+
symbolsF = open(symbolsFile, 'r+')
11+
12+
changes = changesF.read()
13+
symbols = symbolsF.read().splitlines()
1014

11-
changes = changesF.read()
12-
symbols = symbolsF.read().splitlines()
15+
changesF.close()
1316

14-
changesF.close()
17+
# Get rid of lines that start with either '//' or a newline
18+
changes = [c for c in changes.splitlines() if not c.startswith('//') and c != '']
1519

16-
# Get rid of lines that start with either '//' or a newline
17-
changes = [c for c in changes.splitlines() if not c.startswith('//') and c != '']
20+
# Filter the changes for lines that start with Added
21+
additions = [a for a in changes if a.startswith('Added')]
22+
# Filter the changes for lines that start with Removed
23+
removals = [r for r in changes if r.startswith('Removed')]
1824

19-
# Filter the changes for lines that start with Added
20-
additions = [a for a in changes if a.startswith('Added')]
21-
# Filter the changes for lines that start with Removed
22-
removals = [r for r in changes if r.startswith('Removed')]
25+
# Map the additions by removing the 'Added: ' prefix to get just the symbol
26+
additions = list(map(lambda a: a.removeprefix('Added: '), additions))
27+
# Map the removals by removing the 'Removed: ' prefix to get just the symbol
28+
removals = list(map(lambda r: r.removeprefix('Removed: '), removals))
2329

24-
# Map the additions by removing the 'Added: ' prefix to get just the symbol
25-
additions = list(map(lambda a: a.removeprefix('Added: '), additions))
26-
# Map the removals by removing the 'Removed: ' prefix to get just the symbol
27-
removals = list(map(lambda r: r.removeprefix('Removed: '), removals))
30+
# Check for added symbols that are not actually in the just built dylib.
31+
notInDylib = [a for a in additions if a not in symbols]
2832

29-
# Check for added symbols that are not actually in the just built dylib.
30-
notInDylib = [a for a in additions if not a in symbols]
33+
# If there were symbols marked as 'Added' in the changes file, but they didn't
34+
# actually appear in the dylib then print those symbols out and fail.
35+
if notInDylib:
36+
for symbol in notInDylib:
37+
print(('{} was marked as \'Added\', but it was not found in the '
38+
'just built library').format(symbol))
3139

32-
# If there were symbols marked as 'Added' in the changes file, but they didn't
33-
# actually appear in the dylib then print those symbols out and fail.
34-
if notInDylib:
35-
for symbol in notInDylib:
36-
print('{} was marked as \'Added:\', but it was not found in the just built library'.format(symbol))
40+
sys.exit(-1)
3741

38-
sys.exit(-1)
42+
# Filter the built symbols for the additions because we're removing them to
43+
# get back to the baseline
44+
symbols = [s for s in symbols if s not in additions]
3945

40-
# Filter the built symbols for the additions because we're removing them to
41-
# get back to the baseline
42-
symbols = [s for s in symbols if not s in additions]
46+
# Append the removals into the symbol list to get back to the baseline
47+
symbols.extend(removals)
4348

44-
# Append the removals into the symbol list to get back to the baseline
45-
symbols.extend(removals)
49+
# Sort the end result to write back
50+
symbols.sort()
4651

47-
# Sort the end result to write back
48-
symbols.sort()
52+
# Go back to beginning of the file and purge everything
53+
symbolsF.seek(0)
54+
symbolsF.truncate()
4955

50-
# Go back to beginning of the file and purge everything
51-
symbolsF.seek(0)
52-
symbolsF.truncate()
56+
# Append a newline to each symbol (because writelines doesn't do that for us)
57+
symbols = list(map(lambda s: s + '\n', symbols))
5358

54-
# Append a newline to each symbol (because writelines doesn't do that for us)
55-
symbols = list(map(lambda s: s + '\n', symbols))
59+
# Write all of our symbols back into the symbols file
60+
symbolsF.writelines(symbols)
5661

57-
# Write all of our symbols back into the symbols file
58-
symbolsF.writelines(symbols)
62+
# Done
63+
symbolsF.close()
5964

60-
# Done
61-
symbolsF.close()
6265

6366
def main(arguments):
64-
parser = argparse.ArgumentParser(
65-
description='Change absolute install names to use @rpath')
67+
parser = argparse.ArgumentParser(
68+
description='Change absolute install names to use @rpath')
69+
70+
parser.add_argument('changes', help='the changes file')
71+
parser.add_argument('symbols', help='the symbols file')
6672

67-
parser.add_argument('changes', help='the changes file')
68-
parser.add_argument('symbols', help='the symbols file')
73+
args = parser.parse_args(arguments)
6974

70-
args = parser.parse_args(arguments)
75+
checkSymbols(args.changes, args.symbols)
7176

72-
checkSymbols(args.changes, args.symbols)
7377

7478
sys.exit(main(sys.argv[1:]))

0 commit comments

Comments
 (0)