Skip to content

Commit

Permalink
Merge pull request #2 from ananjaser1211/Apollo_clang
Browse files Browse the repository at this point in the history
Apollo Clang support
  • Loading branch information
ananjaser1211 authored Jul 27, 2024
2 parents b17ae44 + 536bb5a commit b291108
Show file tree
Hide file tree
Showing 155 changed files with 2,447 additions and 1,195 deletions.
23 changes: 23 additions & 0 deletions Documentation/filesystems/overlayfs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ Only the lists of names from directories are merged. Other content
such as metadata and extended attributes are reported for the upper
directory only. These attributes of the lower directory are hidden.

credentials
-----------

By default, all access to the upper, lower and work directories is the
recorded mounter's MAC and DAC credentials. The incoming accesses are
checked against the caller's credentials.

In the case where caller MAC or DAC credentials do not overlap, a
use case available in older versions of the driver, the
override_creds mount flag can be turned off and help when the use
pattern has caller with legitimate credentials where the mounter
does not. Several unintended side effects will occur though. The
caller without certain key capabilities or lower privilege will not
always be able to delete files or directories, create nodes, or
search some restricted directories. The ability to search and read
a directory entry is spotty as a result of the cache mechanism not
retesting the credentials because of the assumption, a privileged
caller can fill cache, then a lower privilege can read the directory
cache. The uneven security model where cache, upperdir and workdir
are opened at privilege, but accessed without creating a form of
privilege escalation, should only be used with strict understanding
of the side effects and of the security policies.

whiteouts and opaque directories
--------------------------------

Expand Down
96 changes: 56 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
# "make" in the configured kernel build directory always uses that.
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
#ARCH ?= $(SUBARCH)
#CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
ARCH ?= arm64
#CROSS_COMPILE ?= ../PLATFORM/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-
CROSS_COMPILE ?= $(srctree)/toolchain/gcc-cfp/gcc-ibv-jopp/aarch64-linux-android-4.9/bin/aarch64-linux-android-

# Architecture as present in compile.h
UTS_MACHINE := $(ARCH)
Expand Down Expand Up @@ -306,14 +303,13 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
else if [ -x /bin/bash ]; then echo /bin/bash; \
else echo sh; fi ; fi)

HOSTCC = $(CCACHE) gcc
HOSTCXX = $(CCACHE) g++
HOSTCC = gcc
HOSTCXX = g++
HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
HOSTCXXFLAGS = -O2

ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
-Wno-missing-field-initializers -fno-delete-null-pointer-checks
ifeq ($(CONFIG_EXYNOS_FMP_FIPS),)
READELF = $(CROSS_COMPILE)readelf
export READELF
endif

# Decide whether to build built-in, modular, or both.
Expand Down Expand Up @@ -351,16 +347,16 @@ scripts/Kbuild.include: ;
include scripts/Kbuild.include

# Make variables (CC, etc...)
AS = $(CCACHE) $(CROSS_COMPILE)as
LD = $(CCACHE) $(CROSS_COMPILE)ld
LDGOLD = $(CCACHE) $(CROSS_COMPILE)ld.gold
CC = $(CCACHE) $(CROSS_COMPILE)gcc
CPP = $(CCACHE) $(CC) -E
AR = $(CCACHE) $(CROSS_COMPILE)ar
NM = $(CCACHE) $(CROSS_COMPILE)nm
STRIP = $(CCACHE) $(CROSS_COMPILE)strip
OBJCOPY = $(CCACHE) $(CROSS_COMPILE)objcopy
OBJDUMP = $(CCACHE) $(CROSS_COMPILE)objdump
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
LDGOLD = $(CROSS_COMPILE)ld.gold
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
AWK = awk
GENKSYMS = scripts/genksyms/genksyms
INSTALLKERNEL := installkernel
Expand Down Expand Up @@ -403,7 +399,7 @@ LINUXINCLUDE += $(filter-out $(LINUXINCLUDE),$(USERINCLUDE))

KBUILD_AFLAGS := -D__ASSEMBLY__
KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
-fno-strict-aliasing -fno-common \
-fno-strict-aliasing -fno-common -fshort-wchar \
-Werror-implicit-function-declaration \
-Wno-format-security \
-std=gnu89
Expand All @@ -414,6 +410,7 @@ KBUILD_AFLAGS_MODULE := -DMODULE
KBUILD_CFLAGS_MODULE := -DMODULE
KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
GCC_PLUGINS_CFLAGS :=
CLANG_FLAGS :=

