microbenchmarks: Update common.mk with symbolic and visibility flags This syncs common.mk with the latest source in src/platform2/common-mk. Main change that affects the compiled binary are the newly added -fvisibility-inlines-hidden CXXFLAGS and the -Bsymbolic-non-weak LDFLAGS (see comments in the file for what these do). BUG=b:352469414 TEST=CQ Change-Id: I90146ff2e4fdae8b71dfad2e404d9c94766feab3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/microbenchmarks/+/5693248 Auto-Submit: Tatsuyuki Ishi <ishitatsuyuki@google.com> Tested-by: Tatsuyuki Ishi <ishitatsuyuki@google.com> Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com> Reviewed-by: Vovo Yang <vovoy@chromium.org>
diff --git a/common.mk b/common.mk index 524243e..7c2a904 100644 --- a/common.mk +++ b/common.mk
@@ -1,4 +1,4 @@ -# Copyright (c) 2012 The Chromium OS Authors. All rights reserved. +# Copyright 2012 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # @@ -63,7 +63,7 @@ # # Possible command line variables: # - COLOR=[0|1] to set ANSI color output (default: 1) -# - VERBOSE=[0|1] to hide/show commands (default: 0) +# - VERBOSE=[0|1] V=[0|1] to hide/show commands (default: 0) # - MODE=[opt|dbg|profiling] (default: opt) # opt - Enable optimizations for release builds # dbg - Turn down optimization for debugging @@ -98,9 +98,11 @@ NOSTRIP ?= 1 VALGRIND ?= 0 COLOR ?= 1 -VERBOSE ?= 0 +V ?= 0 +VERBOSE ?= $(V) MODE ?= opt CXXEXCEPTIONS ?= 0 +RUN_TESTS ?= 1 ARCH ?= $(shell uname -m) # Put objects in a separate tree based on makefile locations @@ -122,13 +124,6 @@ # $(PWD) != $(CURDIR) all the time. export SRC ?= $(CURDIR) -# If BASE_VER is not set, read the libchrome revision number from -# common-mk/BASE_VER file. -ifeq ($(strip $(BASE_VER)),) -BASE_VER := $(shell cat $(SRC)/../common-mk/BASE_VER) -endif -$(info Using BASE_VER=$(BASE_VER)) - # Re-start in the $(OUT) directory if we're not there. # We may be invoked using -C or bare and we need to ensure behavior # is consistent so we check both PWD vs OUT and PWD vs CURDIR. @@ -265,13 +260,13 @@ RMDIR ?= rmdir ECHO = /bin/echo -e -ifeq ($(lastword $(subst /, ,$(CC))),clang) +ifeq ($(filter clang,$(subst -, ,$(notdir $(CC)))),clang) CDRIVER = clang else CDRIVER = gcc endif -ifeq ($(lastword $(subst /, ,$(CXX))),clang++) +ifeq ($(filter clang++,$(subst -, ,$(notdir $(CXX)))),clang++) CXXDRIVER = clang else CXXDRIVER = gcc @@ -317,11 +312,23 @@ # CXXFLAGS := $(filter-out badflag,$(CXXFLAGS)) # Filter out a value # The same goes for CFLAGS. COMMON_CFLAGS-gcc := -fvisibility=internal -ggdb3 -Wa,--noexecstack -COMMON_CFLAGS-clang := -fvisibility=hidden -ggdb -COMMON_CFLAGS := -Wall -Werror -fno-strict-aliasing $(SSP_CFLAGS) -O1 -Wformat=2 -CXXFLAGS += $(COMMON_CFLAGS) $(COMMON_CFLAGS-$(CXXDRIVER)) -std=gnu++11 -CFLAGS += $(COMMON_CFLAGS) $(COMMON_CFLAGS-$(CDRIVER)) -std=gnu11 -CPPFLAGS += -D_FORTIFY_SOURCE=3 +COMMON_CFLAGS-clang := -fvisibility=hidden -ggdb -Wimplicit-fallthrough \ + -Wstring-plus-int +# When a class is exported through __attribute__((visibility("default"))), we +# still want to eliminate symbols from inline class member functions to reduce +# symbol resolution overhead. Therefore, pass -fvisibility-inlines-hidden in +# addition to -fvisibility=hidden. (go/cros-symbol-slimming) +COMMON_CFLAGS := -Wall -Wunused -Wno-unused-parameter -Wunreachable-code \ + -Wbool-operation -Wstring-compare -Wxor-used-as-pow \ + -Wint-in-bool-context -Wfree-nonheap-object \ + -Werror -Wformat=2 -fno-strict-aliasing -fvisibility-inlines-hidden \ + $(SSP_CFLAGS) -O1 +CXXFLAGS += $(COMMON_CFLAGS) $(COMMON_CFLAGS-$(CXXDRIVER)) -std=gnu++20 +CFLAGS += $(COMMON_CFLAGS) $(COMMON_CFLAGS-$(CDRIVER)) -std=gnu17 +# We undefine _FORTIFY_SOURCE because some distros enable it by default in +# their toolchains. This makes the compiler issue warnings about redefines +# and our -Werror usage breaks it all. +CPPFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 # Enable large file support. CPPFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE @@ -350,7 +357,11 @@ LDFLAGS := $(LDFLAGS) --coverage endif -LDFLAGS := $(LDFLAGS) -Wl,-z,relro -Wl,-z,noexecstack -Wl,-z,now +# Pass -Bsymbolic-non-weak which pre-binds symbols in the same DSO to improve +# startup performance. We don't support interposing non-weak symbols. +# (go/cros-symbol-slimming) +LDFLAGS := $(LDFLAGS) -Wl,-z,relro -Wl,-z,noexecstack -Wl,-z,now \ + -Wl,-Bsymbolic-non-weak # Fancy helpers for color if a prompt is defined ifeq ($(COLOR),1) @@ -520,8 +531,11 @@ $(error Typo alert! LIBARY != LIBRARY) -TEST(%): % qemu_chroot_install +TEST(%): % $(call TEST_implementation) +ifneq ($(RUN_TESTS),0) +TEST(%): qemu_chroot_install +endif .PHONY: TEST # multiple targets with a wildcard need to share an directory. @@ -587,13 +601,12 @@ $$(QUIET)touch "$$@" endef +# Wrap all the deps in $$(wildcard) so a missing header won't cause weirdness. +# First we remove newlines and \, then wrap it. define OBJECT_PATTERN_implementation @$(ECHO) "$(1) $(subst $(SRC)/,,$<) -> $(2).o" $(call auto_mkdir,$@) $(QUIET)$($(1)) -c -MD -MF $(2).d $(3) -o $(2).o $< - $(QUIET)# Wrap all the deps in $$(wildcard) so a missing header - $(QUIET)# won't cause weirdness. First we remove newlines and \, - $(QUIET)# then wrap it. $(QUIET)sed -i -e :j -e '$$!N;s|\\\s*\n| |;tj' \ -e 's|^\(.*\s*:\s*\)\(.*\)$$|\1 $$\(wildcard \2\)|' $(2).d endef @@ -732,7 +745,9 @@ fi @$(ECHO) "COVERAGE [$(COLOR_YELLOW)FINISHED$(COLOR_RESET)]" endif -.PHONY: tests +# Standard name everyone else uses. +check: tests +.PHONY: check tests qemu_chroot_install: ifeq ($(USE_QEMU),1) @@ -805,12 +820,17 @@ VALGRIND_CMD = /usr/bin/valgrind --tool=memcheck $(VALGRIND_ARGS) -- endif +ifneq ($(RUN_TESTS),0) define TEST_implementation $(QUIET)$(call TEST_setup) $(QUIET)$(call TEST_run) $(QUIET)$(call TEST_teardown) $(QUIET)exit $$(cat $(OUT)$(TARGET_OR_MEMBER).status.test) endef +else +define TEST_implementation +endef +endif define TEST_setup @$(ECHO) -n "TEST $(TARGET_OR_MEMBER) "