linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sedat Dilek <sedat.dilek@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Michal Marek <mmarek@suse.cz>, Sam Ravnborg <sam@ravnborg.org>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Arnd Bergmann <arnd@arndb.de>, Ingo Molnar <mingo@redhat.com>
Cc: linux-kbuild@vger.kernel.org,
	Linux ACPI <linux-acpi@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	"the arch/x86 maintainers" <x86@kernel.org>
Subject: Thoughts about introducing OPTIMIZATION_CFLAG
Date: Mon, 4 Jan 2016 11:54:46 +0100	[thread overview]
Message-ID: <CA+icZUVEs_+XiWeqtJ+34HBSx5LJYyEgoo2DLFzVr6yc9oxx2Q@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 3478 bytes --]

[ Not sure if I have addressed all the correct people and mailing-lists ]

Hi,

while still digging into a llvmlinux issue with workqueue I saw that
the wrong optimization compiler-flag was used on x86 architecture and
acpi subsystem.

CLANG requires '-Oz' whereas GCC requires '-Os'.

As acpi-daemon was throwing out the regression I looked by accident
over the *_CFLAGS.
As said... I checked only for x86 and acpi only.

For example '-Os' is hardcoded in...

arch/x86/Makefile
arch/x86/purgatory/Makefile

drivers/acpi/Makefile
drivers/acpi/acpica/Makefile

For acpi part we have currently both used '-O2' and '-Os' ('-Oz' for
llvmlinux) in approx 200 make-lines.

$ grep '\-O2' build-log_4.4.0-rc8-2-llvmlinux-amd64.txt | grep acpi | wc -l
226
$ grep '\-Oz' build-log_4.4.0-rc8-2-llvmlinux-amd64.txt | grep acpi |
grep '\-O2' | wc -l
200

So, which optimization-cflags is now used if I have both in one
make-line (and how can I check this)?

[ EXAMPLE ]