# Read KERNELRELEASE from include/config/kernel.release (if it exists)
KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
Expand All @@ -426,7 +423,8 @@ export MAKE AWK GENKSYMS INSTALLKERNEL PERL PYTHON UTS_MACHINE
export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS

export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_KASAN CFLAGS_UBSAN
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN
export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
Expand Down Expand Up @@ -532,6 +530,25 @@ ifneq ($(filter install,$(MAKECMDGOALS)),)
endif
endif

ifeq ($(cc-name),clang)
ifneq ($(CROSS_COMPILE),)
CLANG_TRIPLE ?= $(CROSS_COMPILE)
CLANG_FLAGS += --target=$(notdir $(CLANG_TRIPLE:%-=%))
GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
endif
ifneq ($(GCC_TOOLCHAIN),)
CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
endif
KBUILD_CFLAGS += -Wno-sizeof-pointer-div
CLANG_FLAGS += -no-integrated-as
CLANG_FLAGS += -Werror=unknown-warning-option
KBUILD_CFLAGS += $(CLANG_FLAGS)
KBUILD_AFLAGS += $(CLANG_FLAGS)
endif


ifeq ($(mixed-targets),1)
# ===========================================================================
# We're called with mixed targets (*config and build targets).
Expand Down Expand Up @@ -673,6 +690,7 @@ KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
KBUILD_CFLAGS += $(call cc-disable-warning, int-in-bool-context)
KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
KBUILD_CFLAGS += $(call cc-disable-warning, attribute-alias)

ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
Expand Down Expand Up @@ -780,21 +798,9 @@ endif
KBUILD_CFLAGS += $(stackp-flag)

ifeq ($(cc-name),clang)
ifneq ($(CROSS_COMPILE),)
CLANG_TRIPLE ?= $(CROSS_COMPILE)
CLANG_TARGET := --target=$(notdir $(CLANG_TRIPLE:%-=%))
GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..)
endif
ifneq ($(GCC_TOOLCHAIN),)
CLANG_GCC_TC := --gcc-toolchain=$(GCC_TOOLCHAIN)
endif
KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable)
KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier)
KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
KBUILD_CFLAGS += $(call cc-disable-warning, duplicate-decl-specifier)
# Quiet clang warning: comparison of unsigned expression < 0 is always false
KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare)
Expand All @@ -803,14 +809,11 @@ KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare)
# See modpost pattern 2
KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,)
KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior)
KBUILD_CFLAGS += $(call cc-option, -no-integrated-as)
KBUILD_AFLAGS += $(call cc-option, -no-integrated-as)
else

# These warnings generated too much noise in a regular build.
# Use make W=1 to enable them (see scripts/Makefile.build)
# Use make W=1 to enable them (see scripts/Makefile.extrawarn)
KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
KBUILD_CFLAGS += $(call cc-disable-warning, attribute-alias)
KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
Expand All @@ -823,6 +826,7 @@ KBUILD_CFLAGS += $(call cc-disable-warning, unused-function)
KBUILD_CFLAGS += $(call cc-disable-warning, implicit-function-declaration)
endif

KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
ifdef CONFIG_FRAME_POINTER
KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
else
Expand Down Expand Up @@ -851,10 +855,10 @@ KBUILD_CFLAGS += $(call cc-option, -gdwarf-4,)
endif

ifdef CONFIG_RKP_CFP_JOPP
# Don't use jump tables for switch statements, since this generates indirect jump (br)
# Don't use jump tables for switch statements, since this generates indirect jump (br)
# instructions, which are very dangerous for kernel control flow integrity.
KBUILD_CFLAGS += -fno-jump-tables
endif
endif

ifdef CONFIG_DEBUG_INFO_REDUCED
KBUILD_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) \
Expand Down Expand Up @@ -927,6 +931,18 @@ KBUILD_CFLAGS += $(call cc-option,-Werror=date-time)
# enforce correct pointer usage
KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)

# Require designated initializers for all marked structures
KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init)

# change __FILE__ to the relative path from the srctree
KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)

