[flashrom] [PATCH] Makefile: Print data model of C types.

Stefan Tauner stefan.tauner at student.tuwien.ac.at
Sat Jul 20 17:36:19 CEST 2013


Since we are starting to support more data models and are reworking
some core data types in flashrom, it might become useful to know the
size of some types, hence print them at compile and run time.

Because compilers do not define suitable macros for this purpose, we
implement our own in arch.h and the Makefile. Because sizeof is not
evaluated by the CPP, the implementation uses macros from limits.h,
stdint.h and hardcoded constants.
See also http://sourceforge.net/p/predef/wiki/DataModels/

Also, simplify the __FLASHROM_ARCH__ generation and parsing, and
refine sysinfo printing if uname is unavailable.

New output w/o uname:
flashrom v0.9.6.1-r1701 on Windows 5.1 (x86 ILP32)
flashrom v0.9.6.1-r1701 on Windows 5.1 (x86_64 LLP64)
flashrom v0.9.6.1-r1701 on unknown OS (arm ILP32)
flashrom v0.9.6.1-r1701 on unknown OS (ppc ILP32)
flashrom v0.9.6.1-r1701 on unknown OS (x86 LP64)
flashrom v0.9.6.1-r1701 on unknown OS (x86 ILP32)

w/ uname:
flashrom v0.9.6.1-r1701 on Windows 5.1 (x86 ILP32)
flashrom v0.9.6.1-r1701 on Windows 5.1 (x86_64 LLP64)
flashrom v0.9.6.1-r1701 on Linux 2.6.32 (armv7l ILP32)
flashrom v0.9.6.1-r1701 on Linux 2.6.32 (ppc ILP32)
flashrom v0.9.6.1-r1701 on Linux 3.8.0-6-generic (x86_64 LP64)
flashrom v0.9.6.1-r1701 on Linux 3.8.0-6-generic (x86_64 ILP32)

Handcrafted "unknown" example:
flashrom v0.9.6.1-r1701 on Linux 3.8.0-6-generic (x86_64 unknown data model)

Signed-off-by: Stefan Tauner <stefan.tauner at student.tuwien.ac.at>
---
 Makefile   |  9 +++++++--
 arch.h     | 22 +++++++++++++++++++++-
 flashrom.c | 19 ++++++++++---------
 3 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile
index 0cd4e75..5e54c9f 100644
--- a/Makefile
+++ b/Makefile
@@ -267,7 +267,12 @@ endif
 # IMPORTANT: The following line must be placed before ARCH is ever used
 # (of course), but should come after any lines setting CC because the line
 # below uses CC itself.
-override ARCH := $(strip $(shell LC_ALL=C $(CC) $(CPPFLAGS) -E arch.h 2>/dev/null | grep -v '^\#' | grep '"' | cut -f 2 -d'"'))
+override ARCH := $(shell LC_ALL=C $(CC) $(CPPFLAGS) -E arch.h 2>/dev/null | grep '"__FLASHROM_ARCH__"' | cut -f 4 -d'"')
+FLASHROM_CFLAGS += -D'FLASHROM_ARCH="$(ARCH)"'
+
+# As above but for the C data model
+override DATAMODEL := $(shell LC_ALL=C $(CC) $(CPPFLAGS) -E arch.h 2>/dev/null | grep '"__FLASHROM_DATAMODEL__"' | cut -f 4 -d'"')
+FLASHROM_CFLAGS += -D'FLASHROM_DATAMODEL="$(DATAMODEL)"'
 
 # PCI port I/O support is unimplemented on PPC/MIPS and unavailable on ARM.
 # Right now this means the drivers below only work on x86.
@@ -692,7 +697,7 @@ compiler: featuresavailable
 	@# FreeBSD wc will output extraneous whitespace.
 	@echo $(ARCH)|wc -w|grep -q '^[[:blank:]]*1[[:blank:]]*$$' ||	\
 		( echo "unknown. Aborting."; exit 1)
-	@printf "%s\n" '$(ARCH)'
+	@printf "%s %s\n" '$(ARCH)' '$(DATAMODEL)'
 	@printf "Target OS is "
 	@# FreeBSD wc will output extraneous whitespace.
 	@echo $(TARGET_OS)|wc -w|grep -q '^[[:blank:]]*1[[:blank:]]*$$' ||	\
