1#!/bin/sh 2# 3# 4# Our current make(1)-based approach to dependency tracking cannot cope with 5# certain source tree changes, including: 6# 7# - removing source files 8# - replacing generated files with files committed to the tree 9# - changing file extensions (e.g. a C source file rewritten in C++) 10# - moving a file from one directory to another 11# 12# Note that changing extensions or moving files may occur in effect as a result 13# of switching from a generic machine-independent (MI) implementation file to a 14# machine-dependent (MD) one. 15# 16# We handle those cases here in an ad-hoc fashion by looking for the known- 17# bad case in the main .depend file, and if found deleting all of the related 18# .depend files (including for example the lib32 version). 19# 20# These tests increase the build time (albeit by a small amount), so they 21# should be removed once enough time has passed and it is extremely unlikely 22# anyone would try a NO_CLEAN build against an object tree from before the 23# related change. One year should be sufficient. 24# 25# Groups of cleanup rules begin with a comment including the date and git hash 26# of the affected commit, and a description. The clean_dep function (below) 27# handles common dependency cleanup cases. See the comment above the function 28# for its arguments. 29# 30# Examples of each of the special cases: 31# 32# - Removing a source file (including changing a file's extension). The path, 33# file, and extension are passed to clean_dep. 34# 35# # 20231031 0527c9bdc718 Remove forward compat ino64 stuff 36# clean_dep lib/libc fstat c 37# 38# # 20221115 42d10b1b56f2 move from rs.c to rs.cc 39# clean_dep usr.bin/rs rs c 40# 41# - Moving a file from one directory to another. Note that a regex is passed to 42# clean_dep, as the default regex is derived from the file name (strncat.c in 43# this example) does not change. The regex matches the old location, does not 44# match the new location, and does not match any dependency shared between 45# them. The `/`s are replaced with `.` to avoid awkward escaping. 46# 47# # 20250110 3dc5429158cf add strncat SIMD implementation 48# clean_dep lib/libc strncat c "libc.string.strncat.c" 49# 50# - Replacing generated files with files committed to the tree. This is special 51# case of moving from one directory to another. The stale generated file also 52# needs to be deleted, so that it isn't found in make's .PATH. Note the 53# unconditional `rm -f`: there's no need for an extra call to first check for 54# the file's existence. 55# 56# # 20250110 3863fec1ce2d add strlen SIMD implementation 57# clean_dep lib/libc strlen S arm-optimized-routines 58# run rm -f "$OBJTOP"/lib/libc/strlen.S 59# 60# A rule may be required for only one architecture: 61# 62# # 20220326 fbc002cb72d2 move from bcmp.c to bcmp.S 63# if [ "$MACHINE_ARCH" = "amd64" ]; then 64# clean_dep lib/libc bcmp c 65# fi 66 67set -e 68set -u 69 70warn() 71{ 72 echo "$(basename "$0"):" "$@" >&2 73} 74 75err() 76{ 77 warn "$@" 78 exit 1 79} 80 81usage() 82{ 83 echo "usage: $(basename $0) [-v] [-n] objtop" >&2 84} 85 86VERBOSE= 87PRETEND= 88while getopts vn o; do 89 case "$o" in 90 v) 91 VERBOSE=1 92 ;; 93 n) 94 PRETEND=1 95 ;; 96 *) 97 usage 98 exit 1 99 ;; 100 esac 101done 102shift $((OPTIND-1)) 103 104if [ $# -ne 1 ]; then 105 usage 106 exit 1 107fi 108 109OBJTOP=$1 110shift 111if [ ! -d "$OBJTOP" ]; then 112 err "$OBJTOP: Not a directory" 113fi 114 115if [ -z "${MACHINE+set}" ]; then 116 err "MACHINE not set" 117fi 118 119if [ -z "${MACHINE_ARCH+set}" ]; then 120 err "MACHINE_ARCH not set" 121fi 122 123if [ -z "${ALL_libcompats+set}" ]; then 124 err "ALL_libcompats not set" 125fi 126 127run() 128{ 129 if [ "$VERBOSE" ]; then 130 echo "$@" 131 fi 132 if ! [ "$PRETEND" ]; then 133 "$@" 134 fi 135} 136 137# $1 directory 138# $2 source filename w/o extension 139# $3 source extension 140# $4 optional regex for egrep -w 141clean_dep() 142{ 143 for libcompat in "" $ALL_libcompats; do 144 dirprfx=${libcompat:+obj-lib${libcompat}/} 145 if egrep -qw "${4:-$2\.$3}" "$OBJTOP"/$dirprfx$1/.depend.$2.*o 2>/dev/null; then 146 echo "Removing stale ${libcompat:+lib${libcompat} }dependencies and objects for $2.$3" 147 run rm -f \ 148 "$OBJTOP"/$dirprfx$1/.depend.$2.* \ 149 "$OBJTOP"/$dirprfx$1/$2.*o 150 fi 151 done 152} 153 154# Date Rev Description 155 156# 20220326 fbc002cb72d2 move from bcmp.c to bcmp.S 157if [ "$MACHINE_ARCH" = "amd64" ]; then 158 clean_dep lib/libc bcmp c 159fi 160 161# 20220524 68fe988a40ca kqueue_test binary replaced shell script 162if stat "$OBJTOP"/tests/sys/kqueue/libkqueue/*kqtest* \ 163 "$OBJTOP"/tests/sys/kqueue/libkqueue/.depend.kqtest* >/dev/null 2>&1; then 164 echo "Removing old kqtest" 165 run rm -f "$OBJTOP"/tests/sys/kqueue/libkqueue/.depend.* \ 166 "$OBJTOP"/tests/sys/kqueue/libkqueue/* 167fi 168 169# 20221115 42d10b1b56f2 move from rs.c to rs.cc 170clean_dep usr.bin/rs rs c 171 172# 20230110 bc42155199b5 usr.sbin/zic/zic -> usr.sbin/zic 173if [ -d "$OBJTOP"/usr.sbin/zic/zic ] ; then 174 echo "Removing old zic directory" 175 run rm -rf "$OBJTOP"/usr.sbin/zic/zic 176fi 177 178# 20230208 29c5f8bf9a01 move from mkmakefile.c to mkmakefile.cc 179clean_dep usr.sbin/config mkmakefile c 180# 20230209 83d7ed8af3d9 convert to main.cc and mkoptions.cc 181clean_dep usr.sbin/config main c 182clean_dep usr.sbin/config mkoptions c 183 184# 20230401 54579376c05e kqueue1 from syscall to C wrapper 185clean_dep lib/libc kqueue1 S 186 187# 20230623 b077aed33b7b OpenSSL 3.0 update 188if [ -f "$OBJTOP"/secure/lib/libcrypto/aria.o ]; then 189 echo "Removing old OpenSSL 1.1.1 tree" 190 for libcompat in "" $ALL_libcompats; do 191 dirprfx=${libcompat:+obj-lib${libcompat}/} 192 run rm -rf "$OBJTOP"/${dirprfx}secure/lib/libcrypto \ 193 "$OBJTOP"/${dirprfx}secure/lib/libssl 194 done 195fi 196 197# 20230714 ee8b0c436d72 replace ffs/fls implementations with clang builtins 198clean_dep lib/libc ffs S 199clean_dep lib/libc ffsl S 200clean_dep lib/libc ffsll S 201clean_dep lib/libc fls S 202clean_dep lib/libc flsl S 203clean_dep lib/libc flsll S 204 205# 20230815 28f6c2f29280 GoogleTest update 206if [ -e "$OBJTOP"/tests/sys/fs/fusefs/mockfs.o ] && \ 207 grep -q '_ZN7testing8internal18g_linked_ptr_mutexE' "$OBJTOP"/tests/sys/fs/fusefs/mockfs.o; then 208 echo "Removing stale fusefs GoogleTest objects" 209 run rm -rf "$OBJTOP"/tests/sys/fs/fusefs 210fi 211 212# 20231031 0527c9bdc718 Remove forward compat ino64 stuff 213clean_dep lib/libc fstat c 214clean_dep lib/libc fstatat c 215clean_dep lib/libc fstatfs c 216clean_dep lib/libc getdirentries c 217clean_dep lib/libc getfsstat c 218clean_dep lib/libc statfs c 219 220# 20240308 e6ffc7669a56 Remove pointless MD syscall(2) 221# 20240308 0ee0ae237324 Remove pointless MD syscall(2) 222# 20240308 7b3836c28188 Remove pointless MD syscall(2) 223if [ ${MACHINE} != i386 ]; then 224 libcompats= 225 for libcompat in $ALL_libcompats; do 226 if [ $MACHINE = amd64 ] && [ $libcompat = 32 ]; then 227 continue 228 fi 229 libcompats="${libcompats+$libcompats }$libcompat" 230 done 231 ALL_libcompats="$libcompats" clean_dep lib/libsys syscall S ".*/syscall\.S" 232 ALL_libcompats="$libcompats" clean_dep lib/libc syscall S ".*/syscall\.S" 233fi 234 235# 20240416 2fda3ab0ac19 WITH_NVME: Remove from broken 236if [ -f "$OBJTOP"/rescue/rescue/rescue.mk ] && \ 237 ! grep -q 'nvme_util.o' "$OBJTOP"/rescue/rescue/rescue.mk; then 238 echo "removing rescue.mk without nvme_util.o" 239 run rm -f "$OBJTOP"/rescue/rescue/rescue.mk 240fi 241 242# 20240910 e2df9bb44109 243clean_dep cddl/lib/libzpool abd_os c "linux/zfs/abd_os\.c" 244 245# 20241007 246clean_dep cddl/lib/libzpool zfs_debug c "linux/zfs/zfs_debug\.c" 247 248# 20241011 249clean_dep cddl/lib/libzpool arc_os c "linux/zfs/arc_os\.c" 250 251# 20241018 1363acbf25de libc/csu: Support IFUNCs on riscv 252if [ ${MACHINE} = riscv ]; then 253 for f in "$OBJTOP"/lib/libc/.depend.libc_start1.*o; do 254 if [ ! -f "$f" ]; then 255 continue 256 fi 257 if ! grep -q 'lib/libc/csu/riscv/reloc\.c' "$f"; then 258 echo "Removing stale dependencies and objects for libc_start1.c" 259 run rm -f \ 260 "$OBJTOP"/lib/libc/.depend.libc_start1.* \ 261 "$OBJTOP"/lib/libc/libc_start1.*o 262 break 263 fi 264 done 265fi 266 267# 20241018 5deeebd8c6ca Merge llvm-project release/19.x llvmorg-19.1.2-0-g7ba7d8e2f7b6 268p="$OBJTOP"/lib/clang/libclang/clang/Basic 269f="$p"/arm_mve_builtin_sema.inc 270if [ -e "$f" ]; then 271 if grep -q SemaBuiltinConstantArgRange "$f"; then 272 echo "Removing pre-llvm19 clang-tblgen output" 273 run rm -f "$p"/*.inc 274 fi 275fi 276 277# 20241025 cb5e41b16083 Unbundle hash functions fom lib/libcrypt 278clean_dep lib/libcrypt crypt-md5 c 279clean_dep lib/libcrypt crypt-nthash c 280clean_dep lib/libcrypt crypt-sha256 c 281clean_dep lib/libcrypt crypt-sha512 c 282 283# 20241213 b55f5e1c4ae3 jemalloc: Move generated jemalloc.3 into lib/libc tree 284if [ -h "$OBJTOP"/lib/libc/jemalloc.3 ]; then 285 # Have to cleanup the jemalloc.3 in the obj tree since make gets 286 # confused and won't use the one in lib/libc/malloc/jemalloc/jemalloc.3 287 echo "Removing stale jemalloc.3 object" 288 run rm -f "$OBJTOP"/lib/libc/jemalloc.3 289fi 290 291if [ $MACHINE_ARCH = aarch64 ]; then 292 # 20250110 5e7d93a60440 add strcmp SIMD implementation 293 ALL_libcompats= clean_dep lib/libc strcmp S arm-optimized-routines 294 run rm -f "$OBJTOP"/lib/libc/strcmp.S 295 296 # 20250110 b91003acffe7 add strspn optimized implementation 297 ALL_libcompats= clean_dep lib/libc strspn c 298 299 # 20250110 f2bd390a54f1 add strcspn optimized implementation 300 ALL_libcompats= clean_dep lib/libc strcspn c 301 302 # 20250110 89b3872376cb add optimized strpbrk & strsep implementations 303 ALL_libcompats= clean_dep lib/libc strpbrk c "libc.string.strpbrk.c" 304 305 # 20250110 79287d783c72 strcat enable use of SIMD 306 ALL_libcompats= clean_dep lib/libc strcat c "libc.string.strcat.c" 307 308 # 20250110 756b7fc80837 add strlcpy SIMD implementation 309 ALL_libcompats= clean_dep lib/libc strlcpy c 310 311 # 20250110 25c485e14769 add strncmp SIMD implementation 312 ALL_libcompats= clean_dep lib/libc strncmp S arm-optimized-routines 313 run rm -f "$OBJTOP"/lib/libc/strncmp.S 314 315 # 20250110 bad17991c06d add memccpy SIMD implementation 316 ALL_libcompats= clean_dep lib/libc memccpy c 317 318 # 20250110 3dc5429158cf add strncat SIMD implementation 319 ALL_libcompats= clean_dep lib/libc strncat c "libc.string.strncat.c" 320 321 # 20250110 bea89d038ac5 add strlcat SIMD implementation, and move memchr 322 ALL_libcompats= clean_dep lib/libc strlcat c "libc.string.strlcat.c" 323 ALL_libcompats= clean_dep lib/libc memchr S "[[:space:]]memchr.S" 324 run rm -f "$OBJTOP"/lib/libc/memchr.S 325 326 # 20250110 3863fec1ce2d add strlen SIMD implementation 327 ALL_libcompats= clean_dep lib/libc strlen S arm-optimized-routines 328 run rm -f "$OBJTOP"/lib/libc/strlen.S 329 330 # 20250110 79e01e7e643c add bcopy & bzero wrapper 331 ALL_libcompats= clean_dep lib/libc bcopy c "libc.string.bcopy.c" 332 ALL_libcompats= clean_dep lib/libc bzero c "libc.string.bzero.c" 333 334 # 20250110 f2c98669fc1b add ASIMD-enhanced timingsafe_bcmp implementation 335 ALL_libcompats= clean_dep lib/libc timingsafe_bcmp c 336 337 # 20250110 3f224333af16 add timingsafe_memcmp() assembly implementation 338 ALL_libcompats= clean_dep lib/libc timingsafe_memcmp c 339fi 340 341# 20250402 839d0755fea8 ctld converted to C++ 342clean_dep usr.sbin/ctld ctld c 343clean_dep usr.sbin/ctld conf c 344clean_dep usr.sbin/ctld discovery c 345clean_dep usr.sbin/ctld isns c 346clean_dep usr.sbin/ctld kernel c 347clean_dep usr.sbin/ctld login c 348clean_dep usr.sbin/ctld uclparse c 349 350# 20250425 2e47f35be5dc libllvm, libclang and liblldb became shared libraries 351if [ -f "$OBJTOP"/lib/clang/libllvm/libllvm.a ]; then 352 echo "Removing old static libllvm library" 353 run rm -f "$OBJTOP"/lib/clang/libllvm/libllvm.a 354fi 355if [ -f "$OBJTOP"/lib/clang/libclang/libclang.a ]; then 356 echo "Removing old static libclang library" 357 run rm -f "$OBJTOP"/lib/clang/libclang/libclang.a 358fi 359if [ -f "$OBJTOP"/lib/clang/liblldb/liblldb.a ]; then 360 echo "Removing old static liblldb library" 361 run rm -f "$OBJTOP"/lib/clang/liblldb/liblldb.a 362fi 363