Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 390547

Summary: dev-lang/ocaml linking issue
Product: Gentoo Linux Reporter: Guillaume Horel <guillaume.horel>
Component: [OLD] DevelopmentAssignee: Gentoo Team for the ML programming language family <ml>
Status: RESOLVED FIXED    
Severity: major    
Priority: Normal    
Version: unspecified   
Hardware: x86   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Guillaume Horel 2011-11-14 17:37:34 UTC
The patch 060_all_linkorder.patch in the patches tarball introduced to fix builds with the --as-needed option in the linker is not correct.

Reproducible: Always

Steps to Reproduce:
1. I'm trying to build a caml program with the pcre-ocaml library. Let's take the subst.ml from the examples directory.
2. 
3.
Actual Results:  
ocamlopt.opt -verbose -o subst -I /usr/lib/ocaml/pcre /usr/lib/ocaml/pcre/pcre.cmxa subst.ml
+ i686-pc-linux-gnu-as -o 'subst.o' '/tmp/camlasm084159.s'
+ i686-pc-linux-gnu-as -o '/tmp/camlstartup224b90.o' '/tmp/camlstartup777895.s'
+ i686-pc-linux-gnu-gcc -Wl,-O1 -Wl,--as-needed  -Wl,-E -o 'subst'   '-L/usr/lib/ocaml/pcre' '-L/usr/lib/ocaml' -Wl,-O1 -Wl,--as-needed '/tmp/camlstartup224b90.o' '/usr/lib/ocaml/std_exit.o' 'subst.o' '/usr/lib/ocaml/pcre/pcre.a' '/usr/lib/ocaml/stdlib.a' '-L/usr/lib' '/usr/lib/ocaml/libasmrun.a' '-lpcre_stubs' '-lpcre'  -lm  -ldl
/usr/lib/ocaml/pcre/libpcre_stubs.a(pcre_stubs.o): In function `pcre_ocaml_init':
(.text+0x1f4): undefined reference to `caml_hash_variant'
/usr/lib/ocaml/pcre/libpcre_stubs.a(pcre_stubs.o): In function `pcre_ocaml_init':
(.text+0x208): undefined reference to `caml_hash_variant'
/usr/lib/ocaml/pcre/libpcre_stubs.a(pcre_stubs.o): In function `pcre_ocaml_init':
(.text+0x21c): undefined reference to `caml_hash_variant'
/usr/lib/ocaml/pcre/libpcre_stubs.a(pcre_stubs.o): In function `pcre_ocaml_init':
(.text+0x230): undefined reference to `caml_hash_variant'
/usr/lib/ocaml/pcre/libpcre_stubs.a(pcre_stubs.o): In function `pcre_ocaml_init':
(.text+0x244): undefined reference to `caml_hash_variant'
/usr/lib/ocaml/pcre/libpcre_stubs.a(pcre_stubs.o):(.text+0x258): more undefined references to `caml_hash_variant' follow
collect2: ld returned 1 exit status
File "caml_startup", line 1, characters 0-1:
Error: Error during linking

Expected Results:  
If I remove the patch, this is what I get instead:
ocamlopt -verbose -o subst -I /usr/lib/ocaml/pcre /usr/lib/ocaml/pcre/pcre.cmxa subst.ml
+ i686-pc-linux-gnu-as -o 'subst.o' '/tmp/camlasm0ca486.s'
+ i686-pc-linux-gnu-as -o '/tmp/camlstartup0be876.o' '/tmp/camlstartup42e477.s'
+ i686-pc-linux-gnu-gcc -Wl,-O1 -Wl,--as-needed  -Wl,-E -o 'subst'   '-L/usr/lib/ocaml/pcre' '-L/usr/lib/ocaml' -Wl,-O1 -Wl,--as-needed '/tmp/camlstartup0be876.o' '/usr/lib/ocaml/std_exit.o' 'subst.o' '/usr/lib/ocaml/pcre/pcre.a' '/usr/lib/ocaml/stdlib.a' '-lpcre_stubs' '-L/usr/lib' '-lpcre' '/usr/lib/ocaml/libasmrun.a' -lm  -ldl

The patch 060_all_linkorder.patch is the culprit since it changes the order of -lpcre and /usr/lib/ocaml/libasmrun.a in the arguments passed to the linker (the missing symbols are defined in libasmrun.a). I've checked how they do things in debian an they seem to handle all the --as-needed issues at the package level (they change the linker arguments at compilation). I'm not sure if the fix can be done at the compiler level.
Comment 1 Jeroen Roovers (RETIRED) gentoo-dev 2011-11-15 15:09:52 UTC
Please post your `emerge --info' output too.
Comment 2 Guillaume Horel 2011-11-15 15:14:01 UTC
emerge --info output

