mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Add a codesize check of the freestanding/minimal stdlib to prevent large codesize regressions (#40653)
This commit is contained in:
committed by
GitHub
parent
2653b5b931
commit
5076af2ae4
@@ -94,6 +94,7 @@ function(get_test_dependencies SDK result_var_name)
|
||||
llvm-profdata
|
||||
llvm-readelf
|
||||
llvm-readobj
|
||||
llvm-size
|
||||
llvm-strings
|
||||
not
|
||||
split-file)
|
||||
|
||||
@@ -344,6 +344,7 @@ config.llvm_dwarfdump = inferSwiftBinary('llvm-dwarfdump')
|
||||
config.llvm_readelf = inferSwiftBinary('llvm-readelf')
|
||||
config.llvm_dis = inferSwiftBinary('llvm-dis')
|
||||
config.llvm_nm = inferSwiftBinary('llvm-nm')
|
||||
config.llvm_size = inferSwiftBinary('llvm-size')
|
||||
config.sourcekitd_test = inferSwiftBinary('sourcekitd-test')
|
||||
config.complete_test = inferSwiftBinary('complete-test')
|
||||
config.swift_api_digester = inferSwiftBinary('swift-api-digester')
|
||||
@@ -516,6 +517,7 @@ config.substitutions.append( ('%llvm-dwarfdump', config.llvm_dwarfdump) )
|
||||
config.substitutions.append( ('%llvm-readelf', config.llvm_readelf) )
|
||||
config.substitutions.append( ('%llvm-dis', config.llvm_dis) )
|
||||
config.substitutions.append( ('%llvm-nm', config.llvm_nm) )
|
||||
config.substitutions.append( ('%llvm-size', config.llvm_size) )
|
||||
config.substitutions.append( ('%swift-demangle-yamldump', config.swift_demangle_yamldump) )
|
||||
config.substitutions.append( ('%swift-demangle', config.swift_demangle) )
|
||||
config.substitutions.append( ('%Benchmark_O', config.benchmark_o) )
|
||||
|
||||
13
test/stdlib/freestanding-check-size1.swift
Normal file
13
test/stdlib/freestanding-check-size1.swift
Normal file
@@ -0,0 +1,13 @@
|
||||
// Check that we can LTO-optimize the freestanding/minimal stdlib against client usage of APIs, and that we don't produce unexpectedly large final binary.
|
||||
|
||||
// Important (!): This test is in test/stdlib/ to make sure it is actually run on the minimal/freestanding CI job, which
|
||||
// filters the set of tests to test/stdlib/ only (see build-preset.ini).
|
||||
|
||||
// REQUIRES: freestanding
|
||||
// REQUIRES: executable_test
|
||||
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-build-swift %s -o %t/a.out
|
||||
// RUN: %{python} %utils/check_freestanding_size.py --path %t/a.out --triple %module-target-triple --size-path %llvm-size
|
||||
|
||||
print("Hello world")
|
||||
16
test/stdlib/freestanding-check-size2.swift
Normal file
16
test/stdlib/freestanding-check-size2.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
// Check that we can LTO-optimize the freestanding/minimal stdlib against client usage of APIs, and that we don't produce unexpectedly large final binary.
|
||||
|
||||
// Important (!): This test is in test/stdlib/ to make sure it is actually run on the minimal/freestanding CI job, which
|
||||
// filters the set of tests to test/stdlib/ only (see build-preset.ini).
|
||||
|
||||
// REQUIRES: freestanding
|
||||
// REQUIRES: executable_test
|
||||
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-build-swift %s -o %t/a.out
|
||||
// RUN: %{python} %utils/check_freestanding_size.py --path %t/a.out --triple %module-target-triple --size-path %llvm-size
|
||||
|
||||
let array = [1, 2, 3]
|
||||
let dict = ["abc": 42]
|
||||
let s = Set([1, 3, 5])
|
||||
print("Hello \(array) \(dict) \(s)")
|
||||
@@ -1769,14 +1769,15 @@ for host in "${ALL_HOSTS[@]}"; do
|
||||
# build of Swift depend on these for building and testing.
|
||||
build_targets=(llvm-tblgen clang-resource-headers intrinsics_gen clang-tablegen-targets)
|
||||
# If we are not performing a toolchain only build, then we
|
||||
# also want to include FileCheck, not, llvm-nm for testing
|
||||
# purposes.
|
||||
# also want to include FileCheck, not, llvm-nm, and similar
|
||||
# for testing purposes.
|
||||
if [[ ! "${BUILD_TOOLCHAIN_ONLY}" ]] ; then
|
||||
build_targets=(
|
||||
"${build_targets[@]}"
|
||||
FileCheck
|
||||
not
|
||||
llvm-nm
|
||||
llvm-size
|
||||
)
|
||||
fi
|
||||
fi
|
||||
|
||||
67
utils/check_freestanding_size.py
Executable file
67
utils/check_freestanding_size.py
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# This source file is part of the Swift.org open source project
|
||||
#
|
||||
# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
# Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
#
|
||||
# See https://swift.org/LICENSE.txt for license information
|
||||
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--path", help="path to a binary to check")
|
||||
parser.add_argument("--triple", help="target triple of the freestanding stdlib")
|
||||
parser.add_argument("--size-path", help="path to llvm-size binary to use")
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# EXPECTED/ALLOWED TEXT SEGMENT SIZE
|
||||
#
|
||||
# Before bumping the maximum text segment size please consult with:
|
||||
# @kubamracek, @compnerd
|
||||
#
|
||||
# The 'freestanding' build of the Swift runtime and standard library is
|
||||
# intended to be lean and allow dead-code elimination from the standard library
|
||||
# based on client code usage.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# As of 2022-01-05: TEXT segment is 640 KiB on x86_64 Darwin, stdlib without
|
||||
# asserts. Let's allow for some minor increases (~ 15%) and cap at 740 kiB:
|
||||
|
||||
max_text_size_x86_64_apple_macos = 740 * 1024
|
||||
|
||||
################################################################################
|
||||
|
||||
|
||||
if args.triple == "x86_64-apple-macos":
|
||||
max_text_size = max_text_size_x86_64_apple_macos
|
||||
actual_text_size = 0
|
||||
|
||||
nm = args.size_path
|
||||
lines = subprocess.check_output(
|
||||
[nm, "--format=darwin", args.path]) \
|
||||
.decode("utf-8").strip().splitlines()
|
||||
for line in lines:
|
||||
if line.startswith("Segment __TEXT: "):
|
||||
actual_text_size = int(line[len("Segment __TEXT: "):])
|
||||
|
||||
if actual_text_size == 0:
|
||||
print("cannot determine TEXT segment size")
|
||||
sys.exit(1)
|
||||
|
||||
else:
|
||||
print("triple {} not handled yet".format(args.triple))
|
||||
sys.exit(1)
|
||||
|
||||
print("max_text_size: %d" % max_text_size)
|
||||
print("actual_text_size: %d" % actual_text_size)
|
||||
fail = actual_text_size > max_text_size
|
||||
|
||||
sys.exit(1 if fail else 0)
|
||||
Reference in New Issue
Block a user