From: "Khem Raj" <raj.khem@gmail.com>
To: openembedded-core@lists.openembedded.org
Cc: Khem Raj <raj.khem@gmail.com>
Subject: [PATCH v5 09/11] puzzles: Check for excessive constant arguments
Date: Sun, 8 Nov 2020 16:02:15 -0800 [thread overview]
Message-ID: <20201109000217.3008448-9-raj.khem@gmail.com> (raw)
In-Reply-To: <20201109000217.3008448-1-raj.khem@gmail.com>
Fixes an issue found with LTO builds
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
...Check-for-excessive-values-to-malloc.patch | 49 +++++++++++++++++++
meta/recipes-sato/puzzles/puzzles_git.bb | 1 +
2 files changed, 50 insertions(+)
create mode 100644 meta/recipes-sato/puzzles/files/0001-malloc-Check-for-excessive-values-to-malloc.patch
diff --git a/meta/recipes-sato/puzzles/files/0001-malloc-Check-for-excessive-values-to-malloc.patch b/meta/recipes-sato/puzzles/files/0001-malloc-Check-for-excessive-values-to-malloc.patch
new file mode 100644
index 0000000000..66af6afa2f
--- /dev/null
+++ b/meta/recipes-sato/puzzles/files/0001-malloc-Check-for-excessive-values-to-malloc.patch
@@ -0,0 +1,49 @@
+From 1c01a5bc9ac7f8aaa484b1a8e0e74aa5f8899d0e Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Sun, 8 Nov 2020 11:17:59 -0800
+Subject: [PATCH] malloc: Check for excessive values to malloc
+
+with whole program optimizers like lto smalloc()
+is inlined the excessive constant argument is propagated to
+malloc() and ultimately triggers the warning.
+
+malloc.c:15:9: error: argument 1 range [18446744065119617024, 18446744073709551580] exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
+
+therefore add a check before excessive constant argument before calling
+malloc
+
+Note that this will not happen with normal compile since they happen to
+be in different translation units and compiler can not semantically
+analyze as much
+
+Upstream-Status: Pending
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ malloc.c | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/malloc.c b/malloc.c
+index a7fa7c5..520377c 100644
+--- a/malloc.c
++++ b/malloc.c
+@@ -2,6 +2,7 @@
+ * malloc.c: safe wrappers around malloc, realloc, free, strdup
+ */
+
++#include <stdint.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include "puzzles.h"
+@@ -12,6 +13,8 @@
+ */
+ void *smalloc(size_t size) {
+ void *p;
++ if (size > PTRDIFF_MAX)
++ fatal("exceeds maximum object size");
+ p = malloc(size);
+ if (!p)
+ fatal("out of memory");
+--
+2.29.2
+
diff --git a/meta/recipes-sato/puzzles/puzzles_git.bb b/meta/recipes-sato/puzzles/puzzles_git.bb
index a0f3b5d9cd..8e4d5b3349 100644
--- a/meta/recipes-sato/puzzles/puzzles_git.bb
+++ b/meta/recipes-sato/puzzles/puzzles_git.bb
@@ -14,6 +14,7 @@ SRC_URI = "git://git.tartarus.org/simon/puzzles.git \
file://0001-Use-Wno-error-format-overflow-if-the-compiler-suppor.patch \
file://0001-pattern.c-Change-string-lenght-parameter-to-be-size_.patch \
file://fix-ki-uninitialized.patch \
+ file://0001-malloc-Check-for-excessive-values-to-malloc.patch \
"
UPSTREAM_CHECK_COMMITS = "1"
--
2.29.2
next prev parent reply other threads:[~2020-11-09 0:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-09 0:02 [PATCH v5 01/11] lto: Add global LTO distro policy file Khem Raj
2020-11-09 0:02 ` [PATCH v5 02/11] python3: Enable lto if its in DISTRO_FEATURES Khem Raj
2020-11-09 0:02 ` [PATCH v5 03/11] lto.inc: Add -ffat-lto-objects and -fuse-linker-plugin Khem Raj
2020-11-09 0:02 ` [PATCH v5 04/11] lto: Introduce LTOEXTRA variable Khem Raj
2020-11-09 0:02 ` [PATCH v5 05/11] libaio: Disable LTO Khem Raj
2020-11-09 0:02 ` [PATCH v5 06/11] weston: Fix linking with LTO Khem Raj
2020-11-09 0:02 ` [PATCH v5 07/11] lto.inc: Disable LTO for xserver-xorg Khem Raj
2020-11-09 0:02 ` [PATCH v5 08/11] gcc: Do no parameterize LTO configuration flags Khem Raj
2020-11-09 0:02 ` Khem Raj [this message]
2020-11-09 0:02 ` [PATCH v5 10/11] lto.inc: Disable LTO for perf Khem Raj
2020-11-09 0:02 ` [PATCH v5 11/11] gcc: Handle duplicate names for variables Khem Raj
2020-11-09 8:30 ` [OE-core] [PATCH v5 01/11] lto: Add global LTO distro policy file Andreas Müller
2020-11-09 19:14 ` Khem Raj
2020-11-09 20:18 ` Andreas Müller
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=20201109000217.3008448-9-raj.khem@gmail.com \
--to=raj.khem@gmail.com \
--cc=openembedded-core@lists.openembedded.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