Portage 2.2.0_alpha62_p1 (default/linux/x86/10.0/desktop/kde, gcc-4.5.3, glibc-2.13-r4, 3.1.0-gentoo i686)
=================================================================
System uname: Linux-3.1.0-gentoo-i686-Intel-R-_Pentium-R-_CPU_P6000_@_1.87GHz-with-gentoo-2.1
Timestamp of tree: Mon, 14 Nov 2011 16:00:01 +0000
ccache version 3.1.6 [disabled]
app-shells/bash:          4.2_p10
dev-java/java-config:     2.1.11-r3
dev-lang/python:          2.6.7-r2, 2.7.2-r3, 3.2.2
dev-util/ccache:          3.1.6
dev-util/cmake:           2.8.6-r3
dev-util/pkgconfig:       0.26
sys-apps/baselayout:      2.1
sys-apps/openrc:          0.9.4
sys-apps/sandbox:         2.5
sys-devel/autoconf:       2.13, 2.68
sys-devel/automake:       1.4_p6-r1, 1.9.6-r3, 1.10.3, 1.11.1-r1
sys-devel/binutils:       2.21.1-r1
sys-devel/gcc:            4.5.3-r1
sys-devel/gcc-config:     1.5-r2
sys-devel/libtool:        2.4-r4
sys-devel/make:           3.82-r3
sys-kernel/linux-headers: 2.6.39 (virtual/os-headers)
sys-libs/glibc:           2.13-r4
Repositories: gentoo science sunrise java-overlay x11 mozilla local multimedia
Installed sets: @kdebase
ACCEPT_KEYWORDS="x86 ~x86"
ACCEPT_LICENSE="* -@EULA dlj-1.1 AdobeFlash-10.1 skype-eula googleearth google-talkplugin Oracle-BCLA-JavaSE"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-march=native -O2 -pipe -fomit-frame-pointer"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt /usr/share/maven-bin-3.0/conf"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php5.3/ext-active/ /etc/php/apache2-php5.4/ext-active/ /etc/php/cgi-php5.3/ext-active/ /etc/php/cgi-php5.4/ext-active/ /etc/php/cli-php5.3/ext-active/ /etc/php/cli-php5.4/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-march=native -O2 -pipe -fomit-frame-pointer"
DISTDIR="/usr/portage/distfiles"
FEATURES="assume-digests binpkg-logs distlocks ebuild-locks fixlafiles fixpackages news parallel-fetch protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch"
FFLAGS=""
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="en_US.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LINGUAS="en fr"
MAKEOPTS="-j1"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/var/lib/layman/science /var/lib/layman/sunrise /var/lib/layman/java-overlay /var/lib/layman/x11 /var/lib/layman/mozilla /usr/local/portage /var/lib/layman/gentoo-multimedia"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="X a52 aac acl acpi alsa avahi bash-completion berkdb branding bzip2 cairo cdda cdr cli consolekit cracklib crypt cups custom-optimization cxx dbus declarative dri dts dvd dvdr emboss encode exif fam firefox flac fortran gdbm gdu gif gpm gtk iconv ipv6 jpeg kde kipi lcms ldap libnotify lm_sensors lzma mad mmx mng modules mp3 mp4 mpeg mudflap musicbrainz ncurses nls nptl nptlonly ogg opengl openmp pam pango pcre pdf phonon plasma png policykit ppds pppd pulseaudio qt3support qt4 readline sdl semantic-desktop session spell sse sse2 sse3 ssl startup-notification svg sysfs system-sqlite tcpd tiff truetype udev unicode usb vorbis x264 x86 xcb xcomposite xinerama xml xorg xscreensaver xulrunner xv xvid zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1 emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan stage tables krita karbon braindump" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en fr" PHP_TARGETS="php5-3" RUBY_TARGETS="ruby18" USERLAND="GNU" VIDEO_CARDS="intel i965" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 3 Alexis Ballier gentoo-dev 2012-07-09 15:42:58 UTC
FWIW: I've dropped the patch for ocaml-4.00; I didnt want to drop it earlier as it might break some packages.
Comment 4 Alexis Ballier gentoo-dev 2012-11-01 15:58:17 UTC
ocaml-4 dropped that patch and is now unmasked -> fixed