[coreboot-gerrit] Patch set updated for coreboot: Provide a gcc-safe zero pointer
Patrick Georgi (pgeorgi@google.com)
gerrit at coreboot.org
Wed Jan 27 17:38:14 CET 2016
Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/12294
-gerrit
commit 3fa01f5b580765392ca019d14fadae1e53eaa413
Author: Patrick Georgi <patrick at georgi-clan.de>
Date: Wed Jan 27 08:18:16 2016 +0100
Provide a gcc-safe zero pointer
zeroptr is a linker object pointing at 0 that can be used to thwart
GCC's (and other compilers') "dereferencing NULL is undefined"
optimization strategy when it gets in the way.
Change-Id: I6aa6f28283281ebae73d6349811e290bf1b99483
Signed-off-by: Patrick Georgi <patrick at georgi-clan.de>
---
src/include/stddef.h | 8 ++++++++
src/lib/program.ld | 4 ++++
2 files changed, 12 insertions(+)
diff --git a/src/include/stddef.h b/src/include/stddef.h
index b58f645..35326ed 100644
--- a/src/include/stddef.h
+++ b/src/include/stddef.h
@@ -34,4 +34,12 @@ typedef unsigned int wint_t;
#define MAYBE_STATIC static
#endif
+#ifndef __ROMCC__
+/* Provide a pointer to address 0 that thwarts any "accessing this is
+ * undefined behaviour and do whatever" trickery in compilers.
+ * Use when you _really_ need to read32(zeroptr) (ie. read address 0).
+ */
+extern void *zeroptr;
+#endif
+
#endif /* STDDEF_H */
diff --git a/src/lib/program.ld b/src/lib/program.ld
index 865b5f6..9b8c7c9 100644
--- a/src/lib/program.ld
+++ b/src/lib/program.ld
@@ -133,6 +133,10 @@ _eprogram = .;
/* Discard the sections we don't need/want */
+.zeroptr 0 (NOLOAD) : {
+ zeroptr = .;
+}
+
/DISCARD/ : {
*(.comment)
*(.comment.*)
More information about the coreboot-gerrit
mailing list