# ensure -fcf-protection is disabled when using retpoline as it is
# incompatible with -mindirect-branch=thunk-extern
ifdef CONFIG_RETPOLINE
KBUILD_CFLAGS += $(call cc-option,-fcf-protection=none)
endif

# use the deterministic mode of AR if available
KBUILD_ARFLAGS := $(call ar-option,D)

Expand Down
64 changes: 50 additions & 14 deletions apollo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ CR_GCC4=~/Android/Toolchains/aarch64-linux-android-4.9/bin/aarch64-linux-android
CR_GCC9=~/Android/Toolchains/aarch64-linux-gnu-9.x/bin/aarch64-linux-gnu-
CR_GCC12=~/Android/Toolchains/aarch64-linux-gnu-12.x/bin/aarch64-linux-gnu-
CR_GCC13=~/Android/Toolchains/aarch64-linux-gnu-13.x/bin/aarch64-linux-gnu-
CR_CLANG=~/Android/Toolchains/clang-r353983c/bin
CR_CLANG_11=~/Android/Toolchains/clang-r383902-jopp
CR_CLANG_12=~/Android/Toolchains/clang-r416183b
CR_CLANG_14=~/Android/Toolchains/clang-r450784d
CR_CLANG_EXP=~/Android/Toolchains/clang-r522817
#####################################################

# Compiler Selection
Expand All @@ -102,12 +105,42 @@ export CROSS_COMPILE=$CR_GCC13
compile="make"
CR_COMPILER="$CR_GCC13"
fi
if [ $CR_COMPILER = "5" ]; then
export CLANG_PATH=$CR_CLANG
export CROSS_COMPILE=$CR_GCC4
export CLANG_TRIPLE=aarch64-linux-gnu-
compile="make CC=clang ARCH=arm64"
export PATH=${CLANG_PATH}:${PATH}
if [ $CR_COMPILER = "5" ] || [ $CR_COMPILER = "6" ] || [ $CR_COMPILER = "7" ] || [ $CR_COMPILER = "8" ]; then
if [ $CR_COMPILER = "5" ]; then
CR_CLANG=$CR_CLANG_11
elif [ $CR_COMPILER = "6" ]; then
CR_CLANG=$CR_CLANG_12
elif [ $CR_COMPILER = "7" ]; then
CR_CLANG=$CR_CLANG_14
elif [ $CR_COMPILER = "8" ]; then
CR_CLANG=$CR_CLANG_EXP
fi

# Check packages
for pkg in gcc-arm-linux-gnueabi gcc-aarch64-linux-gnu; do
if ! dpkg-query -W -f='${Status}' $pkg | grep "ok installed"; then
echo " $pkg is missing, please install with sudo apt-get install $pkg"
exit 0;
fi
done

