Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 61599 - Porting: libpcap
Summary: Porting: libpcap
Status: RESOLVED LATER
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: PPC All
: High normal (vote)
Assignee: osx porters
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 63831
  Show dependency tree
 
Reported: 2004-08-24 21:48 UTC by stevenschlansker
Modified: 2005-01-23 12:58 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
libpcap-macos.patch (libpcap-macos.patch,410 bytes, patch)
2004-09-05 14:46 UTC, Robin Munn
Details | Diff
libpcap-0.8.3-r1.ebuild.patch (libpcap-0.8.3-r1.ebuild.patch,1.68 KB, patch)
2004-09-05 14:48 UTC, Robin Munn
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description stevenschlansker 2004-08-24 21:48:39 UTC
It looks fairly easy to fix; but I don't have the know-how.  I'm impressed with how well portage actually works - the fact that it even looks like it's working ;)
Keep up the great work guys!


>>> md5 src_uri ;-) libpcap-0.8.3.tar.gz
>>> Unpacking source...
>>> Unpacking libpcap-0.8.3.tar.gz to /var/tmp/portage/libpcap-0.8.3-r1/work
 * Applying libpcap-0.8.1-fPIC.patch...                                                                                                       [ ok ]
>>> Source unpacked.
./configure --prefix=/usr --host=powerpc-apple-darwin --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib --disable-ipv6
configure: WARNING: If you wanted to set the --build type, don't use --host.
    If a cross compiler is detected then cross compile mode will be used.