$ mycompiler --version
clang version 3.7.0 (tags/RELEASE_370/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix

$  mycompiler -Wp,-MD,drivers/acpi/.video_detect.o.d  -nostdinc
-isystem /opt/llvm-toolchain-3.7.0/bin/../lib/clang/3.7.0/include
-nostdinc -isystem
/opt/llvm-toolchain-3.7.0/bin/../lib/clang/3.7.0/include
-I./arch/x86/include -Iarch/x86/include/generated/uapi
-Iarch/x86/include/generated  -Iinclude -I./arch/x86/include/uapi
-Iarch/x86/include/generated/uapi -I./include/uapi
-Iinclude/generated/uapi -include ./include/linux/kconfig.h
-D__KERNEL__ -Qunused-arguments -Wno-unknown-warning-option -Wall
-Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
-fno-common -Werror-implicit-function-declaration -Wno-format-security
-std=gnu89 -no-integrated-as -mno-sse -mno-mmx -mno-sse2 -mno-3dnow
-mno-avx -m64 -mtune=generic -mno-red-zone -mcmodel=kernel
-funit-at-a-time -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1
-DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1
-DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1
-DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -pipe -Wno-sign-compare
-fno-asynchronous-unwind-tables *** -O2 *** -Wframe-larger-than=1024
-fno-stack-protector -Wno-unused-variable
-Wno-format-invalid-specifier -Wno-gnu -Wno-asm-operand-widths
-Wno-initializer-overrides -fno-builtin -Wno-tautological-compare
-mno-global-merge -fno-omit-frame-pointer -fno-optimize-sibling-calls
-pg -Wdeclaration-after-statement -Wno-pointer-sign
-fno-strict-overflow -Werror=implicit-int -Werror=strict-prototypes
-Werror=date-time -Wno-initializer-overrides -Wno-unused-value
-Wno-format -Wno-unknown-warning-option -Wno-sign-compare
-Wno-format-zero-length -Wno-uninitialized *** -Oz *** -DMODULE
-D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(video_detect)"
-D"KBUILD_MODNAME=KBUILD_STR(video)" -c -o
drivers/acpi/.tmp_video_detect.o drivers/acpi/video_detect.c

How can I switch a optimization-cflags for certain code-parts in the
Linux-kernel (with or without the kbuild-system)?
( So the default optimization-cflags is '-O2' whereas parts wants '-Os'. )

What to do when using CONFIG_CC_OPTIMIZE_FOR_SIZE=y which sets '-Os' explicitly?

Below tools/ directory we have also an OPTIMIZATION variable used.

Something like a "global" solution is desired from my side.

I have attached a patchset on top of my llvmlinux-amd64-fixes-4.4,
hope this helps a bit to see what I mean.
It is not doing what I desire - still WIP.

Thoughts?

Thanks in advance.

Regards,
- Sedat -

[-- Attachment #2: 0001-kbuild-Introduce-OPTIMIZATION_CFLAGS.patch --]
[-- Type: text/x-diff, Size: 1640 bytes --]

From ed66e809d779d0ce5db6b71ad48792010bf6aad3 Mon Sep 17 00:00:00 2001
From: Sedat Dilek <sedat.dilek@gmail.com>
Date: Mon, 4 Jan 2016 11:16:00 +0100
Subject: [PATCH 1/3] kbuild: Introduce OPTIMIZATION_CFLAGS

Signed-off-by: Sedat Dilek <sedat.dilek@gmail.com>
---
 Makefile | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index dcdb24b27dde..30cd406a4475 100644
--- a/Makefile
+++ b/Makefile
@@ -295,10 +295,12 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
 	  else if [ -x /bin/bash ]; then echo /bin/bash; \
 	  else echo sh; fi ; fi)
 
+OPTIMIZATION_CFLAGS := -O2
+
 HOSTCC       = gcc
 HOSTCXX      = g++
-HOSTCFLAGS   = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
-HOSTCXXFLAGS = -O2
+HOSTCFLAGS   = -Wall -Wmissing-prototypes -Wstrict-prototypes $(OPTIMIZATION_CFLAGS) -fomit-frame-pointer -std=gnu89
+HOSTCXXFLAGS = $(OPTIMIZATION_CFLAGS)
 
 HOSTCFLAGS  += -Wno-unused-value -Wno-unused-parameter -Wno-missing-field-initializers
 ifneq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
@@ -623,11 +625,10 @@ KBUILD_CFLAGS	+= $(call cc-option,-fno-delete-null-pointer-checks,)
 endif
 
 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
-KBUILD_CFLAGS 	+= $(call cc-option,-Oz,-Os)
+OPTIMIZATION_CFLAGS := $(call cc-option,-Oz,-Os)
 KBUILD_CFLAGS	+= $(call cc-disable-warning,maybe-uninitialized,)
-else
-KBUILD_CFLAGS	+= -O2
 endif
+KBUILD_CFLAGS	+= $(OPTIMIZATION_CFLAGS)
 
 # Tell gcc to never replace conditional load with a non-conditional one
 KBUILD_CFLAGS	+= $(call cc-option,--param=allow-store-data-races=0)
-- 
2.6.4


[-- Attachment #3: 0002-x86-llvmlinux-Use-OPTIMIZATION_CFLAGS.patch --]
[-- Type: text/x-diff, Size: 1844 bytes --]

From a1224cbda2227a10cc86bc7b1c0442df7015f26c Mon Sep 17 00:00:00 2001
From: Sedat Dilek <sedat.dilek@gmail.com>
Date: Mon, 4 Jan 2016 11:41:51 +0100
Subject: [PATCH 2/3] x86: llvmlinux: Use OPTIMIZATION_CFLAGS

Signed-off-by: Sedat Dilek <sedat.dilek@gmail.com>
---
 arch/x86/Makefile           | 4 +++-
 arch/x86/purgatory/Makefile | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 5fa41ffe15e2..a88d0d490191 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -20,7 +20,9 @@ endif
 CODE16GCC_CFLAGS := -m32 -Wa,$(srctree)/arch/x86/boot/code16gcc.h
 M16_CFLAGS	 := $(call cc-option, -m16, $(CODE16GCC_CFLAGS))
 
-REALMODE_CFLAGS	:= $(M16_CFLAGS) -g -Os -D__KERNEL__ \
+OPTIMIZATION_CFLAGS := $(call cc-option,-Oz,-Os)
+
+REALMODE_CFLAGS	:= $(M16_CFLAGS) -g $(OPTIMIZATION_CFLAGS) -D__KERNEL__ \
 		   -DDISABLE_BRANCH_PROFILING \
 		   -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
 		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
index 2c835e356349..c9ffc07f9fa3 100644
--- a/arch/x86/purgatory/Makefile
+++ b/arch/x86/purgatory/Makefile
@@ -10,7 +10,9 @@ targets += purgatory.ro
 # in turn leaves some undefined symbols like __fentry__ in purgatory and not
 # sure how to relocate those. Like kexec-tools, use custom flags.
 
-KBUILD_CFLAGS := -fno-strict-aliasing -Wall -Wstrict-prototypes -fno-zero-initialized-in-bss -fno-builtin -ffreestanding -c -MD -Os -mcmodel=large
+OPTIMIZATION_CFLAGS := $(call cc-option,-Oz,-Os)
+
+KBUILD_CFLAGS := -fno-strict-aliasing -Wall -Wstrict-prototypes -fno-zero-initialized-in-bss -fno-builtin -ffreestanding -c -MD $(OPTIMIZATION_CFLAGS) -mcmodel=large
 KBUILD_CFLAGS += -m$(BITS)
 
 $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE
-- 
2.6.4


[-- Attachment #4: 0003-acpi-llvmlinux-Use-OPTIMIZATION_CFLAGS.patch --]
[-- Type: text/x-diff, Size: 1312 bytes --]

From 3ed0fdeafd219518ceff601cbb4df562c09374da Mon Sep 17 00:00:00 2001
From: Sedat Dilek <sedat.dilek@gmail.com>
Date: Mon, 4 Jan 2016 11:42:58 +0100
Subject: [PATCH 3/3] acpi: llvmlinux: Use OPTIMIZATION_CFLAGS

Signed-off-by: Sedat Dilek <sedat.dilek@gmail.com>
---
 drivers/acpi/Makefile        | 4 +++-
 drivers/acpi/acpica/Makefile | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 675eaf337178..8a52558da32d 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -2,7 +2,9 @@
 # Makefile for the Linux ACPI interpreter
 #
 
-ccflags-y			:= -Os
+OPTIMIZATION_CFLAGS 		:= $(call cc-option,-Oz,-Os)
+
+ccflags-y			:= $(OPTIMIZATION_CFLAGS)
 ccflags-$(CONFIG_ACPI_DEBUG)	+= -DACPI_DEBUG_OUTPUT
 
 #
diff --git a/drivers/acpi/acpica/Makefile b/drivers/acpi/acpica/Makefile
index 885936f79542..44b4648ccb46 100644
--- a/drivers/acpi/acpica/Makefile
+++ b/drivers/acpi/acpica/Makefile
@@ -2,7 +2,9 @@
 # Makefile for ACPICA Core interpreter
 #
 
-ccflags-y			:= -Os -DBUILDING_ACPICA
+OPTIMIZATION_CFLAGS		:= $(call cc-option,-Oz,-Os)
+
+ccflags-y			:= $(OPTIMIZATION_CFLAGS) -DBUILDING_ACPICA
 ccflags-$(CONFIG_ACPI_DEBUG)	+= -DACPI_DEBUG_OUTPUT
 
 # use acpi.o to put all files here into acpi.o modparam namespace
-- 
2.6.4


             reply	other threads:[~2016-01-04 10:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-04 10:54 Sedat Dilek [this message]
2016-01-04 11:25 ` Thoughts about introducing OPTIMIZATION_CFLAG Sedat Dilek
2016-01-04 11:33 ` One Thousand Gnomes
2016-01-04 11:47   ` Sedat Dilek
2016-01-04 22:37     ` Michal Marek
2016-01-08 10:03       ` Sedat Dilek
2016-01-08 11:31         ` Michal Marek
2016-01-08 11:49           ` Sedat Dilek
2016-01-08 12:30             ` Michal Marek
2016-01-08 13:25               ` Sedat Dilek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+icZUVEs_+XiWeqtJ+34HBSx5LJYyEgoo2DLFzVr6yc9oxx2Q@mail.gmail.com \
    --to=sedat.dilek@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mmarek@suse.cz \
    --cc=rafael.j.wysocki@intel.com \
    --cc=sam@ravnborg.org \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).