summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMike Frysinger <[email protected]>2013-02-04 21:27:40 -0500
committerMatt Turner <[email protected]>2013-07-18 13:55:48 -0700
commit73c9b4b0e05fc66629ba250846948dc55c0e7a0d (patch)
treedf99a60ae90c6cb58a90249541c6fef14ad219c7 /src
parenta48be954ceb250b98fb6ee46d82653532d4e4f2f (diff)
gen_matypes: fix cross-compiling with gcc
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. Reviewed-by: Matt Turner <[email protected]> Signed-off-by: Mike Frysinger <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/mesa/x86-64/Makefile.am10
-rw-r--r--src/mesa/x86/Makefile.am10
-rw-r--r--src/mesa/x86/gen_matypes.c35
3 files changed, 49 insertions, 6 deletions
diff --git a/src/mesa/x86-64/Makefile.am b/src/mesa/x86-64/Makefile.am
index 80e791784ec..b62387d66a0 100644
--- a/src/mesa/x86-64/Makefile.am
+++ b/src/mesa/x86-64/Makefile.am
@@ -33,7 +33,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 21ce3607ae5..167857684b1 100644
--- a/src/mesa/x86/Makefile.am
+++ b/src/mesa/x86/Makefile.am
@@ -33,7 +33,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 80ee61aa891..1e904aa0b13 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 )