checking build system type... powerpc-apple-darwin7.5.0
checking host system type... powerpc-apple-darwin
checking target system type... powerpc-apple-darwin
checking for powerpc-apple-darwin-gcc... no
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking gcc version... 3
checking for inline... inline
checking for __attribute__... yes
checking for u_int8_t using gcc... yes
checking for u_int16_t using gcc... yes
checking for u_int32_t using gcc... yes
checking how to run the C preprocessor... gcc -E
checking for egrep... grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking sys/ioccom.h usability... yes
checking sys/ioccom.h presence... yes
checking for sys/ioccom.h... yes
checking sys/sockio.h usability... yes
checking sys/sockio.h presence... yes
checking for sys/sockio.h... yes
checking ifaddrs.h usability... yes
checking ifaddrs.h presence... yes
checking for ifaddrs.h... yes
checking limits.h usability... yes
checking limits.h presence... yes
checking for limits.h... yes
checking for netinet/if_ether.h... yes
checking for ANSI ioctl definitions... yes
checking for ether_hostton... yes
checking for strerror... yes
checking for strlcpy... yes
checking for vsnprintf... yes
checking for snprintf... yes
checking if --disable-protochain option is specified... enabled
checking packet capture type... bpf
checking for getifaddrs... yes
checking if --enable-ipv6 option is specified... no
checking whether to build optimizer debugging code... no
checking whether to build parser debugging code... no
checking whether we have /proc/net/dev... no
checking whether we have DAG API... no
checking for flex... flex
checking for flex 2.4 or higher... yes
checking for bison... bison
checking for powerpc-apple-darwin-ranlib... no
checking for ranlib... ranlib
checking if sockaddr struct has sa_len member... yes
checking if sockaddr_storage struct exists... yes
checking if dl_hp_ppa_info_t struct has dl_module_id_1 member... no
checking if unaligned accesses fail... no
checking for a BSD-compatible install... /usr/bin/install -c
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -c ./pcap-bpf.c
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -c ./fad-getad.c
sed -e 's/.*/static const char pcap_version_string[] = "libpcap version &";/' ./VERSION > version.h
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -c ./inet.c
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -c ./gencode.c
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -c ./optimize.c
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -c ./nametoaddr.c
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -c ./etherent.c
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -c ./savefile.c
rm -f bpf_filter.c
ln -s ./bpf/net/bpf_filter.c bpf_filter.c
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -c ./bpf_image.c
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -c ./bpf_dump.c
flex -Ppcap_ -t scanner.l > $$.scanner.c; mv $$.scanner.c scanner.c
bison -y -p pcap_ -d grammar.y
mv y.tab.c grammar.c
mv y.tab.h tokdefs.h
sed -e 's/.*/char pcap_version[] = "&";/' ./VERSION > version.c
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -c ./pcap.c
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -c bpf_filter.c
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -c scanner.c
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -Dyylval=pcap_lval -c grammar.c
gcc -O2 -O2 -pipe -mcpu=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIC -c version.c
ar rc libpcap.a pcap-bpf.o fad-getad.o pcap.o inet.o gencode.o optimize.o nametoaddr.o etherent.o savefile.o bpf_filter.o bpf_image.o bpf_dump.o  scanner.o grammar.o version.o  
ranlib libpcap.a
gcc: unrecognized option `-shared'
ld: unknown flag: -soname

!!! ERROR: net-libs/libpcap-0.8.3-r1 failed.
!!! Function src_compile, Line 31, Exitcode 1
!!! couldn't make a shared lib
!!! If you need support, post the topmost build error, NOT this status message.

Reproducible: Always
Steps to Reproduce:
On a Mac OS X system with Portage installed,
FEATURES="-sandbox" USE="gtk" ACCEPT_KEYWORDS="macos ~macos ~ppc ppc"  emerge ettercap
Actual Results:  
It failed with the error in the Details section.

Expected Results:  
It should have compiled :)

PPC G4 running OSX 10.3.5
Comment 1 Robin Munn 2004-09-05 14:32:14 UTC
The included Makefile in libpcap-0.8.3.tar.gz only compiles static libraries; the ebuild includes the line:

    gcc -Wl,-soname,libpcap.so.0 -shared -fPIC -o libpcap.so.${PV:0:3} *.o

to build a shared library after the Makefile has built a static library.

But the required gcc options for building shared libraries are different in OS X. Instead of -shared, you use -dynamiclib. And instead of passing "-soname libpcap.so.0" to the linker (which is what "-Wl,-soname,libpcap.so.0" does), you pass those arguments to gcc as well; -soname becomes -install_name, and is supposed to include the path where the library will eventually be installed. Thus "-Wl,-soname,libpcap.so.0" becomes "-install_name /usr/lib/libpcap.0.dylib".

Then there's a couple other things to keep in mind: by default, when you build a shared library, OS X's gcc builds what is called a "two-level namespace" library. You probably wanted a "flat namespace" library instead. (The difference between the two is explained over at http://developer.apple.com/releasenotes/DeveloperTools/TwoLevelNamespaces.html). So you need the "-flat_namespace" flag as well when you build your shared library. And finally, you're going to need to specify a "compatibility version" and a "current version" for this dynamic library. The "current version" is just what is sounds like: the current version of the library. Here you can just use the same version number as the library itself (in this case, 0.8.3). The "compatibility version" is what the OS X linker looks at to see if it's got compatible versions of a library. Here, unless you know what you're doing, a good default is probably the first three characters of the version number (in this case, 0.8).

Putting all that together, the command you're going to want is:

    gcc -dynamiclib -flat_namespace -install_name /usr/lib/libpcap.0.dylib -compatibility_version ${PV:0:3} -current_version ${PV} -fPIC -o libpcap.${PV:0:3}.dylib *.o
Comment 2 Robin Munn 2004-09-05 14:42:30 UTC
Well, if you use that command line to compile, there's one more problem: you'll get an error like "ld: common symbols not allowed with MH_DYLIB output format with the -multi_module option".

Looking at how fink solved this one, I see they included a patch that adds "-fno-common" to CFLAGS in the Makefile. That should take care of the "common symbols not allowed" problem. (Does anyone know the difference between "common" symbols and, well, un"common" ones?)
Comment 3 Robin Munn 2004-09-05 14:46:28 UTC
Created attachment 39007 [details, diff]
libpcap-macos.patch

With the addition of -fno-common to CFLAGS, it works. Note that this does
overwrite some default Macintosh files, so this is not for the faint of heart.
If you really want to install this, you'll need to either use
"FEATURES='-collision-protect'", or else (my favorite) find out which files
have collisions (it'll probably be /usr/lib/libpcap* and /usr/include/pcap*.h)
and then move them out of the way somehow (I renamed them to
/usr/lib/libpcap*.orig and /usr/include/pcap*.h.orig).

Here's a patch that adds -fno-common to CFLAGS in the Makefile.
Comment 4 Robin Munn 2004-09-05 14:48:44 UTC
Created attachment 39008 [details, diff]
libpcap-0.8.3-r1.ebuild.patch

And here's an ebuild patch that will compile a shared libpcap correctly on
macos. I've tested this on my iBook G4 running Panther (10.3.5), and it works
for me.
Comment 5 Lina Pezzella (RETIRED) gentoo-dev 2004-10-09 11:52:24 UTC
An older version is already in package.provided. Please test for ppc-darwin if desired, but due to policy we will not be overwriting the already provided version.
Comment 6 Lina Pezzella (RETIRED) gentoo-dev 2005-01-20 08:52:10 UTC
leaving this one here in case darwin porters care to look at it.
Comment 7 Hasan Khalil (RETIRED) gentoo-dev 2005-01-23 12:58:23 UTC
This depends on bug 67162. Will take a look at it when 67162 has gotten somewhere. Until then, this 
bug should remain frozen.