Re: [PATCH] MIPS: fix native build

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Mar 08, 2015 at 02:04:19PM +0800, Yu Chen wrote:
> Can crash for Mips be cross compiled? say,compile a mips binary on a
> x86_64 machine?

This is not something that is currently supported (and it's not specific
to the MIPS support; it's the same for the other arches.)

But, as I mentioned earlier in another thread[1], I do have a local
patch which allows this.  It's attached.

[1] https://www.redhat.com/archives/crash-utility/2015-January/msg00028.html
>From 8a33ca315a7098e551a110c3d355ddb7df6e5159 Mon Sep 17 00:00:00 2001
From: Rabin Vincent <rabin@xxxxxx>
Date: Sun, 8 Mar 2015 15:10:16 +0100
Subject: [PATCH] Cross compile for big-endian MIPS

Note! Hard-coded paths, edit for your own use.

$ make -f Makefile.cross
$ CC=mips-buildroot-linux-gnu-gcc make host=mips target=mips
---
 CFLAGS.extra   |  1 +
 GDBFLAGS.extra |  1 +
 LDFLAGS.extra  |  1 +
 Makefile       |  8 ++++++--
 Makefile.cross | 38 ++++++++++++++++++++++++++++++++++++++
 configure.c    |  9 ++++++++-
 6 files changed, 55 insertions(+), 3 deletions(-)
 create mode 100644 CFLAGS.extra
 create mode 100644 GDBFLAGS.extra
 create mode 100644 LDFLAGS.extra
 create mode 100644 Makefile.cross

diff --git a/CFLAGS.extra b/CFLAGS.extra
new file mode 100644
index 0000000..09ae6f2
--- /dev/null
+++ b/CFLAGS.extra
@@ -0,0 +1 @@
+-static -I/home/rabin/dev/crash/cross/include -static -I/home/rabin/dev/crash/cross/include/ncurses/
diff --git a/GDBFLAGS.extra b/GDBFLAGS.extra
new file mode 100644
index 0000000..21b1cce
--- /dev/null
+++ b/GDBFLAGS.extra
@@ -0,0 +1 @@
+--host mips-buildroot-linux-gnu
diff --git a/LDFLAGS.extra b/LDFLAGS.extra
new file mode 100644
index 0000000..1f25690
--- /dev/null
+++ b/LDFLAGS.extra
@@ -0,0 +1 @@
+-static -L/home/rabin/dev/crash/cross/lib
diff --git a/Makefile b/Makefile
index 3c38ff5..ee6f3b8 100644
--- a/Makefile
+++ b/Makefile
@@ -215,6 +215,10 @@ ifneq ($(target),)
 CONF_TARGET_FLAG="-t$(target)"
 endif
 
+ifneq ($(host),)
+CONF_TARGET_FLAG+="-h$(host)"
+endif
+
 # To build the extensions library by default, uncomment the third command
 # line below.  Otherwise they can be built by entering "make extensions".
 
@@ -230,7 +234,7 @@ gdb_merge: force
 	@echo "../../${PROGRAM} ../../${PROGRAM}lib.a" > ${GDB}/gdb/mergeobj
 	@rm -f ${PROGRAM}
 	@if [ ! -f ${GDB}/config.status ]; then \
-	  (cd ${GDB}; ./configure ${GDB_CONF_FLAGS} --with-separate-debug-dir=/usr/lib/debug \
+	  (cd ${GDB}; ./configure CFLAGS="${TARGET_CFLAGS}" LDFLAGS="${LDFLAGS}" ${GDB_CONF_FLAGS} --with-separate-debug-dir=/usr/lib/debug \
 	    --with-bugurl="" --with-expat=no --with-python=no; \
 	  make --no-print-directory CRASH_TARGET=${TARGET}; echo ${TARGET} > crash.target) \
 	else make --no-print-directory rebuild; fi
@@ -280,7 +284,7 @@ force:
 
 make_configure: force
 	@rm -f configure
-	@${CC} ${CONF_FLAGS} -o configure configure.c ${WARNING_ERROR} ${WARNING_OPTIONS}
+	@cc ${CONF_FLAGS} -o configure configure.c ${WARNING_ERROR} ${WARNING_OPTIONS}
 
 clean: make_configure
 	@./configure ${CONF_TARGET_FLAG} -q -b
diff --git a/Makefile.cross b/Makefile.cross
new file mode 100644
index 0000000..afcd135
--- /dev/null
+++ b/Makefile.cross
@@ -0,0 +1,38 @@
+ZLIB=zlib-1.2.8
+TERMCAP=termcap-1.3.1
+NCURSES=ncurses-5.9
+
+CROSS_COMPILE=mips-buildroot-linux-gnu
+PREFIX=$(realpath cross)
+
+CC=${CROSS_COMPILE}-gcc
+export CC
+
+all: cross/lib/libz.a cross/lib/libtermcap.a cross/lib/libncurses.a
+
+cross:
+	mkdir -p $@
+
+${NCURSES}.tar.gz:
+	wget http://ftp.gnu.org/pub/gnu/ncurses/${NCURSES}.tar.gz
+
+${TERMCAP}.tar.gz:
+	wget ftp://ftp.gnu.org/gnu/termcap/${TERMCAP}.tar.gz
+
+${ZLIB}.tar.gz:
+	wget http://zlib.net/${ZLIB}.tar.gz
+
+cross/lib/libncurses.a: ${NCURSES}.tar.gz cross
+	tar xzf $<
+	cd ${NCURSES} && ./configure --host=${CROSS_COMPILE} --prefix=${PREFIX}
+	${MAKE} -C ${NCURSES} install
+
+cross/lib/libtermcap.a: ${TERMCAP}.tar.gz cross
+	tar xzf $<
+	cd ${TERMCAP} && ./configure --host=${CROSS_COMPILE} --prefix=${PREFIX}
+	${MAKE} -C ${TERMCAP} install
+
+cross/lib/libz.a: ${ZLIB}.tar.gz cross
+	tar xzf $<
+	cd ${ZLIB} && ./configure --prefix=${PREFIX}
+	${MAKE} -C ${ZLIB} install
diff --git a/configure.c b/configure.c
index a5167db..a06fa4a 100644
--- a/configure.c
+++ b/configure.c
@@ -258,6 +258,7 @@ struct target_data {
 	char release[MAXSTRLEN];
 	struct stat statbuf;
 	const char *target_as_param;
+	const char *host_as_param;
 } target_data = { 0 }; 
 
 int
@@ -268,7 +269,7 @@ main(int argc, char **argv)
 
 	sp = setup_gdb_defaults();
 
-	while ((c = getopt(argc, argv, "gsqnWwubdr:p:P:t:x:")) > 0) {
+	while ((c = getopt(argc, argv, "gsqnWwubdr:p:P:t:x:h:")) > 0) {
 		switch (c) {
 		case 'q':
 			target_data.flags |= QUIET;
@@ -304,6 +305,9 @@ main(int argc, char **argv)
 		case 't':
 			target_data.target_as_param = optarg;
 			break;
+		case 'h':
+			target_data.host_as_param = optarg;
+			break;
 		case 'x':
 			add_extra_lib(optarg);
 			break;
@@ -379,6 +383,9 @@ get_current_configuration(struct supported_gdb_version *sp)
         target_data.target = MIPS;
 #endif
 
+	if (target_data.host_as_param)
+		target_data.target = name_to_target((char *)target_data.host_as_param);
+
 	set_initial_target(sp);
 
         /* 
-- 
2.1.4

--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux