From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/4] sandbox: use host system's UBSan library
Date: Mon, 25 Nov 2024 16:09:42 +0100 [thread overview]
Message-ID: <20241125150945.166979-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241125150945.166979-1-a.fatoum@pengutronix.de>
The host system's libubsan is more extensive than what we have and when
building with libfuzzer later, having the functions defined again leads
to linker error due to repeated definitions.
Therefore, let's only use our ubsan functions when we are outside
sandbox.
While at it, we restructure the Makefile a bit to look more like Linux'
and to allow easier extension in future. CFLAGS_UBSAN will now
unconditionally have the enabled options, but this is ok as we only
make use of it when UBSAN is actually enabled.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
lib/Kconfig.ubsan | 3 +++
lib/Makefile | 2 +-
scripts/Makefile.ubsan | 33 ++++++++++++++++++---------------
3 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/lib/Kconfig.ubsan b/lib/Kconfig.ubsan
index 22958f48011e..c04ff3cbb6fd 100644
--- a/lib/Kconfig.ubsan
+++ b/lib/Kconfig.ubsan
@@ -31,6 +31,9 @@ config UBSAN_NO_ALIGNMENT
Disabling this option on architectures that support unaligned
accesses may produce a lot of false positives.
+config UBSAN_STANDALONE
+ def_bool !SANDBOX
+
config UBSAN_ALIGNMENT
def_bool !UBSAN_NO_ALIGNMENT
diff --git a/lib/Makefile b/lib/Makefile
index 41aed121267c..1cf311ebcdb8 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -82,7 +82,7 @@ obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o
obj-$(CONFIG_CRC8) += crc8.o
obj-$(CONFIG_NLS) += nls_base.o
obj-$(CONFIG_FSL_QE_FIRMWARE) += fsl-qe-firmware.o
-obj-$(CONFIG_UBSAN) += ubsan.o
+obj-$(CONFIG_UBSAN_STANDALONE) += ubsan.o
obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o
# GCC library routines
diff --git a/scripts/Makefile.ubsan b/scripts/Makefile.ubsan
index 019771b845c5..4fb30a6c3768 100644
--- a/scripts/Makefile.ubsan
+++ b/scripts/Makefile.ubsan
@@ -1,19 +1,22 @@
# SPDX-License-Identifier: GPL-2.0
-ifdef CONFIG_UBSAN
- CFLAGS_UBSAN += $(call cc-option, -fsanitize=shift)
- CFLAGS_UBSAN += $(call cc-option, -fsanitize=integer-divide-by-zero)
- CFLAGS_UBSAN += $(call cc-option, -fsanitize=unreachable)
- CFLAGS_UBSAN += $(call cc-option, -fsanitize=signed-integer-overflow)
- CFLAGS_UBSAN += $(call cc-option, -fsanitize=bounds)
- CFLAGS_UBSAN += $(call cc-option, -fsanitize=object-size)
- CFLAGS_UBSAN += $(call cc-option, -fsanitize=bool)
- CFLAGS_UBSAN += $(call cc-option, -fsanitize=enum)
+ifdef CONFIG_UBSAN_STANDALONE
+ ubsan-cflags-y += $(call cc-option, -fsanitize=shift)
+ ubsan-cflags-y += $(call cc-option, -fsanitize=integer-divide-by-zero)
+ ubsan-cflags-y += $(call cc-option, -fsanitize=unreachable)
+ ubsan-cflags-y += $(call cc-option, -fsanitize=signed-integer-overflow)
+ ubsan-cflags-y += $(call cc-option, -fsanitize=bounds)
+ ubsan-cflags-y += $(call cc-option, -fsanitize=object-size)
+ ubsan-cflags-y += $(call cc-option, -fsanitize=bool)
+ ubsan-cflags-y += $(call cc-option, -fsanitize=enum)
-ifdef CONFIG_UBSAN_ALIGNMENT
- CFLAGS_UBSAN += $(call cc-option, -fsanitize=alignment)
+ ubsan-cflags-$(CONFIG_UBSAN_ALIGNMENT) += $(call cc-option, -fsanitize=alignment)
+else
+ ubsan-cflags-y += -fsanitize=undefined
+ ubsan-cflags-$(if $(CONFIG_UBSAN_ALIGNMENT),,y) += $(call cc-option, -fno-sanitize=alignment)
endif
- # -fsanitize=* options makes GCC less smart than usual and
- # increase number of 'maybe-uninitialized false-positives
- CFLAGS_UBSAN += $(call cc-option, -Wno-maybe-uninitialized)
-endif
+# -fsanitize=* options makes GCC less smart than usual and
+# increase number of 'maybe-uninitialized false-positives
+ubsan-cflags-y += $(call cc-option, -Wno-maybe-uninitialized)
+
+export CFLAGS_UBSAN := $(ubsan-cflags-y)
--
2.39.5
next prev parent reply other threads:[~2024-11-25 15:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-25 15:09 [PATCH 0/4] add first LLVM/clang support Ahmad Fatoum
2024-11-25 15:09 ` Ahmad Fatoum [this message]
2024-11-25 15:09 ` [PATCH 2/4] common: implement CC_IS_GCC and CC_IS_CLANG symbols Ahmad Fatoum
2024-11-25 15:09 ` [PATCH 3/4] fixdep: sync with Linux Ahmad Fatoum
2024-11-25 15:09 ` [PATCH 4/4] Makefile: add LLVM/clang support Ahmad Fatoum
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=20241125150945.166979-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.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