Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 510400 - sys-devel/gcc-4.8.2: initial multilib support for Gentoo/FreeBSD
Summary: sys-devel/gcc-4.8.2: initial multilib support for Gentoo/FreeBSD
Status: RESOLVED OBSOLETE
Alias: None
Product: Gentoo/Alt
Classification: Unclassified
Component: FreeBSD (show other bugs)
Hardware: All FreeBSD
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-15 13:51 UTC by Yuta SATOH
Modified: 2019-10-11 17:37 UTC (History)
3 users (show)

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


Attachments
multilib support patch for gcc-4.8.2 (gcc48-freebsd-multilib.patch,1.34 KB, patch)
2014-05-15 13:51 UTC, Yuta SATOH
Details | Diff
patch for /etc/env.d/gcc/x86_64-gentoo-freebsd10.0-4.8.2 (510400-envd-gcc.patch,553 bytes, patch)
2014-05-15 13:53 UTC, Yuta SATOH
Details | Diff
sample patch for freebsd-libexec-9.2.ebuild (510400-ld32.patch,523 bytes, patch)
2014-05-15 16:35 UTC, Yuta SATOH
Details | Diff
patch for sys-apps/portage, pym/portage/util/env_update.py (510400-envupdate.patch,2.12 KB, patch)
2014-05-16 11:21 UTC, Yuta SATOH
Details | Diff
patch for sys-apps/openrc, init.d/bootmisc.in (510400-openrc.patch,555 bytes, patch)
2014-05-16 11:21 UTC, Yuta SATOH
Details | Diff
toolchain.eclass.patch (toolchain.eclass.patch,1.18 KB, patch)
2017-04-10 20:24 UTC, i.Dark_Templar
Details | Diff
gcc-4.9.4-freebsd-multilib.patch (gcc-4.9.4-freebsd-multilib.patch,2.44 KB, patch)
2017-04-10 20:25 UTC, i.Dark_Templar
Details | Diff
portage-freebsd-multilib-env.patch (freebsd-multilib-env.patch,2.30 KB, patch)
2017-04-10 20:33 UTC, i.Dark_Templar
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yuta SATOH 2014-05-15 13:51:43 UTC
Created attachment 377004 [details, diff]
multilib support patch for gcc-4.8.2

Currently, you can not compiled with -m32 option.
If you apply a patch, multilib is enabled, 32-bit libraries are created.


$ gcc -m32 -o hello hello.c
/usr/lib/gcc/x86_64-gentoo-freebsd10.0/4.8.2/../../../../x86_64-gentoo-freebsd10.0/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-gentoo-freebsd10.0/4.8.2/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-gentoo-freebsd10.0/4.8.2/../../../../x86_64-gentoo-freebsd10.0/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-gentoo-freebsd10.0/4.8.2/../../../libgcc.a when searching for -lgcc
<snip>
collect2: error: ld returned 1 exit status



Comments are welcome: 
* Better patch.
* A good way to detect the libraries.

Thanks in advance.
Comment 1 Yuta SATOH 2014-05-15 13:53:41 UTC
Created attachment 377006 [details, diff]
patch for /etc/env.d/gcc/x86_64-gentoo-freebsd10.0-4.8.2

Known issue:

After running emerge gcc, can not find the 64-bit library correctly.

$ g++ -m64 -o hello hello.cpp
$ ./hello
/usr/lib/gcc/x86_64-gentoo-freebsd10.0/4.8.2/32/libstdc++.so.6: unsupported file layout

workaround, please apply the attached patch.

# cd /etc/env.d/gcc
# patch -p0 < patchfile
# gcc-config [num]
# . /etc/profile
Comment 2 Yuta SATOH 2014-05-15 16:35:37 UTC
Created attachment 377016 [details, diff]
sample patch for freebsd-libexec-9.2.ebuild

Needs to drop "${FILESDIR}/${PN}-9.2-no_ld32.patch" to enable LD_32_LIBRARY_PATH.
Comment 3 Yuta SATOH 2014-05-16 11:21:00 UTC
Created attachment 377064 [details, diff]
patch for sys-apps/portage, pym/portage/util/env_update.py

BAD patch... However, it works.


Only 64-bit libraries should be included in /etc/ld.so.conf.

$ cat /etc/ld.so.conf
# ld.so.conf autogenerated by env-update; make all changes to
# contents of /etc/env.d directory
/lib
/usr/lib
/usr/local/lib
/usr/lib/opengl/xorg-x11/lib
/usr/lib/gcc/x86_64-gentoo-freebsd10.0/4.8.2
/usr/lib/gcc/x86_64-gentoo-freebsd10.0/4.6.4
/usr/lib/gcc/x86_64-gentoo-freebsd10.0/4.6.4
/usr/x86_64-gentoo-freebsd10.0/lib
/usr/lib/qca2
/usr/lib/qt4

It should be output to a separate file for 32-bit libraries.
e.g.) /etc/ld32.so.conf

$ cat /etc/ld32.so.conf
/lib32
/usr/lib32
/usr/local/lib32
/usr/lib/gcc/x86_64-gentoo-freebsd10.0/4.8.2/32
/usr/lib32/qt4

