Skip to content

Instantly share code, notes, and snippets.

@faizauthar12
Created March 17, 2016 09:10
Show Gist options
  • Save faizauthar12/434c822a546b02e032b2 to your computer and use it in GitHub Desktop.
Save faizauthar12/434c822a546b02e032b2 to your computer and use it in GitHub Desktop.
Archi Droid 4.1 for temasek cm12.1 also fix for building kernel
From e8d6fe2f8c0632b1e572f2b06a1c7c018b03eca1 Mon Sep 17 00:00:00 2001
From: Faiz Authar <faizauthar@gmail.com>
Date: Thu, 17 Mar 2016 16:07:49 +0700
Subject: ArchiDroid Optimisation 4.1 for Temasek cm12.1
diff --git a/core/Makefile b/core/Makefile
index 6843bf7..c35e477 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -919,6 +919,9 @@ else
build/target/product/security/cm-devkey
endif
+# ArchiDroid
+include $(BUILD_SYSTEM)/archidroid.mk
+
# Generate a file containing the keys that will be read by the
# recovery binary.
RECOVERY_INSTALL_OTA_KEYS := \
@@ -979,7 +982,9 @@ $(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTIMG) $(recovery_ramdisk) \
ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY))
$(BOOT_SIGNER) /recovery $@ $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem $@
endif
+ifneq ($(ARCHIDROID_IGNORE_RECOVERY_SIZE),true)
$(hide) $(call assert-max-image-size,$@,$(BOARD_RECOVERYIMAGE_PARTITION_SIZE))
+endif
@echo -e ${CL_CYN}"Made recovery image: $@"${CL_RST}
endif # BOARD_CUSTOM_BOOTIMG_MK
diff --git a/core/archidroid.mk b/core/archidroid.mk
new file mode 100644
index 0000000..d0cded3
--- /dev/null
+++ b/core/archidroid.mk
@@ -0,0 +1,120 @@
+# _ _ _ ____ _ _
+# / \ _ __ ___| |__ (_) _ \ _ __ ___ (_) __| |
+# / _ \ | '__/ __| '_ \| | | | | '__/ _ \| |/ _` |
+# / ___ \| | | (__| | | | | |_| | | | (_) | | (_| |
+# /_/ \_\_| \___|_| |_|_|____/|_| \___/|_|\__,_|
+#
+# Copyright 2015 Łukasz "JustArchi" Domeradzki
+# Contact: JustArchi@JustArchi.net
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#######################
+### GENERAL SECTION ###
+#######################
+
+# General optimization level of target ARM compiled with GCC. Default: -O2
+ARCHIDROID_GCC_CFLAGS_ARM := -O3
+
+# General optimization level of target THUMB compiled with GCC. Default: -Os
+ARCHIDROID_GCC_CFLAGS_THUMB := -O3
+
+# Additional flags passed to all C targets compiled with GCC
+ARCHIDROID_GCC_CFLAGS := -O3 -fgcse-las -fgcse-sm -fipa-pta -fivopts -fomit-frame-pointer -frename-registers -fsection-anchors -ftracer -ftree-loop-im -ftree-loop-ivcanon -funsafe-loop-optimizations -funswitch-loops -fweb -Wno-error=array-bounds -Wno-error=clobbered -Wno-error=maybe-uninitialized -Wno-error=strict-overflow
+
+############################
+### EXPERIMENTAL SECTION ###
+############################
+
+# Flags in this section are highly experimental
+# Current setup is based on proposed androideabi toolchain
+# Results with other toolchains may vary
+
+# These flags work fine in suggested compiler, but may cause ICEs in other compilers, comment if needed
+# ARCHIDROID_GCC_CFLAGS += -fgraphite -fgraphite-identity
+
+# The following flags (-floop) require that your GCC has been configured with --with-isl
+# Additionally, applying any of them will most likely cause ICE in your compiler, so they're disabled
+# ARCHIDROID_GCC_CFLAGS += -floop-block -floop-interchange -floop-nest-optimize -floop-parallelize-all -floop-strip-mine
+
+# These flags have been disabled because of assembler errors
+# ARCHIDROID_GCC_CFLAGS += -fmodulo-sched -fmodulo-sched-allow-regmoves
+
+####################
+### MISC SECTION ###
+####################
+
+# Flags passed to GCC preprocessor for C and C++
+ARCHIDROID_GCC_CPPFLAGS := $(ARCHIDROID_GCC_CFLAGS)
+
+# Flags passed to linker (ld) of all C and C++ targets compiled with GCC
+ARCHIDROID_GCC_LDFLAGS := -Wl,--sort-common
+
+#####################
+### CLANG SECTION ###
+#####################
+
+# Flags passed to all C targets compiled with CLANG
+ARCHIDROID_CLANG_CFLAGS := -O3 -Qunused-arguments -Wno-unknown-warning-option
+
+# Flags passed to CLANG preprocessor for C and C++
+ARCHIDROID_CLANG_CPPFLAGS := $(ARCHIDROID_CLANG_CFLAGS)
+
+# Flags passed to linker (ld) of all C and C++ targets compiled with CLANG
+ARCHIDROID_CLANG_LDFLAGS := -Wl,--sort-common
+
+# Flags that are used by GCC, but are unknown to CLANG. If you get "argument unused during compilation" error, add the flag here
+ARCHIDROID_CLANG_UNKNOWN_FLAGS := \
+ -mvectorize-with-neon-double \
+ -mvectorize-with-neon-quad \
+ -fgcse-after-reload \
+ -fgcse-las \
+ -fgcse-sm \
+ -fgraphite \
+ -fgraphite-identity \
+ -fipa-pta \
+ -floop-block \
+ -floop-interchange \
+ -floop-nest-optimize \
+ -floop-parallelize-all \
+ -ftree-parallelize-loops=2 \
+ -ftree-parallelize-loops=4 \
+ -ftree-parallelize-loops=8 \
+ -ftree-parallelize-loops=16 \
+ -floop-strip-mine \
+ -fmodulo-sched \
+ -fmodulo-sched-allow-regmoves \
+ -frerun-cse-after-loop \
+ -frename-registers \
+ -fsection-anchors \
+ -ftree-loop-im \
+ -ftree-loop-ivcanon \
+ -funsafe-loop-optimizations \
+ -fweb
+
+#####################
+### HACKS SECTION ###
+#####################
+
+# Most of the flags are increasing code size of the output binaries, especially O3 instead of Os for target THUMB
+# This may become problematic for small blocks, especially for boot or recovery blocks (ramdisks)
+# If you don't care about the size of recovery.img, e.g. you have no use of it, and you want to silence the
+# error "image too large" for recovery.img, use this definition
+#
+# NOTICE: It's better to use device-based flag TARGET_NO_RECOVERY instead, but some devices may have
+# boot + recovery combo (e.g. Sony Xperias), and we must build recovery for them, so we can't set TARGET_NO_RECOVERY globally
+# Therefore, this seems like a safe approach (will only ignore check on recovery.img, without doing anything else)
+# However, if you use compiled recovery.img for your device, please disable this flag (comment or set to false), and lower
+# optimization levels instead
+ARCHIDROID_IGNORE_RECOVERY_SIZE := true
+
diff --git a/core/clang/config.mk b/core/clang/config.mk
index 859adac..2ca5f75 100644
--- a/core/clang/config.mk
+++ b/core/clang/config.mk
@@ -35,6 +35,12 @@ CLANG_CONFIG_EXTRA_CFLAGS :=
CLANG_CONFIG_EXTRA_CPPFLAGS :=
CLANG_CONFIG_EXTRA_LDFLAGS :=
+# ArchiDroid
+include $(BUILD_SYSTEM)/archidroid.mk
+CLANG_CONFIG_EXTRA_CFLAGS += $(ARCHIDROID_CLANG_CFLAGS)
+CLANG_CONFIG_EXTRA_CPPFLAGS += $(ARCHIDROID_CLANG_CPPFLAGS)
+CLANG_CONFIG_EXTRA_LDFLAGS += $(ARCHIDROID_CLANG_LDFLAGS)
+
CLANG_CONFIG_EXTRA_CFLAGS += \
-w -O3 -Qunused-arguments -Wno-unknown-warning-option -D__compiler_offsetof=__builtin_offsetof
@@ -48,6 +54,7 @@ CLANG_CONFIG_EXTRA_CFLAGS += \
-Wno-unused-command-line-argument
CLANG_CONFIG_UNKNOWN_CFLAGS := \
+ -$(ARCHIDROID_CLANG_UNKNOWN_FLAGS) \
-funswitch-loops \
-fno-tree-sra \
-finline-limit=64 \
diff --git a/core/combo/TARGET_linux-arm.mk b/core/combo/TARGET_linux-arm.mk
index 0f2cf3e..cd0db22 100644
--- a/core/combo/TARGET_linux-arm.mk
+++ b/core/combo/TARGET_linux-arm.mk
@@ -67,17 +67,25 @@ $(combo_2nd_arch_prefix)TARGET_STRIP := $($(combo_2nd_arch_prefix)TARGET_TOOLS_P
$(combo_2nd_arch_prefix)TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
-$(combo_2nd_arch_prefix)TARGET_arm_CFLAGS := -O3 \
+# ArchiDroid
+include $(BUILD_SYSTEM)/archidroid.mk
+
+$(combo_2nd_arch_prefix)TARGET_arm_CFLAGS := $(ARCHIDROID_GCC_CFLAGS_ARM) \
-fomit-frame-pointer \
-fstrict-aliasing \
-funswitch-loops
# Modules can choose to compile some source as thumb.
$(combo_2nd_arch_prefix)TARGET_thumb_CFLAGS := -mthumb \
- -O3 \
+ $(ARCHIDROID_GCC_CFLAGS_THUMB) \
-fomit-frame-pointer \
-fno-strict-aliasing
+$(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += $(ARCHIDROID_GCC_CFLAGS)
+$(combo_2nd_arch_prefix)TARGET_GLOBAL_CPPFLAGS += $(ARCHIDROID_GCC_CPPFLAGS)
+$(combo_2nd_arch_prefix)TARGET_GLOBAL_LDFLAGS += $(ARCHIDROID_GCC_LDFLAGS)
+
+
# Set FORCE_ARM_DEBUGGING to "true" in your buildspec.mk
# or in your environment to force a full arm build, even for
# files that are normally built as thumb; this can make
diff --git a/core/combo/TARGET_linux-arm64.mk b/core/combo/TARGET_linux-arm64.mk
index 20a5fb5..2dabc63 100644
--- a/core/combo/TARGET_linux-arm64.mk
+++ b/core/combo/TARGET_linux-arm64.mk
@@ -119,10 +119,17 @@ TARGET_GLOBAL_LDFLAGS += $(BOARD_GLOBAL_LDFLAGS)
TARGET_GLOBAL_CPPFLAGS += -fvisibility-inlines-hidden
+# ArchiDroid
+include $(BUILD_SYSTEM)/archidroid.mk
+
+$(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += $(ARCHIDROID_GCC_CFLAGS)
+$(combo_2nd_arch_prefix)TARGET_GLOBAL_CPPFLAGS += $(ARCHIDROID_GCC_CPPFLAGS)
+$(combo_2nd_arch_prefix)TARGET_GLOBAL_LDFLAGS += $(ARCHIDROID_GCC_LDFLAGS)
+
# More flags/options can be added here
TARGET_RELEASE_CFLAGS := \
-DNDEBUG \
- -O2 -g \
+ $(ARCHIDROID_GCC_CFLAGS_ARM) \
-Wstrict-aliasing=2 \
-fgcse-after-reload \
-frerun-cse-after-loop \
diff --git a/core/combo/select.mk b/core/combo/select.mk
index 69a690b..b4536ad 100644
--- a/core/combo/select.mk
+++ b/core/combo/select.mk
@@ -26,6 +26,9 @@ combo_os_arch := $($(combo_target)OS)-$($(combo_target)$(combo_2nd_arch_prefix)A
combo_var_prefix := $(combo_2nd_arch_prefix)$(combo_target)
+# ArchiDroid
+include $(BUILD_SYSTEM)/archidroid.mk
+
# Set reasonable defaults for the various variables
$(combo_var_prefix)CC := $(CC)
@@ -50,7 +53,7 @@ $(combo_var_prefix)HAVE_STRLCAT := 0
$(combo_var_prefix)HAVE_KERNEL_MODULES := 0
$(combo_var_prefix)GLOBAL_CFLAGS := -fno-exceptions -Wno-multichar
-$(combo_var_prefix)RELEASE_CFLAGS := -O3 -fno-strict-aliasing
+$(combo_var_prefix)RELEASE_CFLAGS := $(ARCHIDROID_GCC_CFLAGS_ARM) -fno-strict-aliasing
$(combo_var_prefix)GLOBAL_CPPFLAGS :=
$(combo_var_prefix)GLOBAL_LDFLAGS := -Wl,-O1 -Wl,--as-needed -Wl,--relax -Wl,--sort-common -Wl,--gc-sections
$(combo_var_prefix)GLOBAL_ARFLAGS := crsPD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment