Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 377039 - sys-devel/crossdev-20110705: crossdev -t avr produces broken toolchain: cannot find crtm1280.o, skipping incompatible libm.a when searching for -lm
Summary: sys-devel/crossdev-20110705: crossdev -t avr produces broken toolchain: canno...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Unspecified (show other bugs)
Hardware: x86 Linux
: Normal normal with 7 votes (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
: 378387 378517 393081 429994 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-07-30 10:41 UTC by Michael Moon
Modified: 2012-08-30 18:16 UTC (History)
14 users (show)

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


Attachments
gcc-4.5.2.ebuild with addition of gcc-005-constructor patch (gcc-4.5.2.ebuild,1.76 KB, text/plain)
2011-12-04 15:07 UTC, J.C. Wren
Details
gcc-005-constructor patch to save R20 in _ctors and _dtors (gcc-005-constructor.patch,531 bytes, patch)
2011-12-04 15:09 UTC, J.C. Wren
Details | Diff
crossdev-avrMultilib.patch (crossdev-20120301-avrMultilib.patch,621 bytes, patch)
2012-03-02 21:44 UTC, Jess Haas
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Moon 2011-07-30 10:41:44 UTC
# crossdev -t avr
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 * crossdev version:      20110705
 * Host Portage ARCH:     x86
 * Target Portage ARCH:   *
 * Target System:         avr
 * Stage:                 4 (C/C++ compiler)
 * ABIs:                  default

 * binutils:              binutils-[latest]
 * gcc:                   gcc-[latest]
 * libc:                  avr-libc-[latest]

 * PORTDIR_OVERLAY:       /usr/local/portage-crossdev
 * PORT_LOGDIR:           /var/log/portage
 * PORTAGE_CONFIGROOT:
  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~  -  _  -  ~
!!! WARNING - Cannot auto-configure CHOST avr
!!! You should edit /usr/avr/etc/portage/make.conf
!!! by hand to complete your configuration
 * Forcing the latest versions of {binutils,gcc}-config/gnuconfig ...                                                                                                                                                                                [ ok ]
 * Log: /var/log/portage/cross-avr-binutils.log
 * Emerging cross-binutils ...                                                                                                                                                                                                                       [ ok ]
 * Log: /var/log/portage/cross-avr-gcc-stage1.log
 * Emerging cross-gcc-stage1 ...                                                                                                                                                                                                                     [ ok ]
 * Log: /var/log/portage/cross-avr-avr-libc.log
 * Emerging cross-avr-libc ...                                                                                                                                                                                                                       [ ok ]
 * Log: /var/log/portage/cross-avr-gcc-stage2.log
 * Emerging cross-gcc-stage2 ...
#

then,

$ avr-gcc -c -Os -mmcu=atmega1280 -DF_CPU=16000000L -std=gnu99 -o mendel.o mendel.c
$ avr-gcc -Os -mmcu=atmega1280 -DF_CPU=16000000L -std=gnu99 -o mendel.elf mendel.o
/usr/libexec/gcc/avr/ld: cannot find crtm1280.o: No such file or directory
/usr/libexec/gcc/avr/ld: skipping incompatible /usr/lib/gcc/avr/4.5.2/../../../../avr/lib/libm.a when searching for -lm
/usr/libexec/gcc/avr/ld: cannot find -lm
/usr/libexec/gcc/avr/ld: skipping incompatible /usr/lib/gcc/avr/4.5.2/libgcc.a when searching for -lgcc
/usr/libexec/gcc/avr/ld: cannot find -lgcc
/usr/libexec/gcc/avr/ld: skipping incompatible /usr/lib/gcc/avr/4.5.2/../../../../avr/lib/libc.a when searching for -lc
/usr/libexec/gcc/avr/ld: cannot find -lc
/usr/libexec/gcc/avr/ld: skipping incompatible /usr/lib/gcc/avr/4.5.2/libgcc.a when searching for -lgcc
/usr/libexec/gcc/avr/ld: cannot find -lgcc
collect2: ld returned 1 exit status

$ avr-objdump -f mendel.o 

mendel.o:     file format elf32-avr
architecture: avr:51, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000

$ avr-objdump -f /usr/lib/gcc/avr/4.5.2/../../../../avr/lib/libm.a | head -n7
In archive /usr/lib/gcc/avr/4.5.2/../../../../avr/lib/libm.a:

acos.o:     file format elf32-avr
architecture: avr, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000

$

perhaps it should be trying to use /usr/avr/lib/avr51/libm.a ?

This also happened with sys-devel/crossdev-20110310

# ls /var/db/pkg/cross-avr/
avr-libc-1.7.0 binutils-2.21.1  gcc-4.5.2

# emerge --info
Portage 2.1.10.3 (default/linux/x86/10.0, gcc-4.4.5, glibc-2.12.2-r0, 2.6.38-gentoo-r6-jinsuul i686)
=================================================================
System uname: Linux-2.6.38-gentoo-r6-jinsuul-i686-Genuine_Intel-R-_CPU_T2300_@_1.66GHz-with-gentoo-2.0.3
Timestamp of tree: Tue, 26 Jul 2011 08:15:01 +0000
app-shells/bash:          4.1_p9
dev-lang/python:          2.7.1-r1, 3.1.3-r1
dev-util/cmake:           2.8.4-r1
dev-util/pkgconfig:       0.26
sys-apps/baselayout:      2.0.3
sys-apps/openrc:          0.8.3-r1
sys-apps/sandbox:         2.4
sys-devel/autoconf:       2.68
sys-devel/automake:       1.9.6-r3, 1.10.3, 1.11.1
sys-devel/binutils:       2.20.1-r1
sys-devel/gcc:            4.4.5
sys-devel/gcc-config:     1.4.1-r1
sys-devel/libtool:        2.2.10
sys-devel/make:           3.82
sys-kernel/linux-headers: 2.6.36.1 (virtual/os-headers)
sys-libs/glibc:           2.12.2
Repositories: gentoo x-portage-crossdev x-portage
ACCEPT_KEYWORDS="x86"
ACCEPT_LICENSE="* -@EULA Q3AEULA PUEL dlj-1.1 skype-eula cadsoft googleearth AdobeFlash-10 AdobeFlash-10.1 CePL"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-O2 -march=native -pipe"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/init.d /etc/php/apache2-php5.3/ext-active/ /etc/php/cgi-php5.3/ext-active/ /etc/php/cli-php5.3/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -march=native -pipe"
DISTDIR="/usr/portage/distfiles"
EMERGE_DEFAULT_OPTS="--alphabetical --keep-going"
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="/usr/portage/distfiles-old http://gentoo.helios/ http://ftp.iinet.net.au/pub/Gentoo/ http://mirror.internode.on.net/pub/gentoo"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LINGUAS="en en_US"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_EXTRA_OPTS="--exclude='/searchdesc'"
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="/usr/local/portage-crossdev /usr/local/portage"
SYNC="rsync://ftp.iinet.net.au/gentoo-portage"
USE="3dnow 3dnowext X Xaw3d a52 aac aalib acl acpi adns aio alsa apache2 apng athena berkdb bluetooth branding bzip2 cairo cdda cddb cdparanoia chm cli collab connection-sharing consolekit cpudetection cracklib crypt cups curl cxx declarative desktopglobe device-mapper dga dhcp dhcpcd djvu dnd dri dvd eap-tls ebook encode eolconv exif fam fbcon ffmpeg flac fluidsynth fontconfig fortran fping gd gdbm gif git glut gnutls gphoto2 gpm graphviz gs gsm gstreamer gtk hardware-carrier hdri iconv icu id3tag imagemagick ipv6 jack jingle jpeg jpeg2k kpathsea ladspa lame latex latin1 libass libcaca libmpeg2 libnotify libsamplerate libssh2 libv4l2 linuxkeys lirc llvm lzma lzo math mathml matroska md5sum midi mjpeg mktemp mmap mmx mmxext mng modules mp3 mpeg mpg123 mplayer mppe-mppc mudflap mule multimedia mysql ncurses nethack nls nptl nptlonly nsplugin ntp offensive ogg openal opengl openmp openxml ots pam pcre pdf perl php plugins png pnm policykit postproc ppds pppd python python3 qalculate qt3support qt4 quicktime readline rtsp samba sasl sdl session skype smbclient smp sms sndfile soap sockets socks5 soundtouch sox sql sqlite3 sse sse2 ssl startup-notification stream subtitles subversion svg sysfs sysvipc taglib tcpd theora thumbnail tiff tk tordns truetype twolame type3 udev udis86 unicode upnp urandom usb v4l v4l2 vaapi vamp vcd vdpau video vorbis webkit wifi win32codecs wps x264 x86 xcomposite xft xim xine xinerama xml xmlreader xmlrpc xmlwriter xorg xpm xrandr xsl xterm xv xvid xvmc yv12 zip 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_default authn_file authz_default 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 imagemap include info log_config log_forensic logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias reqtimeout" CALLIGRA_FEATURES="braindump flow karbon kexi kpresenter krita tables words" CAMERAS="adc65 agfa_cl20 aox ax203 barbie canon casio_qv clicksmart310 digigr8 digita dimagev dimera3500 directory enigma13 fuji gsmart300 hp215 iclick jamcam jd11 jl2005a jl2005c kodak_dc120 kodak_dc210 kodak_dc240 kodak_dc3200 kodak_ez200 konica konica_qm150 largan lg_gsm mars mustek panasonic_coolshot panasonic_dc1000 panasonic_dc1580 panasonic_l859 pccam300 pccam600 polaroid_pdc320 polaroid_pdc640 polaroid_pdc700 ptp2 ricoh ricoh_g3 samsung sierra sipix_blink sipix_blink2 sipix_web2 smal sonix sony_dscf1 sony_dscf55 soundvision spca50x sq905 st2205 stv0674 stv0680 sx330z template topfield toshiba_pdrm11" 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="keyboard mouse synaptics evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en en_US" LIRC_DEVICES="accent act200l act220l adaptec alsa_usb animax asusdh atilibusb atiusb audio audio_alsa avermedia avermedia98 avermedia_vdomate awlibusb bestbuy bestbuy2 breakoutbox bte bw6130 caraca chronos commandir cph06x creative creative_infracd devinput digimatrix dsp dvico ea65 ene0100 exaudio flyvideo ftdi gvbctv5pci hauppauge hauppauge_dvb hercules_smarttv_stereo i2cuser igorplugusb iguanaIR imon imon_24g imon_knob imon_lcd imon_pad imon_rsc inputlirc irdeo irdeo_remote irlink irman irreal it87 ite8709 knc_one kworld leadtek_0007 leadtek_0010 leadtek_pvr2000 livedrive_midi livedrive_seq logitech macmini mediafocusI mouseremote mouseremote_ps2 mp3anywhere mplay nslu2 packard_bell parallel pcmak pcmak_usb pctv pixelview_bt878 pixelview_pak pixelview_pro provideo realmagic remote_wonder_plus remotemaster sa1100 samsung sasem sb0540 serial serial_igor_cesko silitek sir slinke streamzap tekram tekram_bt829 tira ttusbir tuxbox tvbox udp uirt2 uirt2_raw usb_uirt_raw usbx userspace wpc8769l xboxusb" PHP_TARGETS="php5-3" RUBY_TARGETS="ruby18" USERLAND="GNU" VIDEO_CARDS="nvidia" 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, INSTALL_MASK, LANG, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS
Comment 1 Michael Moon 2011-07-30 10:53:13 UTC
$ equery b crtm1280.o
 * Searching for crtm1280.o ... 
cross-avr/avr-libc-1.7.0 (/usr/avr/lib/avr51/crtm1280.o)
cross-avr/avr-libc-1.7.0 (/usr/avr/lib/avr5/crtm1280.o)
$ avr-gcc -Os -mmcu=atmega1280 -DF_CPU=16000000L -std=gnu99 -o mendel.elf mendel.o -lm -L /usr/avr/lib/avr51 
/usr/libexec/gcc/avr/ld: cannot find crtm1280.o: No such file or directory
/usr/libexec/gcc/avr/ld: skipping incompatible /usr/lib/gcc/avr/4.5.2/libgcc.a when searching for -lgcc
/usr/libexec/gcc/avr/ld: cannot find -lgcc
/usr/libexec/gcc/avr/ld: skipping incompatible /usr/lib/gcc/avr/4.5.2/libgcc.a when searching for -lgcc
/usr/libexec/gcc/avr/ld: cannot find -lgcc
collect2: ld returned 1 exit status
$ ln -s /usr/avr/lib/avr51/crtm1280.o 
$ avr-gcc -Os -mmcu=atmega1280 -DF_CPU=16000000L -std=gnu99 -o mendel.elf mendel.o -lm -L /usr/avr/lib/avr51 
/usr/libexec/gcc/avr/ld: skipping incompatible /usr/lib/gcc/avr/4.5.2/libgcc.a when searching for -lgcc
/usr/libexec/gcc/avr/ld: cannot find -lgcc
/usr/libexec/gcc/avr/ld: skipping incompatible /usr/lib/gcc/avr/4.5.2/libgcc.a when searching for -lgcc
/usr/libexec/gcc/avr/ld: cannot find -lgcc
collect2: ld returned 1 exit status
$ equery b libgcc.a
 * Searching for libgcc.a ... 
cross-avr/gcc-4.5.2 (/usr/lib/gcc/avr/4.5.2/libgcc.a)
sys-devel/gcc-4.4.5 (/usr/lib/gcc/i686-pc-linux-gnu/4.4.5/libgcc.a)

forcing the lib dir and symlinking the startup file into ./ seems to help, but I only have the one avr/libgcc.a!
Comment 2 Michael Moon 2011-08-01 06:49:11 UTC
I read somewhere that this may happen when avr-gcc is a different version to system gcc so I passed --g 4.4.5 to crossdev.

I also read that passing -v shows the full commandline passed to avr-ld.

This showed that it's looking in current dir for crtm1280.o instead of /usr/avr/lib/$MCPU

Symlinking that file into current dir gave this:

$ avr-gcc -v -Os -mmcu=atmega1280 -DF_CPU=16000000L -std=gnu99 -o mendel.elf
mendel.o
Using built-in specs.
Target: avr
Configured with: /var/tmp/portage/cross-avr/gcc-4.4.5/work/gcc-4.4.5/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/avr/gcc-bin/4.4.5 --includedir=/usr/lib/gcc/avr/4.4.5/include --datadir=/usr/share/gcc-data/avr/4.4.5 --mandir=/usr/share/gcc-data/avr/4.4.5/man --infodir=/usr/share/gcc-data/avr/4.4.5/info --with-gxx-include-dir=/usr/lib/gcc/avr/4.4.5/include/g++-v4 --host=i686-pc-linux-gnu --target=avr --build=i686-pc-linux-gnu --disable-altivec --disable-fixed-point --without-ppl --without-cloog --enable-nls --without-included-gettext --with-system-zlib --disable-werror --enable-secureplt --disable-multilib --disable-libmudflap --disable-libssp --disable-libgomp --with-python-dir=/share/gcc-data/avr/4.4.5/python --enable-checking=release --disable-libgcj --enable-languages=c,c++ --enable-shared --disable-threads --disable-bootstrap --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.4.5 p1.3, pie-0.4.5'
Thread model: single
gcc version 4.4.5 (Gentoo 4.4.5 p1.3, pie-0.4.5) 
COMPILER_PATH=/usr/libexec/gcc/avr/4.4.5/:/usr/libexec/gcc/avr/4.4.5/:/usr/libexec/gcc/avr/:/usr/lib/gcc/avr/4.4.5/:/usr/lib/gcc/avr/
LIBRARY_PATH=/usr/lib/gcc/avr/4.4.5/:/usr/lib/gcc/avr/4.4.5/../../../../avr/lib/
COLLECT_GCC_OPTIONS='-g' '-Wall' '-Wstrict-prototypes' '-Os' '-ffunction-sections' '-finline-functions-called-once' '-mcall-prologues' '-mmcu=atmega1280' '-DF_CPU=16000000L' '-std=gnu99' '-funsigned-char' '-funsigned-bitfields' '-fpack-struct' '-fshort-enums' '-save-temps' '-o' 'mendel.elf' '-v'
 /usr/libexec/gcc/avr/ld -m avr5 -Tdata 0x800200 -o mendel.elf crtm1280.o -L/usr/lib/gcc/avr/4.4.5 -L/usr/lib/gcc/avr/4.4.5/../../../../avr/lib --as-needed --gc-sections mendel.o dda.o gcode_parse.o gcode_process.o timer.o temp.o sermsg.o dda_queue.o watchdog.o debug.o sersendf.o heater.o analog.o intercom.o pinio.o clock.o home.o crc.o delay.o serial.o -lm -lgcc -lc -lgcc
heater.o: In function `heater_init':
/home/triffid/Projects/Teacup_Firmware/heater.c:167: undefined reference to `__eewr_dword_m1280'
/home/triffid/Projects/Teacup_Firmware/heater.c:98: undefined reference to `__eewr_dword_m1280'
/home/triffid/Projects/Teacup_Firmware/heater.c:101: undefined reference to `__eewr_dword_m1280'
/home/triffid/Projects/Teacup_Firmware/heater.c:101: undefined reference to `__eewr_word_m1280'
/home/triffid/Projects/Teacup_Firmware/heater.c:101: undefined reference to `__eewr_word_m1280'
/home/triffid/Projects/Teacup_Firmware/heater.c:157: undefined reference to `__eerd_dword_m1280'
/home/triffid/Projects/Teacup_Firmware/heater.c:158: undefined reference to `__eerd_dword_m1280'
/home/triffid/Projects/Teacup_Firmware/heater.c:159: undefined reference to `__eerd_dword_m1280'
/home/triffid/Projects/Teacup_Firmware/heater.c:160: undefined reference to `__eerd_word_m1280'
/home/triffid/Projects/Teacup_Firmware/heater.c:163: undefined reference to `__eerd_word_m1280'

So apparently even with all that workaround, it still can't find stuff!

If I add -L/usr/avr/lib/avr5 to that commandline, it compiles successfully and seems to work.

Crossdev should be creating a toolchain that can work all this stuff out for itself!
Comment 3 Michael Moon 2011-08-01 07:22:49 UTC
crossdev-20100814 installed a working avr-gcc-4.4.3, avr-binutils-2.20.1 and avr-libc-1.6.8 on an old install, but these exact same versions on my new install produce the above errors!

Whatever's changed to cause this problem is outside these packages, perhaps portage tree or portage itself?
Comment 4 Niko Böckerman 2011-08-06 20:53:01 UTC
This bug affects me too. Linking fails when it can't find crtm128rfa1.o which is installed to /usr/avr/lib/avr51/ folder by avr-libc.

Avr toolchain used to work just fine few months ago but some updates had obviously caused it to not work any more and show this same error.

I managed to get working toolchain back after downgrading crossdev to 20101011 and completely rebuilding the toolchain with that version. Crossdev versions 20110310(newest stable), 20110705 and 99999999 all produced not working toolchains.

Versions I specified crossdev to build were avr-libc-1.7.0, avr-gcc-4.4.5 and binutils-2.20.1-r1 however that doesn't seem to have any effect in this bug.
Comment 5 SpanKY gentoo-dev 2011-08-15 04:58:27 UTC
*** Bug 378517 has been marked as a duplicate of this bug. ***
Comment 6 Aydin Tarik Zengin 2011-08-15 14:54:21 UTC
This affects me too. All my work has stopped just because of this.
In my case, I face this on Arduino IDE.
Comment 7 Maciej S. Szmigiero 2011-09-05 19:34:28 UTC
The crossdev version has nothing to do with this error.

The real reason for this error is that gcc for avr needs to be compiled with multilib enabled in order to have a library path properly set.

How to get a working avr toolchain on non-multilib systems:
a) Unmerge the broken gcc: emerge --unmerge cross-avr/gcc
b) In /usr/portage/eclass/toolchain.eclass search for gcc-library-configure() function,
c) Change "--disable-multilib" into "--enable-multilib" in this function
d) Scroll few lines down to the gcc-compiler-configure() function and do the same
there,
e) Run crossdev -t avr to compile cross gcc again.

This worked for me on 32-bit x86 Gentoo.

Note that this is a terrible hack.
Be sure to resync or undo the changes to toolchain.eclass later so you don't compile native gcc with multilib enabled by mistake.
Comment 8 Maciej S. Szmigiero 2011-09-05 20:15:26 UTC
In addition to gcc workaround from my previous comment binutils,
as of version 2.21.1, also needs to have ldscripts symlinked in order
to find them.

To do that go to /usr/i686-pc-linux-gnu/avr/binutils-bin/2.21.1/
(where i686 is host arch and 2.21.1 is binutils version) and execute
"ln -s ../../lib/ldscripts ldscripts"
Comment 9 Ernst Herzberg 2011-09-07 20:57:11 UTC
(In reply to comment #7)
> The crossdev version has nothing to do with this error.
> 
> The real reason for this error is that gcc for avr needs to be compiled with
> multilib enabled in order to have a library path properly set.

Doesn't work for me. I'm using amd64, mutilib enabled.

Masking >sys-devel/crossdev-20101011 works.
Comment 10 Maciej S. Szmigiero 2011-09-07 21:47:07 UTC
So maybe there are 2 bugs: one on x86 (gcc) and one on amd64 (crossdev).

Because on my x86 any crossdev downgrade doesn't result in a working toolchain.
Comment 11 Maciej S. Szmigiero 2011-09-08 22:58:43 UTC
I have just tested on amd64 and can confirm that, out of the box,
crossdev-20110819 does not work, but sys-devel/crossdev-20101011 does.

However, if I comment out "set_use_force ${pkg} -multilib" in crossdev-20110819
it does produce a working toolchain.

On my system, editing toolchain.eclass gives the same effect (working toolchain).

Hopefully, when https://bugs.gentoo.org/show_bug.cgi?id=378387 is fixed it will
fix this one, too.
Comment 12 SpanKY gentoo-dev 2011-10-11 22:27:38 UTC
post an actual test case for me to look at.  posting command lines that rely on source files that don't exist isn't sufficient.

something like:
echo 'main(){}' | avr-gcc -x c - .....
Comment 13 Michael Moon 2011-10-11 23:12:41 UTC
$ echo 'main(){}' | avr-gcc -mmcu=atmega328p -x c -
/usr/libexec/gcc/avr/ld: cannot find crtm328p.o: No such file or directory
$ ln -s /usr/avr/lib/avr5/crtm328p.o ./
$ echo 'main(){}' | avr-gcc -mmcu=atmega328p -x c - -lm
$ ls a.out 
a.out

so apparently somewhere in all my stuffing around with this, the incompatible libraries thing has resolved itself, but it still isn't looking for crt[cpu].o in the right spot
Comment 14 Maciej S. Szmigiero 2011-10-12 20:26:00 UTC
(In reply to comment #12)
> post an actual test case for me to look at.  posting command lines that rely on
> source files that don't exist isn't sufficient.

a) Be on amd64,
b) emerge --unmerge crossdev cross-avr/gcc
c) emerge crossdev [installs 20111011]
d) crossdev -t avr [note that you have to have hardened USE flag unset or gcc fails to build]
e) echo 'main(){}' | avr-gcc -x c - -mmcu=atmega2561

Result is:
/usr/libexec/gcc/avr/ld: cannot find crtm2561.o: No such file or directory
/usr/libexec/gcc/avr/ld: skipping incompatible /usr/lib/gcc/avr/4.5.3/libgcc.a when searching for -lgcc                                                                                              
/usr/libexec/gcc/avr/ld: cannot find -lgcc                                                                                                                                                           
/usr/libexec/gcc/avr/ld: skipping incompatible /usr/lib/gcc/avr/4.5.3/../../../../avr/lib/libc.a when searching for -lc                                                                              
/usr/libexec/gcc/avr/ld: cannot find -lc                                                                                                                                                             
/usr/libexec/gcc/avr/ld: skipping incompatible /usr/lib/gcc/avr/4.5.3/libgcc.a when searching for -lgcc                                                                                              
/usr/libexec/gcc/avr/ld: cannot find -lgcc                                                                                                                                                           
collect2: ld returned 1 exit status

Will check what happens on non-multilib x86 host tomorrow.
Comment 15 Aydin Tarik Zengin 2011-10-13 08:59:19 UTC
Enabling multilib and using "non-stable" versions like --gcc 4.5.1-r1 --binutils 2.21.1 --libc 1.7.1 , compiles and works fine.
BUT!, it creates faulty binaries for serial libraries for Arduino.

I have tried both ATMEL toolchain and crossdev.

First enable multilib from eclass,
Then
USE="-openmp" crossdev  --target avr --gcc 4.5.1-r1 --binutils 2.21.1 --libc 1.7.1 -s4 --without-headers
ln -s /usr/avr/lib/avr6/crtm2560.o /usr/avr/lib/crtm2560.o
ln -s /usr/avr/lib/avr6/crtm2561.o /usr/avr/lib/crtm2561.o
ln -s /usr/i686-pc-linux-gnu/avr/lib/ldscripts /usr/avr/lib/ldscripts

disable multilib again.


In this configuration delay.h has problem.
Add 
#include <math.h>
to fix it.

This configuration seems working fine and compiles fine, but actually the binary created won't work.
Comment 16 Aydin Tarik Zengin 2011-10-13 09:00:40 UTC
Forgot to say,

ATMEL toolchain works like a charm. No problem with it.
Comment 17 Maciej S. Szmigiero 2011-10-13 10:32:36 UTC
(In reply to comment #14)
> Will check what happens on non-multilib x86 host tomorrow.

The same happens on non-multilib x86.
Comment 18 Michael Moon 2011-10-13 12:15:28 UTC
avr-g++ produces non-working binaries for me too, after clobbering everything else into submission. Not just arduino libs, but other C++ avr projects as well.

I'm not familiar enough with C++ to craft even a simple test case for avr, anyone care to write a hello world in C++ and see what happens?
Comment 19 Maciej S. Szmigiero 2011-10-13 12:28:46 UTC
(In reply to comment #15)
> This configuration seems working fine and compiles fine, but actually the
> binary created won't work.

Which -mmcu are you using?

I my case, after emerging with multilib USE flag on to get crts resulting
toolchain does produce working binaries (including serial port baudrate calculation), at least for -mmcu=atmega2561.
Comment 20 Michael Moon 2011-10-13 12:31:24 UTC
I've tried with both -mmcu=atmega1280 and -mmcu=atmega328p since those are the chips I have. The toolchain from my old install, and binary toolchains from non-gentoo users both compile the exact same code to a working binary.
Comment 21 Aydin Tarik Zengin 2011-10-13 12:38:08 UTC
(In reply to comment #19)
> Which -mmcu are you using?
> 
> I my case, after emerging with multilib USE flag on to get crts resulting
> toolchain does produce working binaries (including serial port baudrate
> calculation), at least for -mmcu=atmega2561.

Tried for atmega2560. In my case crossdev created environment produces faulty binary. Atmel toolchain produces working binary for exactly the same code.
Comment 22 Maciej S. Szmigiero 2011-10-13 12:39:57 UTC
So(In reply to comment #20)
> I've tried with both -mmcu=atmega1280 and -mmcu=atmega328p since those are the
> chips I have. The toolchain from my old install, and binary toolchains from
> non-gentoo users both compile the exact same code to a working binary.

So, could you please post the smallest code fragment which doesn't work when compiled by Gentoo cross-gcc, but does work when compiled by Atmel gcc?

I'm assuming that it does compile and link in the first place.
Comment 23 Aydin Tarik Zengin 2011-10-13 12:49:32 UTC
In my case, I could only give an example on arduino.

This is the shortest code which compiled fine and produce a working binary by Atmel toolchain, but a non-working binary by Gentoo cross gcc.

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
  Serial.print("Hello"); 
}

void loop() {    
}
Comment 24 Boris Borisov 2011-11-09 18:53:26 UTC
If I try to build my old simple project the compiler are generated :

avr-gcc -Wl,-Map,labelrollm8.out.map -lm  -mmcu=atmega8 -o labelrollm8.out main.o timers.o    
/usr/libexec/gcc/avr/ld: cannot find crtm8.o: No such file or directory
collect2: ld returned 1 exit status
make: *** [labelrollm8.out] Error 1

I try to look deep and add de verbouse comand:


$ avr-gcc -v -Wl,-Map,labelrollm8.out.map -lm  -mmcu=atmega8 -o labelrollm8.out main.o timers.o 
Using built-in specs.
COLLECT_GCC=/usr/i686-pc-linux-gnu/avr/gcc-bin/4.5.3/avr-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/avr/4.5.3/lto-wrapper
Target: avr
Configured with: /var/tmp/portage/cross-avr/gcc-4.5.3-r1/work/gcc-4.5.3/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/avr/gcc-bin/4.5.3 --includedir=/usr/lib/gcc/avr/4.5.3/include --datadir=/usr/share/gcc-data/avr/4.5.3 --mandir=/usr/share/gcc-data/avr/4.5.3/man --infodir=/usr/share/gcc-data/avr/4.5.3/info --with-gxx-include-dir=/usr/lib/gcc/avr/4.5.3/include/g++-v4 --host=i686-pc-linux-gnu --target=avr --build=i686-pc-linux-gnu --disable-altivec --disable-fixed-point --without-ppl --without-cloog --disable-lto --enable-nls --without-included-gettext --with-system-zlib --disable-werror --enable-secureplt --disable-multilib --disable-libmudflap --disable-libssp --disable-libgomp --with-python-dir=/share/gcc-data/avr/4.5.3/python --enable-checking=release --disable-libgcj --enable-languages=c,c++ --enable-shared --disable-threads --disable-bootstrap --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.5.3-r1 p1.0, pie-0.4.5'
Thread model: single
gcc version 4.5.3 (Gentoo 4.5.3-r1 p1.0, pie-0.4.5) 
COMPILER_PATH=/usr/libexec/gcc/avr/4.5.3/:/usr/libexec/gcc/avr/4.5.3/:/usr/libexec/gcc/avr/:/usr/lib/gcc/avr/4.5.3/:/usr/lib/gcc/avr/
LIBRARY_PATH=/usr/lib/gcc/avr/4.5.3/:/usr/lib/gcc/avr/4.5.3/../../../../avr/lib/
COLLECT_GCC_OPTIONS='-v' '-mmcu=atmega8' '-o' 'labelrollm8.out'
 /usr/libexec/gcc/avr/4.5.3/collect2 -m avr4 -o labelrollm8.out crtm8.o -L/usr/lib/gcc/avr/4.5.3 -L/usr/lib/gcc/avr/4.5.3/../../../../avr/lib -Map labelrollm8.out.map -lm main.o timers.o -lgcc -lc -lgcc
/usr/libexec/gcc/avr/ld: cannot find crtm8.o: No such file or directory
collect2: ld returned 1 exit status


The fail are during the linking the project with exact architecture. If I add the verbose command to linker I acheve:
$ /usr/libexec/gcc/avr/4.5.3/collect2 -verbose -m avr4 -o labelrollm8.out crtm8.o -L/usr/lib/gcc/avr/4.5.3 -L/usr/lib/gcc/avr/4.5.3/../../../../avr/lib -Map labelrollm8.out.map -lm main.o timers.o -lgcc -lc -lgcc
GNU ld (GNU Binutils) 2.21.1
  Supported emulations:
   avr2
   avr1
   avr25
   avr3
   avr31
   avr35
   avr4
   avr5
   avr51
   avr6
opened script file /usr/i686-pc-linux-gnu/avr/binutils-bin/2.21.1/../../../../avr/lib/ldscripts/avr4.x
using external linker script:
==================================================
/* Default linker script, for normal executables */
OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
OUTPUT_ARCH(avr:4)
MEMORY
{
------------------snip-----------------------------
  .debug_macinfo  0 : { *(.debug_macinfo) }
}

==================================================
attempt to open crtm8.o failed
attempt to open /usr/lib/gcc/avr/4.5.3/libm.so failed
attempt to open /usr/lib/gcc/avr/4.5.3/libm.a failed
attempt to open /usr/lib/gcc/avr/4.5.3/../../../../avr/lib/libm.so failed
attempt to open /usr/lib/gcc/avr/4.5.3/../../../../avr/lib/libm.a succeeded
attempt to open main.o succeeded
main.o
attempt to open timers.o succeeded
timers.o
attempt to open /usr/lib/gcc/avr/4.5.3/libgcc.so failed
attempt to open /usr/lib/gcc/avr/4.5.3/libgcc.a succeeded
(/usr/lib/gcc/avr/4.5.3/libgcc.a)_copy_data.o
(/usr/lib/gcc/avr/4.5.3/libgcc.a)_clear_bss.o
attempt to open /usr/lib/gcc/avr/4.5.3/libc.so failed
attempt to open /usr/lib/gcc/avr/4.5.3/libc.a failed
attempt to open /usr/lib/gcc/avr/4.5.3/../../../../avr/lib/libc.so failed
attempt to open /usr/lib/gcc/avr/4.5.3/../../../../avr/lib/libc.a succeeded
attempt to open /usr/lib/gcc/avr/4.5.3/libgcc.so failed
attempt to open /usr/lib/gcc/avr/4.5.3/libgcc.a succeeded
/usr/bin/avr-ld: cannot find crtm8.o: No such file or directory
collect2: ld returned 1 exit status

Probably someting wrong in compilation and some path because if I put the crtm8.o in source directory all files are compiled and linked corectly.
But that are incredible hard to change each time and replace the file in same source for diferent architectures.

Some ideas?
Comment 25 Jeroen Roovers (RETIRED) gentoo-dev 2011-12-04 06:54:41 UTC
*** Bug 393081 has been marked as a duplicate of this bug. ***
Comment 26 J.C. Wren 2011-12-04 15:06:06 UTC
(In reply to comment #7)
> The crossdev version has nothing to do with this error.
> 
> The real reason for this error is that gcc for avr needs to be compiled with
> multilib enabled in order to have a library path properly set.
> 
> How to get a working avr toolchain on non-multilib systems:
> a) Unmerge the broken gcc: emerge --unmerge cross-avr/gcc
> b) In /usr/portage/eclass/toolchain.eclass search for gcc-library-configure()
> function,
> c) Change "--disable-multilib" into "--enable-multilib" in this function
> d) Scroll few lines down to the gcc-compiler-configure() function and do the
> same
> there,
> e) Run crossdev -t avr to compile cross gcc again.
> 
> This worked for me on 32-bit x86 Gentoo.
> 
> Note that this is a terrible hack.
> Be sure to resync or undo the changes to toolchain.eclass later so you don't
> compile native gcc with multilib enabled by mistake.

Apparently the structure of toolchain.eclass has changed since this was originallu posted. In version "v 1.489 2011/12/03 20:45:45 vapier" of the file, I made the following changes starting at line 1004:

gcc-multilib-configure() {
    # if multilib is disabled, get out quick!
    #if ! is_multilib ; then
        #confgcc+=" --disable-multilib"
        #return
    #else
        confgcc+=" --enable-multilib"
    #fi

(basically commenting everything out except the one line). In addition, /usr/bin/crossdev from crossdev-20111018, line 457 needs the following change.

-GUSE_DISABLE_STAGE_1="${GUSE_DISABLE} -fortran nocxx -openmp"
+GUSE_DISABLE_STAGE_1="${GUSE_DISABLE} -fortran nocxx -cxx -openmp"

Tthe following commands build a working toolchain with gcc-4.5.2, binutils-2.22 and avr-libc-1.7.0 on an x86 machine:

# crossdev -C avr
# cp gcc-4.5.2.ebuild /usr/portage/sys-devel/gcc
# cp gcc-005-constructor.patch /usr/portage/sys-devel/gcc/files
# ebuild /usr/portage/sys-devel/gcc/gcc-4.5.2.ebuild manifest
# ln -s /usr/lib/binutils/avr/2.22/ldscripts /usr/i686-pc-linux-gnu/avr/binutils-bin/2.22/ldscripts
# USE="-openmp" crossdev -t avr --l 1.7.0 --g 4.5.2 -s4 --without-headers

The gcc-005-constructor patch is necessary for AVR cores supporting the RAMPZ instruction. See attachments for the above two files that are copied. gcc-4.5.2.ebuild has the addition of the following after line 45:

    [[ ${CTARGET} == *avr* ]] && epatch "${FILESDIR}"/gcc-005-constructor.patch

There's probably some more elegant and correct way to enable multilib in the toolchain.eclass using a conditional based on the target. Since this was actually holding me up from producing an AVR-based deliverable for a client, I didn't have time to figure out how to properly correct it. It's a nasty brute-force approach, and the toolchain.ebuild changes should be removed after a successful build, as it's likely it will break something it shouldn't.
Comment 27 J.C. Wren 2011-12-04 15:07:27 UTC
Created attachment 294747 [details]
gcc-4.5.2.ebuild with addition of gcc-005-constructor patch

This is the gcc-4.5.2.ebuild file with the single line added at line 45 to apply the gcc-005-constructor patch for AVR processors.
Comment 28 J.C. Wren 2011-12-04 15:09:25 UTC
Created attachment 294749 [details, diff]
gcc-005-constructor patch to save R20 in _ctors and _dtors

This patch causes R20 to be saved in the _ctors and _dtors functions. On AVR cores with the RAMPZ instruction, the compiler will produce non-functional code without this patch.
Comment 29 SpanKY gentoo-dev 2012-03-02 19:04:13 UTC
*** Bug 378387 has been marked as a duplicate of this bug. ***
Comment 30 Jess Haas 2012-03-02 21:44:12 UTC
Created attachment 304037 [details, diff]
crossdev-avrMultilib.patch
Comment 31 Jess Haas 2012-03-02 21:46:27 UTC
I attached a patch which fixes this problem by enabling multilib only for the avr target.

The gcc constructor problems and patch should really be in a separate bug report.
Comment 32 SpanKY gentoo-dev 2012-08-10 04:24:49 UTC
*** Bug 429994 has been marked as a duplicate of this bug. ***
Comment 33 SpanKY gentoo-dev 2012-08-30 18:07:29 UTC
Comment on attachment 294747 [details]
gcc-4.5.2.ebuild with addition of gcc-005-constructor patch

not relevant to this bug ...
Comment 34 SpanKY gentoo-dev 2012-08-30 18:07:35 UTC
Comment on attachment 294749 [details, diff]
gcc-005-constructor patch to save R20 in _ctors and _dtors

not relevant to this bug ...