diff --git a/arch.h b/arch.h
index f3f3b0d..1ed13fb 100644
--- a/arch.h
+++ b/arch.h
@@ -21,6 +21,25 @@
  * Header file for CPU architecture checking.
  */
 
+#include <limits.h>
+#include <stdint.h>
+#define __16b 0xFFFFULL
+#define __32b 0xFFFFFFFFULL
+#define __64b 0xFFFFFFFFFFFFFFFFULL
+#if   (UINT_MAX == __16b && ULONG_MAX == __32b && UINTPTR_MAX == __32b)
+#define __FLASHROM_DATAMODEL__ "LP32"
+#elif (UINT_MAX == __32b && ULONG_MAX == __32b && UINTPTR_MAX == __32b)
+#define __FLASHROM_DATAMODEL__ "ILP32"
+#elif (UINT_MAX == __32b && ULONG_MAX == __32b && UINTPTR_MAX == __64b)
+#define __FLASHROM_DATAMODEL__ "LLP64"
+#elif (UINT_MAX == __32b && ULONG_MAX == __64b && UINTPTR_MAX == __64b)
+#define __FLASHROM_DATAMODEL__ "LP64"
+#elif (UINT_MAX ==  8 && ULONG_MAX == __64b && UINTPTR_MAX == __64b)
+#define __FLASHROM_DATAMODEL__ "ILP64"
+#else
+#define __FLASHROM_DATAMODEL__ "unknown data model"
+#endif
+
 #if defined (__i386__) || defined (__x86_64__)
 #define __FLASHROM_ARCH__ "x86"
 #elif defined (__mips) || defined (__mips__) || defined (_mips) || defined (mips)
@@ -30,4 +49,5 @@
 #elif defined(__arm__)
 #define __FLASHROM_ARCH__ "arm"
 #endif
-__FLASHROM_ARCH__
+"__FLASHROM_ARCH__"=__FLASHROM_ARCH__
+"__FLASHROM_DATAMODEL__"=__FLASHROM_DATAMODEL__
diff --git a/flashrom.c b/flashrom.c
index b05faf3..8a9b185 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -1578,40 +1578,41 @@ void list_programmers_linebreak(int startcol, int cols, int paren)
 
 void print_sysinfo(void)
 {
+msg_ginfo(" on ");
 #ifdef _WIN32
 	SYSTEM_INFO si;
 	OSVERSIONINFOEX osvi;
 
 	memset(&si, 0, sizeof(SYSTEM_INFO));
 	memset(&osvi, 0, sizeof(OSVERSIONINFOEX));
-	msg_ginfo(" on Windows");
+	msg_ginfo("Windows ");
 	/* Tell Windows which version of the structure we want. */
 	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
 	if (GetVersionEx((OSVERSIONINFO*) &osvi))
-		msg_ginfo(" %lu.%lu", osvi.dwMajorVersion, osvi.dwMinorVersion);
+		msg_ginfo("%lu.%lu", osvi.dwMajorVersion, osvi.dwMinorVersion);
 	else
-		msg_ginfo(" unknown version");
+		msg_ginfo("unknown version");
 	GetSystemInfo(&si);
 	switch (si.wProcessorArchitecture) {
 	case PROCESSOR_ARCHITECTURE_AMD64:
-		msg_ginfo(" (x86_64)");
+		msg_ginfo(" (x86_64");
 		break;
 	case PROCESSOR_ARCHITECTURE_INTEL:
-		msg_ginfo(" (x86)");
+		msg_ginfo(" (x86");
 		break;
 	default:
-		msg_ginfo(" (unknown arch)");
+		msg_ginfo(" (unknown arch");
 		break;
 	}
 #elif HAVE_UTSNAME == 1
 	struct utsname osinfo;
 
 	uname(&osinfo);
-	msg_ginfo(" on %s %s (%s)", osinfo.sysname, osinfo.release,
-		  osinfo.machine);
+	msg_ginfo("%s %s (%s", osinfo.sysname, osinfo.release, osinfo.machine);
 #else
-	msg_ginfo(" on unknown machine");
+	msg_ginfo("unknown OS (" FLASHROM_ARCH);
 #endif
+	msg_ginfo(" " FLASHROM_DATAMODEL ")");
 }
 
 void print_buildinfo(void)
-- 
Kind regards, Stefan Tauner





More information about the flashrom mailing list