Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame^] | 1 | From 4030e28f2c2296ba138cb5e2495202f8aec7ba32 Mon Sep 17 00:00:00 2001 |
| 2 | From: Richard Purdie <richard.purdie@linuxfoundation.org> |
| 3 | Date: Tue, 9 Mar 2021 15:21:36 +0000 |
| 4 | Subject: [PATCH 2/3] Makefile: Avoid wildcard determinism issues |
| 5 | |
| 6 | wildcard used in Makefiles preserves the order of the files on disk |
| 7 | which leads to differences in the order the binaries are linked. |
| 8 | |
| 9 | This patch tweaks the usage of wildcard to also have a sort, making |
| 10 | the binaries reproducible. A previous patch massively improved |
| 11 | the situation but wider testing showed that these other changes can |
| 12 | have an effect on some binaries, this patch avoids those issues as |
| 13 | exposed by our wider testing. |
| 14 | |
| 15 | Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> |
| 16 | Upstream-Status: Submitted [http://lists.linux.it/pipermail/ltp/2021-March/021388.html] |
| 17 | |
| 18 | --- |
| 19 | include/mk/env_post.mk | 2 +- |
| 20 | include/mk/module.mk | 2 +- |
| 21 | runtest/Makefile | 2 +- |
| 22 | scenario_groups/Makefile | 2 +- |
| 23 | testcases/commands/ldd/datafiles/Makefile | 2 +- |
| 24 | testcases/kernel/hotplug/memory_hotplug/Makefile | 3 ++- |
| 25 | testcases/kernel/io/disktest/Makefile | 2 +- |
| 26 | testcases/kernel/io/disktest/Makefile.linux | 4 ++-- |
| 27 | testcases/kernel/sched/hyperthreading/ht_affinity/Makefile | 2 +- |
| 28 | testcases/kernel/sched/hyperthreading/ht_enabled/Makefile | 2 +- |
| 29 | testcases/kernel/sched/sched_stress/Makefile | 2 +- |
| 30 | testcases/kernel/syscalls/lchown/Makefile | 2 +- |
| 31 | testcases/kernel/syscalls/migrate_pages/Makefile | 2 +- |
| 32 | testcases/kernel/syscalls/move_pages/Makefile | 2 +- |
| 33 | testcases/kernel/syscalls/utils/compat_16.mk | 2 +- |
| 34 | testcases/kernel/syscalls/utils/newer_64.mk | 2 +- |
| 35 | testcases/misc/math/float/Makefile | 2 +- |
| 36 | testcases/network/nfs/nfs_stress/nfs05_make_tree.c | 4 ++-- |
| 37 | testcases/network/nfsv4/locks/Makefile | 2 +- |
| 38 | utils/sctp/func_tests/Makefile | 2 +- |
| 39 | 20 files changed, 23 insertions(+), 22 deletions(-) |
| 40 | |
| 41 | diff --git a/include/mk/env_post.mk b/include/mk/env_post.mk |
| 42 | index d52ad9f0b..1d22f9c53 100644 |
| 43 | --- a/include/mk/env_post.mk |
| 44 | +++ b/include/mk/env_post.mk |
| 45 | @@ -47,7 +47,7 @@ LDFLAGS += -L$(top_builddir)/lib/android_libpthread |
| 46 | LDFLAGS += -L$(top_builddir)/lib/android_librt |
| 47 | endif |
| 48 | |
| 49 | -MAKE_TARGETS ?= $(notdir $(patsubst %.c,%,$(wildcard $(abs_srcdir)/*.c))) |
| 50 | +MAKE_TARGETS ?= $(notdir $(patsubst %.c,%,$(sort $(wildcard $(abs_srcdir)/*.c)))) |
| 51 | MAKE_TARGETS := $(filter-out $(FILTER_OUT_MAKE_TARGETS),$(MAKE_TARGETS)) |
| 52 | |
| 53 | # with only *.dwo, .[0-9]+.dwo can not be cleaned |
| 54 | diff --git a/include/mk/module.mk b/include/mk/module.mk |
| 55 | index 95fb8336a..6c8814b96 100644 |
| 56 | --- a/include/mk/module.mk |
| 57 | +++ b/include/mk/module.mk |
| 58 | @@ -42,7 +42,7 @@ endif |
| 59 | |
| 60 | ifneq ($(filter install clean,$(MAKECMDGOALS)),) |
| 61 | MAKE_TARGETS := $(filter-out %.ko, $(MAKE_TARGETS)) |
| 62 | -MAKE_TARGETS += $(wildcard *.ko) |
| 63 | +MAKE_TARGETS += $(sort $(wildcard *.ko)) |
| 64 | endif |
| 65 | |
| 66 | CLEAN_TARGETS += .dep_modules *.mod built-in.a |
| 67 | diff --git a/runtest/Makefile b/runtest/Makefile |
| 68 | index b7caaee06..6a1565b6a 100644 |
| 69 | --- a/runtest/Makefile |
| 70 | +++ b/runtest/Makefile |
| 71 | @@ -36,7 +36,7 @@ ifneq ($(WITH_POWER_MANAGEMENT_TESTSUITE),yes) |
| 72 | UNWANTED_FILES += power_management_tests |
| 73 | endif |
| 74 | |
| 75 | -INSTALL_TARGETS := $(filter-out $(UNWANTED_FILES),$(notdir $(patsubst $(abs_srcdir)/%,%,$(wildcard $(abs_srcdir)/*)))) |
| 76 | +INSTALL_TARGETS := $(filter-out $(UNWANTED_FILES),$(notdir $(patsubst $(abs_srcdir)/%,%,$(sort $(wildcard $(abs_srcdir)/*))))) |
| 77 | |
| 78 | MAKE_TARGETS := |
| 79 | |
| 80 | diff --git a/scenario_groups/Makefile b/scenario_groups/Makefile |
| 81 | index 2978675d9..fcbc92708 100644 |
| 82 | --- a/scenario_groups/Makefile |
| 83 | +++ b/scenario_groups/Makefile |
| 84 | @@ -31,7 +31,7 @@ UNWANTED_FILES := Makefile |
| 85 | |
| 86 | INSTALL_MODE := 00644 |
| 87 | |
| 88 | -INSTALL_TARGETS := $(filter-out $(UNWANTED_FILES),$(notdir $(patsubst $(abs_srcdir)/%,%,$(wildcard $(abs_srcdir)/*)))) |
| 89 | +INSTALL_TARGETS := $(filter-out $(UNWANTED_FILES),$(notdir $(patsubst $(abs_srcdir)/%,%,$(sort $(wildcard $(abs_srcdir)/*))))) |
| 90 | |
| 91 | MAKE_TARGETS := |
| 92 | |
| 93 | diff --git a/testcases/commands/ldd/datafiles/Makefile b/testcases/commands/ldd/datafiles/Makefile |
| 94 | index d8bcf5c06..01c352052 100644 |
| 95 | --- a/testcases/commands/ldd/datafiles/Makefile |
| 96 | +++ b/testcases/commands/ldd/datafiles/Makefile |
| 97 | @@ -21,7 +21,7 @@ CPPFLAGS += -fpic |
| 98 | |
| 99 | INSTALL_TARGETS := ldd*.so lddfile.out |
| 100 | |
| 101 | -LDD_C_FILES := $(wildcard $(abs_srcdir)/lddfile*.c) |
| 102 | +LDD_C_FILES := $(sort $(wildcard $(abs_srcdir)/lddfile*.c)) |
| 103 | LDD_SO_FILES := $(patsubst $(abs_srcdir)/%.c,%.obj.so,$(LDD_C_FILES)) |
| 104 | MAKE_TARGETS := lddfile.out |
| 105 | CLEAN_TARGETS += *.obj $(LDD_SO_FILES) |
| 106 | diff --git a/testcases/kernel/hotplug/memory_hotplug/Makefile b/testcases/kernel/hotplug/memory_hotplug/Makefile |
| 107 | index d1ba65e65..38a77a2ba 100644 |
| 108 | --- a/testcases/kernel/hotplug/memory_hotplug/Makefile |
| 109 | +++ b/testcases/kernel/hotplug/memory_hotplug/Makefile |
| 110 | @@ -31,6 +31,7 @@ LDLIBS := $(filter-out -lltp,$(LDLIBS)) |
| 111 | |
| 112 | MAKE_TARGETS := memtoy |
| 113 | |
| 114 | -memtoy: $(patsubst $(abs_srcdir)/%.c,%.o,$(wildcard $(abs_srcdir)/*.c)) |
| 115 | +memtoy: $(patsubst $(abs_srcdir)/%.c,%.o,$(sort $(wildcard $(abs_srcdir)/*.c))) |
| 116 | + |
| 117 | |
| 118 | include $(top_srcdir)/include/mk/generic_leaf_target.mk |
| 119 | diff --git a/testcases/kernel/io/disktest/Makefile b/testcases/kernel/io/disktest/Makefile |
| 120 | index d10d98434..3a3a9cbf0 100644 |
| 121 | --- a/testcases/kernel/io/disktest/Makefile |
| 122 | +++ b/testcases/kernel/io/disktest/Makefile |
| 123 | @@ -209,7 +209,7 @@ LDLIBS += -lpthread |
| 124 | |
| 125 | MAKE_TARGETS := disktest |
| 126 | |
| 127 | -OBJS := $(patsubst $(abs_srcdir)/%.c,%.o,$(wildcard $(abs_srcdir)/*.c)) |
| 128 | +OBJS := $(patsubst $(abs_srcdir)/%.c,%.o,$(sort $(wildcard $(abs_srcdir)/*.c))) |
| 129 | |
| 130 | disktest-$(VER): |
| 131 | mkdir -p "$@" |
| 132 | diff --git a/testcases/kernel/io/disktest/Makefile.linux b/testcases/kernel/io/disktest/Makefile.linux |
| 133 | index ea45b5a57..0f3aab622 100644 |
| 134 | --- a/testcases/kernel/io/disktest/Makefile.linux |
| 135 | +++ b/testcases/kernel/io/disktest/Makefile.linux |
| 136 | @@ -167,8 +167,8 @@ mandir=/usr/share/man |
| 137 | |
| 138 | VER=`grep VER_STR main.h | awk -F\" '{print $$2}'` |
| 139 | GBLHDRS=main.h globals.h defs.h |
| 140 | -ALLHDRS=$(wildcard *.h) |
| 141 | -SRCS=$(wildcard *.c) |
| 142 | +ALLHDRS=$(sort $(wildcard *.h)) |
| 143 | +SRCS=$(sort $(wildcard *.c)) |
| 144 | OBJS=$(SRCS:.c=.o) |
| 145 | |
| 146 | CFLAGS += -g -Wall -O -D"LINUX" -D"_THREAD_SAFE" -D"_GNU_SOURCE" -D"_LARGE_FILES" -D"_LARGEFILE64_SOURCE" -D"_FILE_OFFSET_BITS=64" $(RPM_OPT_FLAGS) |
| 147 | diff --git a/testcases/kernel/sched/hyperthreading/ht_affinity/Makefile b/testcases/kernel/sched/hyperthreading/ht_affinity/Makefile |
| 148 | index 10fec96dc..6b64bd261 100644 |
| 149 | --- a/testcases/kernel/sched/hyperthreading/ht_affinity/Makefile |
| 150 | +++ b/testcases/kernel/sched/hyperthreading/ht_affinity/Makefile |
| 151 | @@ -28,6 +28,6 @@ INSTALL_TARGETS := smt_smp_affinity.sh |
| 152 | |
| 153 | MAKE_TARGETS := ht_affinity |
| 154 | |
| 155 | -$(MAKE_TARGETS): $(patsubst $(abs_srcdir)/%.c,%.o,$(wildcard $(abs_srcdir)/*.c)) |
| 156 | +$(MAKE_TARGETS): $(patsubst $(abs_srcdir)/%.c,%.o,$(sort $(wildcard $(abs_srcdir)/*.c))) |
| 157 | |
| 158 | include $(top_srcdir)/include/mk/generic_leaf_target.mk |
| 159 | diff --git a/testcases/kernel/sched/hyperthreading/ht_enabled/Makefile b/testcases/kernel/sched/hyperthreading/ht_enabled/Makefile |
| 160 | index 9c1e139d6..585ff1383 100644 |
| 161 | --- a/testcases/kernel/sched/hyperthreading/ht_enabled/Makefile |
| 162 | +++ b/testcases/kernel/sched/hyperthreading/ht_enabled/Makefile |
| 163 | @@ -28,6 +28,6 @@ INSTALL_TARGETS := smt_smp_enabled.sh |
| 164 | |
| 165 | MAKE_TARGETS := ht_enabled |
| 166 | |
| 167 | -$(MAKE_TARGETS): $(patsubst $(abs_srcdir)/%.c,%.o,$(wildcard $(abs_srcdir)/*.c)) |
| 168 | +$(MAKE_TARGETS): $(patsubst $(abs_srcdir)/%.c,%.o,$(sort $(wildcard $(abs_srcdir)/*.c))) |
| 169 | |
| 170 | include $(top_srcdir)/include/mk/generic_leaf_target.mk |
| 171 | diff --git a/testcases/kernel/sched/sched_stress/Makefile b/testcases/kernel/sched/sched_stress/Makefile |
| 172 | index b76126c73..4dbbf3477 100644 |
| 173 | --- a/testcases/kernel/sched/sched_stress/Makefile |
| 174 | +++ b/testcases/kernel/sched/sched_stress/Makefile |
| 175 | @@ -10,7 +10,7 @@ INSTALL_TARGETS := sched_stress.sh |
| 176 | |
| 177 | LDLIBS += -lpthread |
| 178 | |
| 179 | -MAKE_TARGETS := $(filter-out sched,$(patsubst $(abs_srcdir)/%.c,%,$(wildcard $(abs_srcdir)/*.c))) |
| 180 | +MAKE_TARGETS := $(filter-out sched,$(patsubst $(abs_srcdir)/%.c,%,$(sort $(wildcard $(abs_srcdir)/*.c)))) |
| 181 | |
| 182 | RM += -r |
| 183 | |
| 184 | diff --git a/testcases/kernel/syscalls/lchown/Makefile b/testcases/kernel/syscalls/lchown/Makefile |
| 185 | index 13d39cb81..305fee281 100644 |
| 186 | --- a/testcases/kernel/syscalls/lchown/Makefile |
| 187 | +++ b/testcases/kernel/syscalls/lchown/Makefile |
| 188 | @@ -5,7 +5,7 @@ top_srcdir ?= ../../../.. |
| 189 | |
| 190 | include $(top_srcdir)/include/mk/testcases.mk |
| 191 | |
| 192 | -SRCS := $(wildcard $(abs_srcdir)/lchown*.c) |
| 193 | +SRCS := $(sort $(wildcard $(abs_srcdir)/lchown*.c)) |
| 194 | |
| 195 | include $(abs_srcdir)/../utils/compat_16.mk |
| 196 | |
| 197 | diff --git a/testcases/kernel/syscalls/migrate_pages/Makefile b/testcases/kernel/syscalls/migrate_pages/Makefile |
| 198 | index 46912b025..9cf3ce526 100644 |
| 199 | --- a/testcases/kernel/syscalls/migrate_pages/Makefile |
| 200 | +++ b/testcases/kernel/syscalls/migrate_pages/Makefile |
| 201 | @@ -5,7 +5,7 @@ top_srcdir ?= ../../../.. |
| 202 | |
| 203 | include $(top_srcdir)/include/mk/testcases.mk |
| 204 | |
| 205 | -MAKE_TARGETS := $(patsubst $(abs_srcdir)/%.c,%,$(wildcard $(abs_srcdir)/*[0-9].c)) |
| 206 | +MAKE_TARGETS := $(patsubst $(abs_srcdir)/%.c,%,$(sort $(wildcard $(abs_srcdir)/*[0-9].c))) |
| 207 | $(MAKE_TARGETS): %: migrate_pages_common.o |
| 208 | |
| 209 | CPPFLAGS += -I$(abs_srcdir)/../utils/ |
| 210 | diff --git a/testcases/kernel/syscalls/move_pages/Makefile b/testcases/kernel/syscalls/move_pages/Makefile |
| 211 | index cd7ff6349..4b22160ed 100644 |
| 212 | --- a/testcases/kernel/syscalls/move_pages/Makefile |
| 213 | +++ b/testcases/kernel/syscalls/move_pages/Makefile |
| 214 | @@ -7,7 +7,7 @@ include $(top_srcdir)/include/mk/testcases.mk |
| 215 | |
| 216 | CPPFLAGS += -I$(abs_srcdir)/../utils |
| 217 | |
| 218 | -MAKE_TARGETS := $(patsubst $(abs_srcdir)/%.c,%,$(wildcard $(abs_srcdir)/*[0-9].c)) |
| 219 | +MAKE_TARGETS := $(patsubst $(abs_srcdir)/%.c,%,$(sort $(wildcard $(abs_srcdir)/*[0-9].c))) |
| 220 | |
| 221 | $(MAKE_TARGETS): %: move_pages_support.o |
| 222 | |
| 223 | diff --git a/testcases/kernel/syscalls/utils/compat_16.mk b/testcases/kernel/syscalls/utils/compat_16.mk |
| 224 | index a0ff8f558..e81a00c40 100644 |
| 225 | --- a/testcases/kernel/syscalls/utils/compat_16.mk |
| 226 | +++ b/testcases/kernel/syscalls/utils/compat_16.mk |
| 227 | @@ -50,7 +50,7 @@ |
| 228 | |
| 229 | CPPFLAGS += -I$(abs_srcdir) -I$(abs_srcdir)/../utils |
| 230 | |
| 231 | -SRCS ?= $(wildcard $(abs_srcdir)/*.c) |
| 232 | +SRCS ?= $(sort $(wildcard $(abs_srcdir)/*.c)) |
| 233 | |
| 234 | MAKE_TARGETS := $(notdir $(patsubst %.c,%,$(SRCS))) |
| 235 | MAKE_TARGETS_OBJS_WO_COMPAT_16 := $(addsuffix .o,$(MAKE_TARGETS)) |
| 236 | diff --git a/testcases/kernel/syscalls/utils/newer_64.mk b/testcases/kernel/syscalls/utils/newer_64.mk |
| 237 | index 8cd7e03c8..5e798057a 100644 |
| 238 | --- a/testcases/kernel/syscalls/utils/newer_64.mk |
| 239 | +++ b/testcases/kernel/syscalls/utils/newer_64.mk |
| 240 | @@ -25,7 +25,7 @@ |
| 241 | |
| 242 | CPPFLAGS += -I$(abs_srcdir) -I$(abs_srcdir)/../utils |
| 243 | |
| 244 | -SRCS ?= $(wildcard $(abs_srcdir)/*.c) |
| 245 | +SRCS ?= $(sort $(wildcard $(abs_srcdir)/*.c)) |
| 246 | |
| 247 | MAKE_TARGETS := $(notdir $(patsubst %.c,%,$(SRCS))) |
| 248 | |
| 249 | diff --git a/testcases/misc/math/float/Makefile b/testcases/misc/math/float/Makefile |
| 250 | index 79dda35d6..5f4cb0f6c 100644 |
| 251 | --- a/testcases/misc/math/float/Makefile |
| 252 | +++ b/testcases/misc/math/float/Makefile |
| 253 | @@ -27,6 +27,6 @@ include $(top_srcdir)/include/mk/testcases.mk |
| 254 | LDLIBS += -lpthread -lm |
| 255 | |
| 256 | # main.c doesn't compile... |
| 257 | -MAKE_TARGETS := $(patsubst $(abs_srcdir)/%.c,%,$(wildcard $(abs_srcdir)/float*.c)) |
| 258 | +MAKE_TARGETS := $(patsubst $(abs_srcdir)/%.c,%,$(sort $(wildcard $(abs_srcdir)/float*.c))) |
| 259 | |
| 260 | include $(top_srcdir)/include/mk/generic_trunk_target.mk |
| 261 | diff --git a/testcases/network/nfs/nfs_stress/nfs05_make_tree.c b/testcases/network/nfs/nfs_stress/nfs05_make_tree.c |
| 262 | index 12c86799d..23c520d9d 100644 |
| 263 | --- a/testcases/network/nfs/nfs_stress/nfs05_make_tree.c |
| 264 | +++ b/testcases/network/nfs/nfs_stress/nfs05_make_tree.c |
| 265 | @@ -104,7 +104,7 @@ static void *thread_fn(LTP_ATTRIBUTE_UNUSED void *args) |
| 266 | "\treturn 0;\n}\n"; |
| 267 | |
| 268 | const char make_buf_n[] = "CFLAGS := -O -w -g\n" |
| 269 | - "SRCS=$(wildcard *.c)\n" |
| 270 | + "SRCS=$(sort $(wildcard *.c))\n" |
| 271 | "TARGETS=$(SRCS:.c=)\n" |
| 272 | "all: $(TARGETS)\n" |
| 273 | "$(TARGETS): %: %.c\n" |
| 274 | @@ -114,7 +114,7 @@ static void *thread_fn(LTP_ATTRIBUTE_UNUSED void *args) |
| 275 | |
| 276 | const char make_buf[] = "CFLAGS := -O -w -g\n" |
| 277 | "SUBDIR = dir\n" |
| 278 | - "SRCS=$(wildcard *.c)\n" |
| 279 | + "SRCS=$(sort $(wildcard *.c))\n" |
| 280 | "TARGETS=$(SRCS:.c=)\n" |
| 281 | "all: $(SUBDIR) $(TARGETS)\n" |
| 282 | "$(TARGETS): %: %.c\n" |
| 283 | diff --git a/testcases/network/nfsv4/locks/Makefile b/testcases/network/nfsv4/locks/Makefile |
| 284 | index 5812dea3a..05941c892 100644 |
| 285 | --- a/testcases/network/nfsv4/locks/Makefile |
| 286 | +++ b/testcases/network/nfsv4/locks/Makefile |
| 287 | @@ -28,6 +28,6 @@ MAKE_TARGETS := locktests |
| 288 | |
| 289 | LDLIBS += -lpthread |
| 290 | |
| 291 | -$(MAKE_TARGETS): $(patsubst $(abs_srcdir)/%.c,%.o,$(wildcard $(abs_srcdir)/*.c)) |
| 292 | +$(MAKE_TARGETS): $(patsubst $(abs_srcdir)/%.c,%.o,$(sort $(wildcard $(abs_srcdir)/*.c))) |
| 293 | |
| 294 | include $(top_srcdir)/include/mk/generic_leaf_target.mk |
| 295 | diff --git a/utils/sctp/func_tests/Makefile b/utils/sctp/func_tests/Makefile |
| 296 | index d296c652a..a17107853 100644 |
| 297 | --- a/utils/sctp/func_tests/Makefile |
| 298 | +++ b/utils/sctp/func_tests/Makefile |
| 299 | @@ -30,7 +30,7 @@ LDFLAGS += $(addprefix -L$(abs_builddir)/../,lib testlib) |
| 300 | |
| 301 | LDLIBS += -lsctputil -lsctp -lpthread |
| 302 | |
| 303 | -V4_TARGETS := $(patsubst $(abs_srcdir)/%.c,%,$(wildcard $(abs_srcdir)/*.c)) |
| 304 | +V4_TARGETS := $(patsubst $(abs_srcdir)/%.c,%,$(sort $(wildcard $(abs_srcdir)/*.c))) |
| 305 | |
| 306 | V6_TARGETS := test_basic_v6 test_fragments_v6 test_getname_v6 \ |
| 307 | test_inaddr_any_v6 test_peeloff_v6 \ |
| 308 | -- |
| 309 | 2.27.0 |
| 310 | |