Add cross-compilation support for android
cover Add cross-compilation support for android
As part of my efforts to port xfstests so it can be used in an Android runtime environment (where running fsstress by hand seems to be the state-of-the-art in file system QA), I needed to make the following changes to xfsprogs so it can be built using cross compilation using Android's bionic C library. Fortunately given XFS's Irix roots, the number of glibc'isms that have kept in was relatively small.
Theodore Ts'o (6):
xfsprogs: define NBBY if not defined by the system header files
xfsprogs: pull in libgen.h to get prototype for basename()
xfsprogs: define and use BUILD_CC in configure.ac for cross
compilation
xfsprogs: avoid use of si_tid in struct xlog_split_item
xfsprogs: use "unsigned short" instead of ushort
xfsprogs: add missing include of <stat.h>
configure.ac | 8 ++++++++ include/builddefs.in | 1 + include/platform_defs.h.in | 5 +++++ include/xfs_inode_buf.h | 4 ++-- include/xfs_log_format.h | 4 ++-- include/xfs_log_recover.h | 2 +- libdisk/evms.c | 1 + libxfs/Makefile | 4 ++-- libxfs/logitem.c | 2 +- libxfs/xfs_ialloc.c | 4 ++-- logprint/log_misc.c | 8 ++++---- 11 files changed, 29 insertions(+), 14 deletions(-)
Signature · 1 line
2.3.0
PATCH 1/6 xfsprogs: define NBBY if not defined by the system header files
Android's bionic libc doesn't define NBBY; this isn't a standard define, and since all modern/sane platforms have 8 bits per byte, use this as a default.
--- include/platform_defs.h.in | 4 ++++ 1 file changed, 4 insertions(+)
include/platform_defs.h.in +4 -0
@@ -178,4 +178,8 @@ typedef unsigned short umode_t; #define max(a,b) (((a)>(b))?(a):(b)) #endif +#ifndef NBBY +#define NBBY 8 +#endif + #endif /* __XFS_PLATFORM_DEFS_H__ */
Signature · 1 line
2.3.0
Re: [PATCH 1/6] xfsprogs: define NBBY if not defined by the system header files
Quoted 5 lines · Theodore Ts'o
Android's bionic libc doesn't define NBBY; this isn't a standard define, and since all modern/sane platforms have 8 bits per byte, use this as a default.
Signed-off-by Theodore Ts'o <[email protected]>
This looks fine, but it'll clash with my patch that changes platform_defs.h so that it's not run through autoconfs m4 anymore.
Otherwise:
PATCH 2/6 xfsprogs: pull in libgen.h to get prototype for basename()
In reply to Theodore Ts'oThe function prototype for basename() is in <libgen.h>, per Posix. Without the the function prototype, the build will throw errors due to the missing prototype.
On glibc, using libgen.h will force the use of Poxis's basename(), instead of glibc's basename() with GNU extensions. However, xfsprogs doesn't depend on any of the GNU extensions, so this is fine.
--- include/platform_defs.h.in | 1 + 1 file changed, 1 insertion(+)
include/platform_defs.h.in +1 -0
@@ -35,6 +35,7 @@ #include <sys/types.h> #include <limits.h> #include <stdbool.h> +#include <libgen.h> #undef HAVE___U32 #ifdef HAVE___U32
Signature · 1 line
2.3.0
Re: [PATCH 2/6] xfsprogs: pull in libgen.h to get prototype for basename()
Looks fine, with the same caveat as the previous patch:
PATCH 3/6 xfsprogs: define and use BUILD_CC in configure.ac for cross compilation
In reply to Theodore Ts'oIn order to support cross-compilation, we need to build gen_crc32table using the C compiler targetted for the build platform, since it is run as part of the build process.
--- configure.ac | 8 ++++++++ include/builddefs.in | 1 + libxfs/Makefile | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-)
configure.ac +8 -0
@@ -8,6 +8,14 @@ AC_PREFIX_DEFAULT(/usr) AC_PROG_LIBTOOL +AC_PROG_CC +if test $cross_compiling = no; then + BUILD_CC="$CC" + AC_SUBST(BUILD_CC) +else + AC_CHECK_PROGS(BUILD_CC, gcc cc) +fi + AC_ARG_ENABLE(shared, [ --enable-shared=[yes/no] Enable use of shared libraries [default=yes]],, enable_shared=yes)
include/builddefs.in +1 -0
@@ -64,6 +64,7 @@ PKG_DOC_DIR = @datadir@/doc/@pkg_name@ PKG_LOCALE_DIR = @datadir@/locale CC = @cc@ +BUILD_CC = @BUILD_CC@ AWK = @awk@ SED = @sed@ TAR = @tar@
libxfs/Makefile +2 -2
@@ -67,7 +67,7 @@ default: crc32selftest ltdepend $(LTLIBRARY) crc32table.h: gen_crc32table.c @echo " [CC] gen_crc32table" - $(Q) $(CC) $(CFLAGS) -o gen_crc32table $< + $(Q) $(BUILD_CC) $(CFLAGS) -o gen_crc32table $< @echo " [GENERATE] $@" $(Q) ./gen_crc32table > crc32table.h
@@ -78,7 +78,7 @@ crc32table.h: gen_crc32table.c # disk. crc32selftest: gen_crc32table.c crc32table.h crc32.c @echo " [TEST] CRC32" - $(Q) $(CC) $(CFLAGS) -D CRC32_SELFTEST=1 crc32.c -o $@ + $(Q) $(BUILD_CC) $(CFLAGS) -D CRC32_SELFTEST=1 crc32.c -o $@ $(Q) ./$@ include $(BUILDRULES)
Signature · 1 line
2.3.0
Re: [PATCH 3/6] xfsprogs: define and use BUILD_CC in configure.ac for cross compilation
Looks fine,
Re: [PATCH 3/6] xfsprogs: define and use BUILD_CC in configure.ac for cross compilation
In reply to Theodore Ts'olibxfs/Makefile default: crc32selftest ltdepend $(LTLIBRARY) · line 70
Quoted 2 lines · Theodore Ts'o <tytso <at> mit.edu> writes:
libxfs/Makefile +1
-1- $(Q) $(CC) $(CFLAGS) -o gen_crc32table $< + $(Q) $(BUILD_CC) $(CFLAGS) -o gen_crc32table $<
Try to cross compile to armv7a, but I hit a compilation failure for gen_crc32table.c:
gcc.real: error: unrecognized command line option '-mfpu=neon' gcc.real: error: unrecognized command line option '-mfloat-abi=hard'
The problem is CFLAGS is set up for the cross compiler (armv7a-cros-linux- gnueabi-gcc) and some options does not work on the native compiler.
(CFLAGS is " -O2 -O2 -pipe -march=armv7-a -mtune=cortex-a15 -mfpu=neon - mfloat-abi=hard -g -fno-exceptions -fno-unwind-tables -fno-asynchronous- unwind-tables")
Looking into defining BUILD_CFLAGS.
Gwendal.
xfsprogs: Add BUILD_CFLAGS for cross compilation
In reply to Theodore Ts'oWhen cross compiling, CFLAGS may contains option for the cros-compiler the host compiler can not handle.
Add BUILD_CFLAGS variable that does not include $OPTIMIZER options.
Signed-off by: Gwendal Grignou <[email protected]>
include/builddefs.in +4 -2
@@ -27,6 +27,7 @@ LOADERFLAGS = @LDFLAGS@ LTLDFLAGS = @LDFLAGS@ CFLAGS = @CFLAGS@ +BUILD_CFLAGS = @BUILD_CFLAGS@ LIBRT = @librt@ LIBUUID = @libuuid@
@@ -151,7 +151,7 @@ endif -GCFLAGS = $(OPTIMIZER) $(DEBUG) \ +GCFLAGS = $(DEBUG) \ -DVERSION=\"$(PKG_VERSION)\" -DLOCALEDIR=\"$(PKG_LOCALE_DIR)\" \ -DPACKAGE=\"$(PKG_NAME)\" -I$(TOPDIR)/include -I$(TOPDIR)/libxfs
@@ -160,7 +160,8 @@ endif # First, Global, Platform, Local CFLAGS -CFLAGS += $(FCFLAGS) $(GCFLAGS) $(PCFLAGS) $(LCFLAGS) +BUILD_CFLAGS += $(FCFLAGS) $(GCFLAGS) $(PCFLAGS) $(LCFLAGS) +CFLAGS += $(FCFLAGS) $(OPTIMIZER) $(GCFLAGS) $(PCFLAGS) $(LCFLAGS) include $(TOPDIR)/include/buildmacros
libxfs/Makefile +2 -2
@@ -111,7 +111,7 @@ crc32table.h: gen_crc32table.c @echo " [CC] gen_crc32table" - $(Q) $(BUILD_CC) $(CFLAGS) -o gen_crc32table $< + $(Q) $(BUILD_CC) $(BUILD_CFLAGS) -o gen_crc32table $< @echo " [GENERATE] $@" $(Q) ./gen_crc32table > crc32table.h
@@ -122,7 +122,7 @@ # disk. crc32selftest: gen_crc32table.c crc32table.h crc32.c @echo " [TEST] CRC32" - $(Q) $(BUILD_CC) $(CFLAGS) -D CRC32_SELFTEST=1 crc32.c -o $@ + $(Q) $(BUILD_CC) $(BUILD_CFLAGS) -D CRC32_SELFTEST=1 crc32.c -o $@ $(Q) ./$@ # set up include/xfs header directory
configure.ac +3 -0
@@ -11,9 +11,12 @@ AC_PROG_CC if test $cross_compiling = no; then BUILD_CC="$CC" + BUILD_CFLAGS="$CFLAGS" AC_SUBST(BUILD_CC) else AC_CHECK_PROGS(BUILD_CC, gcc cc) + BUILD_CFLAGS="-g" fi +AC_SUBST(BUILD_CFLAGS) AC_ARG_ENABLE(shared,
[ --enable-shared=[yes/no] Enable use of shared libraries [default=yes]],,
Christoph Hellwig
Reviewed-byRe: xfsprogs: Add BUILD_CFLAGS for cross compilation
Quoted 3 lines · Gwendal Grignou
When cross compiling, CFLAGS may contains option for the cros-compiler the host compiler can not handle.
AddBUILD_CFLAGSvariable that does not include $OPTIMIZER options.
I would have expected this to be HOST_CFLAGS, but it seems the BUILD_ convention already exists in xfsprogs, so sticking to it looks fine to me.
Re: xfsprogs: Add BUILD_CFLAGS for cross compilation
Looking at xfsprogs-4.5.0, that patch has not been applied. Did it not work? It still applies cleanly on 4.5.
Gwendal.
Quoted 12 lines · Christoph Hellwig
Quoted 1 line · Gwendal Grignou
When cross compiling, CFLAGS may contains option for the cros-compiler
the
Quoted 2 lines
host compiler can not handle.
AddBUILD_CFLAGSvariable that does not include $OPTIMIZER options.I would have expected this to be
HOST_CFLAGS, but it seems theBUILD_convention already exists in xfsprogs, so sticking to it looks fine to me.Reviewed-by Christoph Hellwig <[email protected]>
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: xfsprogs: Add BUILD_CFLAGS for cross compilation
Quoted 2 lines · Gwendal Grignou
Looking at xfsprogs-4.5.0, that patch has not been applied. Did it not work? It still applies cleanly on 4.5.
It probably just got missed by Dave between all the patches on the list. Can you just resend it with my Reviewed-by tag added?
Re: xfsprogs: Add BUILD_CFLAGS for cross compilation
[+Mike]
Sure. Mike suggested improvements (ability to specify the host compiler), and found I did not properly regenerate ./configure. I will resubmit a better patch.
Gwendal.
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Gwendal Grignou
Looking at xfsprogs-4.5.0, that patch has not been applied. Did it not work? It still applies cleanly on 4.5.
It probably just got missed by Dave between all the patches on the list. Can you just resend it with my Reviewed-by tag added?
PATCH 4/6 xfsprogs: avoid use of si_tid in struct xlog_split_item
In reply to Theodore Ts'oIn Android's bionic libc (as well as the Linux kernel's include/uapi/asm-generic/siginfo.h), si_tid is a #define to provide backwards compatibility for the timerid in the siginfo structure. This breaks the compile of logprint/log_misc.c. Change this to be si_xtid in order to avoid a namespace collision
--- logprint/log_misc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
logprint/log_misc.c +3 -3
@@ -76,7 +76,7 @@ char *trans_type[] = {typedef struct xlog_split_item {struct xlog_split_item *si_next;struct xlog_split_item *si_prev; -xlog_tid_t si_tid; +xlog_tid_t si_xtid;int si_skip; }xlog_split_item_t ;
@@ -161,7 +161,7 @@ xlog_print_add_to_trans(xlog_tid_t tid,xlog_split_item_t *item; item = (xlog_split_item_t *)calloc (sizeof (xlog_split_item_t),1 ); - item->si_tid = tid; + item->si_xtid = tid; item->si_skip = skip; item->si_next = split_list; item->si_prev =NULL ;
@@ -183,7 +183,7 @@ xlog_print_find_tid(xlog_tid_t tid, uint was_cont)return 0 ; }while (listp) { -if (listp->si_tid == tid) +if (listp->si_xtid == tid)break ; listp = listp->si_next; }
Signature · 1 line
2.3.0
Re: [PATCH 4/6] xfsprogs: avoid use of si_tid in struct xlog_split_item
Quoted 5 lines · Theodore Ts'o
In Android's bionic libc (as well as the Linux kernel's
include/uapi/asm-generic/siginfo.h),si_tidis a #define to provide backwards compatibility for the timerid in the siginfo structure. This breaks the compile oflogprint/log_misc.c. Change this to besi_xtidin order to avoid a namespace collision
Looks fine,
PATCH 5/6 xfsprogs: use "unsigned short" instead of ushort
In reply to Theodore Ts'oAndroid's bionic libc doesn't define ushort. There isn't a real benefit (other than perhaps conciseness) to use ushort over "unsigned short", and it's only used in a handful of files in xfsprogs. So change over to using unsigned short everywhere.
--- include/xfs_inode_buf.h | 4 ++-- include/xfs_log_format.h | 4 ++-- include/xfs_log_recover.h | 2 +- libxfs/logitem.c | 2 +- libxfs/xfs_ialloc.c | 4 ++-- logprint/log_misc.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-)
include/xfs_inode_buf.h +2 -2
@@ -28,8 +28,8 @@ struct xfs_icdinode;*/ struct xfs_imap {xfs_daddr_t im_blkno;/* starting BB of inode chunk */ -ushort im_len;/* length in BBs of inode chunk */ -ushort im_boffset;/* inode offset in block in bytes */ +unsigned short im_len;/* length in BBs of inode chunk */ +unsigned short im_boffset;/* inode offset in block in bytes */ }; int xfs_imap_to_bp(struct xfs_mount *, struct xfs_trans *,
include/xfs_log_format.h +2 -2
@@ -456,8 +456,8 @@ static inline uint xfs_icdinode_size(int version) typedef struct xfs_buf_log_format { unsigned short blf_type; /* buf log item type indicator */ unsigned short blf_size; /* size of this item */ - ushort blf_flags; /* misc state */ - ushort blf_len; /* number of blocks in this buf */ + unsigned short blf_flags; /* misc state */ + unsigned short blf_len; /* number of blocks in this buf */ __int64_t blf_blkno; /* starting blkno of this buf */ unsigned int blf_map_size; /* used size of data bitmap in words */ unsigned int blf_data_map[XFS_BLF_DATAMAP_SIZE]; /* dirty bitmap */
include/xfs_log_recover.h +1 -1
@@ -52,7 +52,7 @@ typedef struct xlog_recover {struct list_head r_itemq;/* q for items */ } xlog_recover_t; -#define ITEM_TYPE (i) (*(ushort *)(i)->ri_buf[0].i_addr) +#define ITEM_TYPE (i) (*(unsigned short *)(i)->ri_buf[0].i_addr)/* * This is the number of entries in the l_buf_cancel_table used during
libxfs/logitem.c +1 -1
@@ -112,7 +112,7 @@ xfs_buf_item_init( bip->bli_buf = bp; bip->bli_format.blf_type =XFS_LI_BUF ; bip->bli_format.blf_blkno = (__int64_t )XFS_BUF_ADDR (bp); - bip->bli_format.blf_len = (ushort )BTOBB (XFS_BUF_COUNT (bp)); + bip->bli_format.blf_len = (unsigned short )BTOBB (XFS_BUF_COUNT (bp));XFS_BUF_SET_FSPRIVATE (bp, bip); }
libxfs/xfs_ialloc.c +2 -2
@@ -1784,7 +1784,7 @@ xfs_imap( imap->im_blkno =XFS_AGB_TO_DADDR (mp, agno, agbno); imap->im_len =XFS_FSB_TO_BB (mp,1 ); - imap->im_boffset = (ushort)(offset << mp->m_sb.sb_inodelog); + imap->im_boffset = (unsigned short )(offset << mp->m_sb.sb_inodelog);return 0 ; }
@@ -1812,7 +1812,7 @@ out_map: imap->im_blkno =XFS_AGB_TO_DADDR (mp, agno, cluster_agbno); imap->im_len =XFS_FSB_TO_BB (mp, blks_per_cluster); - imap->im_boffset = (ushort)(offset << mp->m_sb.sb_inodelog); + imap->im_boffset = (unsigned short )(offset << mp->m_sb.sb_inodelog);/* * If the inode number maps to a block outside the bounds
logprint/log_misc.c +1 -1
@@ -252,7 +252,7 @@ xlog_print_trans_buffer(xfs_caddr_t *ptr, int len, int *i, int num_ops)xfs_buf_log_format_t lbuf;int size, blen, map_size, struct_size;__be64 x, y; -ushort flags; +unsigned short flags;/* * memmove to ensure 8-byte alignment for the long longs in
Signature · 1 line
2.3.0
Re: [PATCH 5/6] xfsprogs: use "unsigned short" instead of ushort
Quoted 4 lines · Theodore Ts'o
Android's bionic libc doesn't define ushort. There isn't a real benefit (other than perhaps conciseness) to use ushort over "unsigned short", and it's only used in a handful of files in xfsprogs. So change over to using unsigned short everywhere.
For the files shared with the kernel this should go into the kernel first or at least at the same time. Can you also send
a kernel patch to remove all uses of ushort under fs/xfs?
Otherwise looks fine:
PATCH 6/6 xfsprogs: add missing include of <stat.h>
In reply to Theodore Ts'oIn libdisk/evms.c, fields from struct stat are used without including <stat.h>. Apparently stat.h is included indirectly in glibc's header files; not so in Android's bionic libc.
--- libdisk/evms.c | 1 + 1 file changed, 1 insertion(+)
libdisk/evms.c +1 -0
@@ -22,6 +22,7 @@#include <fcntl.h> #include <sys/ioctl.h> #include <sys/sysmacros.h> +#include <sys/stat.h> #include <disk/volume.h> #include "evms.h"
Signature · 1 line
2.3.0
Re: [PATCH 6/6] xfsprogs: add missing include of <stat.h>
This looks fine, but hopefull this file will be gone for the next major release anyway.