[Mesa-dev] [PATCH] gen_matypes: fix cross-compiling with gcc
Mike Frysinger
vapier at gentoo.org
Mon Feb 4 18:27:40 PST 2013
The current gen_matypes logic assumes that the host compiler will produce
information that is useful for the target compiler. Unfortunately, this
is not the case whenever cross-compiling.
When we detect that we're cross-compiling and using GCC, use the target
compiler to produce assembly from the gen_matypes.c source, then process
it with a shell script to create a usable header. This is similar to how
the linux kernel creates its asm-offsets.c file.
Signed-off-by: Mike Frysinger <vapier at gentoo.org>
---
configure.ac | 6 ++++++
src/mesa/x86-64/Makefile.am | 10 ++++++++++
src/mesa/x86/Makefile.am | 10 ++++++++++
src/mesa/x86/gen_matypes.c | 35 +++++++++++++++++++++++++++++------
4 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/configure.ac b/configure.ac
index abfe3d7..3e34da6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -98,6 +98,7 @@ AC_MSG_RESULT([$acv_mesa_CLANG])
dnl If we're using GCC, make sure that it is at least version 3.3.0. Older
dnl versions are explictly not supported.
+GEN_ASM_OFFSETS=no
if test "x$GCC" = xyes -a "x$acv_mesa_CLANG" = xno; then
AC_MSG_CHECKING([whether gcc version is sufficient])
major=0
@@ -115,7 +116,12 @@ if test "x$GCC" = xyes -a "x$acv_mesa_CLANG" = xno; then
else
AC_MSG_RESULT([yes])
fi
+
+ if test "x$cross_compiling" = xyes; then
+ GEN_ASM_OFFSETS=yes
+ fi
fi
+AM_CONDITIONAL([GEN_ASM_OFFSETS], test "x$GEN_ASM_OFFSETS" = xyes)
dnl Make sure the pkg-config macros are defined
m4_ifndef([PKG_PROG_PKG_CONFIG],
diff --git a/src/mesa/x86-64/Makefile.am b/src/mesa/x86-64/Makefile.am
index baeb4b6..809cbaa 100644
--- a/src/mesa/x86-64/Makefile.am
+++ b/src/mesa/x86-64/Makefile.am
@@ -34,7 +34,17 @@ gen_matypes_SOURCES = ../x86/gen_matypes.c
BUILT_SOURCES = matypes.h
CLEANFILES = matypes.h
+if GEN_ASM_OFFSETS
+
+matypes.h: $(gen_matypes_SOURCES)
+ $(AM_V_GEN)$(COMPILE) $< -DASM_OFFSETS -S -o - | \
+ sed -n '/^->/{s:^->::;/[$$]/{s:^:#define :;s:[$$]::};p}' > $@
+
+else
+
matypes.h: gen_matypes
$(AM_V_GEN)./gen_matypes > $@
endif
+
+endif
diff --git a/src/mesa/x86/Makefile.am b/src/mesa/x86/Makefile.am
index 5976bb4..93c1698 100644
--- a/src/mesa/x86/Makefile.am
+++ b/src/mesa/x86/Makefile.am
@@ -34,7 +34,17 @@ gen_matypes_SOURCES = gen_matypes.c
BUILT_SOURCES = matypes.h
CLEANFILES = matypes.h
+if GEN_ASM_OFFSETS
+
+matypes.h: $(gen_matypes_SOURCES)
+ $(AM_V_GEN)$(COMPILE) $< -DASM_OFFSETS -S -o - | \
+ sed -n '/^->/{s:^->::;/[$$]/{s:^:#define :;s:[$$]::};p}' > $@
+
+else
+
matypes.h: gen_matypes
$(AM_V_GEN)./gen_matypes > $@
endif
+
+endif
diff --git a/src/mesa/x86/gen_matypes.c b/src/mesa/x86/gen_matypes.c
index 61f181c..825fb67 100644
--- a/src/mesa/x86/gen_matypes.c
+++ b/src/mesa/x86/gen_matypes.c
@@ -52,7 +52,7 @@ do { \
printf( "\n" ); \
printf( "/* =====================================================" \
"========\n" ); \
- printf( " * Offsets for %s\n", x ); \
+ printf( " * Offsets for " x "\n" ); \
printf( " */\n" ); \
printf( "\n" ); \
} while (0)
@@ -61,20 +61,43 @@ do { \
do { \
printf( "\n" ); \
printf( "/*\n" ); \
- printf( " * Flags for %s\n", x ); \
+ printf( " * Flags for " x "\n" ); \
printf( " */\n" ); \
printf( "\n" ); \
} while (0)
-#define OFFSET( s, t, m ) \
- printf( "#define %s\t%lu\n", s, (unsigned long) offsetof( t, m ) );
+#ifdef ASM_OFFSETS
-#define SIZEOF( s, t ) \
- printf( "#define %s\t%lu\n", s, (unsigned long) sizeof(t) );
+/*
+ * Format the asm output in a special way that we can manipulate
+ * after the fact and turn into the final header for the target.
+ */
+
+#define DEFINE_UL( s, ul ) \
+ __asm__ __volatile__ ( "\n->" s " %0" : : "i" (ul) )
+
+#define DEFINE( s, d ) \
+ DEFINE_UL( s, d )
+
+#define printf( x ) \
+ __asm__ __volatile__ ( "\n->" x )
+
+#else
+
+#define DEFINE_UL( s, ul ) \
+ printf( "#define %s\t%lu\n", s, (unsigned long) (ul) );
#define DEFINE( s, d ) \
printf( "#define %s\t0x%" PRIx64 "\n", s, (uint64_t) d );
+#endif
+
+#define OFFSET( s, t, m ) \
+ DEFINE_UL( s, offsetof( t, m ) )
+
+#define SIZEOF( s, t ) \
+ DEFINE_UL( s, sizeof(t) )
+
int main( int argc, char **argv )
--
1.8.0.2
More information about the mesa-dev
mailing list