Various patches from GrapheneOS

This commit is contained in:
Tad 2021-06-26 15:17:41 -04:00
parent d6dca6e66d
commit 881c24d8b2
17 changed files with 429 additions and 13 deletions

View file

@ -0,0 +1,26 @@
From f699532069f985837f61c43cd7697869890672ea Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 13 Sep 2016 22:05:56 -0400
Subject: [PATCH] use -fwrapv when signed overflow checking is off
---
core/config_sanitizers.mk | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk
index 70cb456a5..705bcb1ef 100644
--- a/core/config_sanitizers.mk
+++ b/core/config_sanitizers.mk
@@ -308,3 +308,9 @@ ifneq ($(my_sanitize_diag),)
my_shared_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_RUNTIME_LIBRARY)
endif
endif
+
+ifeq ($(filter signed-integer-overflow integer undefined,$(my_sanitize)),)
+ ifeq ($(filter -ftrapv,$(my_cflags)),)
+ my_cflags += -fwrapv
+ endif
+endif
--
2.31.1

View file

@ -0,0 +1,56 @@
From 2b6950b03eb3d8cc82fa2b0a91db480dacf58a78 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Wed, 23 Aug 2017 20:28:03 -0400
Subject: [PATCH] use -fwrapv when signed overflow checking is off
---
cc/cc.go | 2 ++
cc/sanitize.go | 12 ++++++++++++
2 files changed, 14 insertions(+)
diff --git a/cc/cc.go b/cc/cc.go
index 983ffc0..45a50cf 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -533,6 +533,8 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
}
if c.sanitize != nil {
flags = c.sanitize.flags(ctx, flags)
+ } else {
+ flags.CFlags = append(flags.CFlags, "-fwrapv")
}
if c.coverage != nil {
flags = c.coverage.flags(ctx, flags)
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 9c3b8e5..1dbd9fe 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -271,6 +271,7 @@ func (sanitize *sanitize) deps(ctx BaseModuleContext, deps Deps) Deps {
func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
if !sanitize.Properties.SanitizerEnabled {
+ flags.CFlags = append(flags.CFlags, "-fwrapv")
return flags
}
@@ -315,6 +316,17 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
sanitizers = append(sanitizers, sanitize.Properties.Sanitize.Misc_undefined...)
}
+ wrapv := true
+ for _, element := range sanitizers {
+ if (element == "signed-integer-overflow" || element == "integer" || element == "undefined") {
+ wrapv = false
+ break
+ }
+ }
+ if wrapv {
+ flags.CFlags = append(flags.CFlags, "-fwrapv")
+ }
+
if Bool(sanitize.Properties.Sanitize.Diag.Undefined) {
diagSanitizers = append(diagSanitizers, "undefined")
}
--
2.31.1