Bug 50146 - cross compiling apr error: redefinition of 'struct iovec'
Summary: cross compiling apr error: redefinition of 'struct iovec'
Status: NEW
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: HEAD
Hardware: PC Linux
: P1 blocker with 3 votes (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-23 10:05 UTC by Matteo 'Peach' Pescarin
Modified: 2021-02-19 10:19 UTC (History)
4 users (show)



Attachments
Crude patch to configure which demonstrates the issue / direction for a fix (2.26 KB, text/plain)
2021-01-04 18:43 UTC, Michael Driscoll
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matteo 'Peach' Pescarin 2010-10-23 10:05:40 UTC
apr-1.4.2
target architecture is powerpc from a x86_64 machine
I had to add --tag=CC to libtool options, but ended being blocked by this error.


make -j1 
make[1]: Entering directory `/usr/powerpc-unknown-linux-gnu/tmp/portage/dev-libs/apr-1.4.2/work/apr-1.4.2
'
/bin/bash /usr/bin/libtool --silent --tag=CC --mode=compile powerpc-unknown-linux-gnu-gcc   -Os -pipe -mcpu=603e -fno-strict-aliasing -fsigned-char -I/usr/powerpc-unknown-linux-gnu/usr/include/ -I/usr/powerpc-unknown-linux-gnu/include/ -DHAVE_CONFIG_H -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE   -I./include -I/usr/powerpc-unknown-linux-gnu/tmp/portage/dev-libs/apr-1.4.2/work/apr-1.4.2/include/arch/unix -I./include/arch/unix -I/usr/powerpc-unknown-linux-gnu/tmp/portage/dev-libs/apr-1.4.2/work/apr-1.4.2/include/arch/unix -I/usr/powerpc-unknown-linux-gnu/tmp/portage/dev-libs/apr-1.4.2/work/apr-1.4.2/include  -o passwd/apr_getpass.lo -c passwd/apr_getpass.c && touch passwd/apr_getpass.lo
In file included from ./include/apr_strings.h:52,
                 from passwd/apr_getpass.c:23:
./include/apr_want.h:93: error: redefinition of 'struct iovec'
make[1]: *** [passwd/apr_getpass.lo] Error 1
make[1]: Leaving directory `/usr/powerpc-unknown-linux-gnu/tmp/portage/dev-libs/apr-1.4.2/work/apr-1.4.2'

tell me if you need further infos
make: *** [all-recursive] Error 1
Comment 1 Guenter Knauf 2011-02-14 14:37:46 UTC
It seems that the struct iovec is perhaps in another header for powerpc than in sys/uio.h, and configure needs to check for it; from apr_want.h it looks as if APR_HAVE_IOVEC is set to 0, and therefore the definition at line 93 plugs in ...
can you please check the configure log why APR_HAVE_IOVEC was not detected properly, and check your headers for struct iovec where it is defined?
Comment 2 Guenter Knauf 2011-03-28 01:43:11 UTC
(In reply to comment #1)
> can you please check the configure log why APR_HAVE_IOVEC was not detected
> properly, and check your headers for struct iovec where it is defined?
unless you provide more infos we are not able to fix this for your platform ...
I've just commited a change to apr to better protect our own struct iovec definition, but I doubt that this will fix your issue:
http://svn.apache.org/viewvc?rev=1086125&view=rev
this change will be available with next snapshots:
http://svn.apache.org/snapshots/apr-1.4.x/
Comment 3 kirsche40 2012-06-20 08:07:42 UTC
I am using following script to configure APR.


#!/bin/sh
export PATH=/opt/eldk/usr/bin:/opt/eldk/bin:$PATH
export CROSS_COMPILE=ppc_82xx-
export  CC=ppc_82xx-gcc
export  LD=ppc_82xx-ld
export  CXX=ppc_82xx-g++
export  AR=ppc_82xx-ar
export  CPP=ppc_82xx-cpp
export  STRIP=ppc_82xx-strip
./configure  \
	--host=ppc-linux \
	--target=ppc-linux \
	--prefix=/opt/eldk/ppc_82xx/usr \
	--build=i686-cross-linux-gnu \
	ac_cv_file__dev_zero=no \
	ac_cv_func_setpgrp_void=no \
	apr_cv_tcp_nodelay_with_cork=no \
	cross_compiling=yes \
	apr_cv_process_shared_works=no



The additional variables set to no are necessary because I get all times a configure error becuase of cross compiling like

checking for /dev/zero... configure: error: cannot check for file existence when cross compiling 


When I start make I get the following lines:

jddev@m101n11ech:~/Downloads/apr-1.4.6$ make
make[1]: Entering directory `/home/jddev/Downloads/apr-1.4.6'
/bin/bash /home/jddev/Downloads/apr-1.4.6/libtool --silent --mode=compile ppc_82xx-gcc -g -O2   -DHAVE_CONFIG_H -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE   -I./include -I/home/jddev/Downloads/apr-1.4.6/include/arch/unix -I./include/arch/unix -I/home/jddev/Downloads/apr-1.4.6/include/arch/unix -I/home/jddev/Downloads/apr-1.4.6/include  -o passwd/apr_getpass.lo -c passwd/apr_getpass.c && touch passwd/apr_getpass.lo
In file included from include/apr_strings.h:52,
                 from passwd/apr_getpass.c:23:
include/apr_want.h:95: redefinition of `struct iovec'
make[1]: *** [passwd/apr_getpass.lo] Fehler 1
make[1]: Leaving directory `/home/jddev/Downloads/apr-1.4.6'
make: *** [all-recursive] Fehler 1
jddev@m101n11ech:~/Downloads/apr-1.4.6$
Comment 4 kirsche40 2012-06-20 08:12:48 UTC
Sorry, I forgot some information. I am using Denx ELDK 3.0 (www.denx.de) for cross compiling. This toolchain is rather old but can not be changed for product maintenance reasons.
Comment 5 kirsche40 2012-06-20 10:44:42 UTC
New information. I am through apr and aprutils compilation. I used following files for build:

=============
 APR
=============
#!/bin/sh
export PATH=/opt/eldk/usr/bin:/opt/eldk/bin:$PATH
export ARCH=powerpc
export CROSS_COMPILE=ppc_82xx-
export CC=ppc_82xx-gcc
export LD=ppc_82xx-ld
export CXX=ppc_82xx-g++
export AR=ppc_82xx-ar
export CPP=ppc_82xx-cpp
export STRIP=ppc_82xx-strip
./configure  \
	--host=ppc-linux \
	--target=ppc-linux \
	--prefix=/opt/eldk/ppc_82xx/usr \
	--build=i686-cross-linux-gnu \
	--disable-libtool-lock \
	--disable-lfs \
	--disable-dso \
	--disable-ipv6 \
	--with-gnu-ld \
	ac_cv_file__dev_zero=no \
	ac_cv_func_setpgrp_void=no \
	apr_cv_tcp_nodelay_with_cork=no \
	cross_compiling=yes \
	apr_cv_process_shared_works=no \
	ac_cv_sizeof_struct_iovec=1


=============
 APR Utils
=============
#!/bin/sh
export PATH=/opt/eldk/usr/bin:/opt/eldk/bin:$PATH
export ARCH=powerpc
export CROSS_COMPILE=ppc_82xx-
export CC=ppc_82xx-gcc
export LD=ppc_82xx-ld
export CXX=ppc_82xx-g++
export AR=ppc_82xx-ar
export CPP=ppc_82xx-cpp
export STRIP=ppc_82xx-strip
./configure  \
	--host=ppc-linux \
	--target=ppc-linux \
	--prefix=/opt/eldk/ppc_82xx/usr \
	--build=i686-cross-linux-gnu \
	--disable-util-dso \
	--with-apr=/opt/eldk/ppc_82xx/usr
Comment 6 kirsche40 2012-12-21 10:01:47 UTC
Now I tried to compile the lib with a new cross-compiler (denx ELDK 5.1) and this mess breaks again:

In file included from ./include/apr_strings.h:52:0,
                 from passwd/apr_getpass.c:23:
./include/apr_want.h:94:8: error: redefinition of 'struct iovec'
/opt/eldk-5.1/powerpc/sysroots/powerpc-linux/opt/eldk-5.1/powerpc/sysroots/powerpc-linux/usr/include/bits/uio.h:44:8: note: originally defined here
make[1]: *** [passwd/apr_getpass.lo] Error 1

I do not want to search workarounds for this crappy piece of SW anymore.

Because this bug is rather old and the library is still unusable I set the bug importance to P1 and to blocker.
Comment 7 Dennis Herbrich 2017-03-15 10:18:52 UTC
I have encountered this problem recently in my attempt to cross-compile APR 1.5.2 for an x86 platform, with no option to "just compile it natively". The essential workaround I used, after tracing the configure script and include files, was defining APR_IOVEC_DEFINED in the CPPFLAGS passed in the environment of my ./configure call. See the excerpt of the apr_want.h include file below.

sha256sum of source tarball:
7d03ed29c22a7152be45b8e50431063736df9e1daa1ddf93f6a547ba7a28f67a

File apr-1.5.2/include/apr_want.h:80 in apr-1.5.2.tar.bz2:
/* --------------------------------------------------------------------- */

#ifdef APR_WANT_IOVEC

#if APR_HAVE_IOVEC

#if APR_HAVE_SYS_UIO_H
#include <sys/uio.h>
#endif

#else

#ifndef APR_IOVEC_DEFINED
#define APR_IOVEC_DEFINED
struct iovec
{
    void *iov_base;
    size_t iov_len;
};
#endif /* !APR_IOVEC_DEFINED */

#endif /* APR_HAVE_IOVEC */

#undef APR_WANT_IOVEC
#endif

/* --------------------------------------------------------------------- */

Naturally, I also needed a bunch of ac_cv_ and apr_cv_ variables to give hints to the configure script. These may be different for your target. To sum it up, my ./configure call essentially looked like this:

ac_cv_file__dev_zero=yes \
ac_cv_sizeof_size_t=4 \
ac_cv_sizeof_ssize_t=4 \
ac_cv_struct_rlimit=yes \
apr_cv_mutex_robust_shared=no \
apr_cv_process_shared_works=yes \
apr_cv_pthreads_lib="-lpthread" \
apr_cv_tcp_nodelay_with_cork=yes \
CPPFLAGS="-DAPR_IOVEC_DEFINED" ./configure <irrelevant options>

Good luck. May these problems in the Apache *PORTABLE* Runtime library be fixed one glorious day.
Comment 8 Michael Driscoll 2021-01-04 18:43:40 UTC
Created attachment 37685 [details]
Crude patch to configure which demonstrates the issue / direction for a fix

Hello!  We had this same problem with our product's usage of APR, and worked out what the issue was.

I've attached the temporary workaround patch that we're using in the meantime, I know this isn't the correct way to fix it (which will involve something like updating autoconf / autotools, and/or tweaking configure.in, which are both beyond my ken).  But to summarize the problem / patch:

- In several places `configure` compiles a program like the following to find the size of a given struct:

    fprintf(f, "%d", sizeof(foo));

This fails on newer macos / xcode / clang, because it generates a fatal warning ("%d" is not a portable specifier for a size_t).  This patch tweaks all of these uses to use the "%zd" specifier instead.  It would be even more portable to cast sizeof to (int) instead.

This particular fix is the fix for iovec, without this configure assumes that "struct iovec" does not exist in system headers, causing the duplicate/incompatible definition that then fails the compile.

- In other places `configure` is compiling programs that call `exit(1)` without including <stdlib.h>.  I fixed this by also adding $ac_includes_default to any programs calling `exit()`.  This might not be a problem in up-to-date apr (we could be versions behind, I haven't checked), but it caused a compile failure for us so I'm including it in this patch as an FYI.
Comment 9 Michael Driscoll 2021-01-04 18:56:07 UTC
Tweak to comment #8: the <stdlib.h> angle seems to be bug 64753, the report in that bug overlaps with this one.

bug #50146: "error: redefinition of 'iovec'"
bug #64753: "Can not determine the proper size for pid_t"

on newer xcode / macos both are occurring.
Comment 10 Khalifa 2021-02-19 10:19:01 UTC
Add