Generate the hints for 32-bit ABI shared libraries
# ldconfig -32 -elf -i -f /var/run/ld-elf32.so.hints /etc/ld32.so.conf


FYI,
FreeBSD man page (ldconfig)
http://www.freebsd.org/cgi/man.cgi?query=ldconfig&apropos=0&sektion=0&manpath=FreeBSD+10.0-RELEASE&arch=default&format=html
Comment 4 Yuta SATOH 2014-05-16 11:21:34 UTC
Created attachment 377068 [details, diff]
patch for sys-apps/openrc, init.d/bootmisc.in

keep /var/run/ld-elf32.so.hints
Comment 5 Yuta SATOH 2014-08-02 02:36:49 UTC
dev-libs/libxml2 fails to build with the following error message:

/bin/sh ./libtool  --tag=CC   --mode=link x86_64-gentoo-freebsd10.0-gcc -m32 -DCOMPAT_32BIT -B/usr/lib32 -L/usr/lib32 -D_REENTRANT   -O2 -pipe -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wno-long-long   -o xmllint xmllint.o   ./libxml2.la -lpthread -lz   -lm
libtool: link: x86_64-gentoo-freebsd10.0-gcc -m32 -DCOMPAT_32BIT -B/usr/lib32 -D_REENTRANT -O2 -pipe -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wno-long-long -o .libs/xmllint xmllint.o  -L/usr/lib32 ./.libs/libxml2.so -licui18n -licuuc -licudata -lpthread -lz -lm -Wl,-rpath -Wl,/usr/lib32
/usr/lib/gcc/x86_64-gentoo-freebsd10.0/4.8.3/../../../../x86_64-gentoo-freebsd10.0/bin/ld: warning: libstdc++.so.6, needed by /usr/lib32/libicui18n.so, not found (try using -rpath or -rpath-link)
/usr/lib32/libicui18n.so: undefined reference to `operator delete(void*)@GLIBCXX_3.4'
/usr/lib32/libicui18n.so: undefined reference to `vtable for __cxxabiv1::__si_class_type_info@CXXABI_1.3'
/usr/lib32/libicui18n.so: undefined reference to `__gxx_personality_v0@CXXABI_1.3'
/usr/lib32/libicuuc.so: undefined reference to `__cxa_call_unexpected@CXXABI_1.3'
/usr/lib32/libicui18n.so: undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info@CXXABI_1.3'
/usr/lib32/libicui18n.so: undefined reference to `__cxa_pure_virtual@CXXABI_1.3'
/usr/lib32/libicui18n.so: undefined reference to `__dynamic_cast@CXXABI_1.3'
/usr/lib32/libicui18n.so: undefined reference to `vtable for __cxxabiv1::__class_type_info@CXXABI_1.3'
collect2: error: ld returned 1 exit status
Makefile:1099: recipe for target 'xmllint' failed
gmake[2]: *** [xmllint] Error 1
gmake[2]: Leaving directory '/var/tmp/portage/dev-libs/libxml2-2.9.1-r4/work/libxml2-2.9.1-abi_x86_32.x86_fbsd'
Makefile:1401: recipe for target 'all-recursive' failed


Please add the following contents to /etc/portage/bashrc for a successful build.

pre_pkg_setup() {
        GCC32PATH=`grep LDPATH /etc/env.d/gcc/.NATIVE | awk -F: '{print $2}' | sed 's:"::g'`
        export CFLAGS_x86_fbsd="${CFLAGS_x86_fbsd} -rpath /usr/lib32 -rpath /lib32 -rpath ${GCC32PATH}"
}
Comment 6 i.Dark_Templar 2017-04-10 20:24:59 UTC
Created attachment 469654 [details, diff]
toolchain.eclass.patch

I did a similar thing recently for gcc-4.9.4 and Gentoo/FreeBSD 10.3. But I also patched toolchain.eclass and took a bit different approach for env-update patch.
Comment 7 i.Dark_Templar 2017-04-10 20:25:57 UTC
Created attachment 469656 [details, diff]
gcc-4.9.4-freebsd-multilib.patch
Comment 8 i.Dark_Templar 2017-04-10 20:33:07 UTC
Created attachment 469658 [details, diff]
portage-freebsd-multilib-env.patch

For this patch I chose to not make second env file, but to put directories for 32bit libraries and 64bit libraries into 2 separate arrays, form command line from strings from these arrays and call ldconfig with these strings as arguments.
It may be further improved by bot guessing whether directory is 64bit or 32bit, but by using separate env entries, like LDPATH_m32, LDPATH_m64, and so on, but it'd be too much effort for this feature IMHO since this crude arch guessing logic works fine.
64bit multilib detection definitely may be improved for this patch.
Comment 9 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2018-03-11 17:55:13 UTC
@toolchain, how far you'd be interested in patching gcc to make multilib work on FreeBSD? We're trying to establish if it's a worthwhile effort at all or if we should mask gcc and focus on clang.
Comment 10 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2019-10-11 17:37:21 UTC
*-fbsd is gone.