export PATH=$CR_CLANG/bin:$CR_CLANG/lib:${PATH}
export CLANG_TRIPLE=$CR_GCC9
export CROSS_COMPILE=$CR_GCC9
export CROSS_COMPILE_ARM32=arm-linux-gnueabi-
export CC=$CR_CLANG/bin/clang
export REAL_CC=$CR_CLANG/bin/clang
export LD=$CR_CLANG/bin/ld.lld
export AR=$CR_CLANG/bin/llvm-ar
export NM=$CR_CLANG/bin/llvm-nm
export OBJCOPY=$CR_CLANG/bin/llvm-objcopy
export OBJDUMP=$CR_CLANG/bin/llvm-objdump
export READELF=$CR_CLANG/bin/llvm-readelf
export STRIP=$CR_CLANG/bin/llvm-strip
export LLVM=1
export LLVM_IAS=1
export ARCH=arm64 && export SUBARCH=arm64
compile="make ARCH=arm64 CC=clang"
CR_COMPILER="$CR_CLANG"
fi
}
Expand Down Expand Up @@ -279,7 +312,7 @@ PACK_BOOT_IMG()
echo " Abort "
fi
# Remove red warning at boot
echo -n "SEANDROIDENFORCE" » $CR_AIK/image-new.img
echo -n "SEANDROIDENFORCE" >> $CR_AIK/image-new.img
# Copy boot.img to Production folder
if [ ! -e $CR_PRODUCT ]; then
mkdir $CR_PRODUCT
Expand Down Expand Up @@ -391,14 +424,14 @@ BUILD_DEBUG(){
echo "----------------------------------------------"
echo " DEBUG : Debug build initiated "
CR_TARGET=5
CR_COMPILER=2
CR_SELINUX=1
CR_COMPILER=8
CR_SELINUX=0
CR_KSU="y"
CR_CLEAN="n"
echo " DEBUG : Set Build options "
echo " DEBUG : Variant : $CR_VARIANT_G965N"
echo " DEBUG : Compiler : $CR_GCC9"
echo " DEBUG : Selinux : $CR_SELINUX Permissive"
echo " DEBUG : Compiler : $CR_CLANG_EXP"
echo " DEBUG : Selinux : $CR_SELINUX Enforcing"
echo " DEBUG : Clean : $CR_CLEAN"
echo "----------------------------------------------"
BUILD
Expand Down Expand Up @@ -508,9 +541,12 @@ echo "1) $CR_GCC4 (GCC 4.9)"
echo "2) $CR_GCC9 (GCC 9.x)"
echo "3) $CR_GCC12 (GCC 12.x)"
echo "4) $CR_GCC13 (GCC 13.x)"
echo "5) $CR_CLANG (CLANG)"
echo "5) $CR_CLANG_11 (Clang 11 - Samsung)"
echo "6) $CR_CLANG_12 (Clang 12)"
echo "7) $CR_CLANG_14 (Clang 14)"
echo "8) $CR_CLANG_EXP (Clang 18)"
echo " "
read -p "Please select your compiler (1-5) > " CR_COMPILER
read -p "Please select your compiler (1-8) > " CR_COMPILER
echo " "
echo "1) Selinux Permissive " "2) Selinux Enforcing"
echo " "
Expand Down
37 changes: 31 additions & 6 deletions arch/arm/include/asm/vdso_datapage.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,53 @@

#include <asm/page.h>

#ifndef _VDSO_WTM_CLOCK_SEC_T
#define _VDSO_WTM_CLOCK_SEC_T
typedef u32 vdso_wtm_clock_nsec_t;
#endif

#ifndef _VDSO_XTIME_CLOCK_SEC_T
#define _VDSO_XTIME_CLOCK_SEC_T
typedef u32 vdso_xtime_clock_sec_t;
#endif

#ifndef _VDSO_RAW_TIME_SEC_T
#define _VDSO_RAW_TIME_SEC_T
typedef u32 vdso_raw_time_sec_t;
#endif

/* Try to be cache-friendly on systems that don't implement the
* generic timer: fit the unconditionally updated fields in the first
* 32 bytes.
*/
struct vdso_data {
u32 seq_count; /* sequence count - odd during updates */
u16 tk_is_cntvct; /* fall back to syscall if false */
u32 tb_seq_count; /* sequence count - odd during updates */
u16 use_syscall; /* fall back to syscall if true */
u16 cs_shift; /* clocksource shift */
u32 xtime_coarse_sec; /* coarse time */
u32 xtime_coarse_nsec;

u32 wtm_clock_sec; /* wall to monotonic offset */
u32 wtm_clock_nsec;
u32 xtime_clock_sec; /* CLOCK_REALTIME - seconds */
u32 cs_mult; /* clocksource multiplier */
/* wall to monotonic offset */
u32 wtm_clock_sec;
vdso_wtm_clock_nsec_t wtm_clock_nsec;
/* CLOCK_REALTIME - seconds */
vdso_xtime_clock_sec_t xtime_clock_sec;
u32 cs_mono_mult; /* clocksource multiplier */

u64 cs_cycle_last; /* last cycle value */
u64 cs_mask; /* clocksource mask */

u64 xtime_clock_snsec; /* CLOCK_REALTIME sub-ns base */
u32 tz_minuteswest; /* timezone info for gettimeofday(2) */
u32 tz_dsttime;

u32 btm_sec; /* monotonic to boot time */
u32 btm_nsec;
/* Raw clocksource multipler */
u32 cs_raw_mult;
/* Raw time */
vdso_raw_time_sec_t raw_time_sec;
u32 raw_time_nsec;
};

union vdso_data_store {
Expand Down
Loading

0 comments on commit b291108

Please sign in to comment.