Bug 19405

Summary: nios2 binutils assertion fail at elf32-nios2.c:1038
Product: binutils Reporter: Thomas Petazzoni <thomas.petazzoni>
Component: binutilsAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: nickc, romain.naour
Priority: P2    
Version: 2.25   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed: 2016-01-19 00:00:00
Attachments: Fix assertion, reduce number of messages about FDE encoding

Description Thomas Petazzoni 2015-12-27 14:51:27 UTC
When compiling the gtkmm3 project on the nios2 architecture using a gcc 5.3.0 / binutils 2.25 toolchain, at the moment of linking the final shared library, I get tons of:

/home/test/outputs/gtkmm3-nios2-internal/host/usr/lib/gcc/nios2-buildroot-linux-gnu/5.3.0/../../../../nios2-buildroot-linux-gnu/bin/ld: BFD (GNU Binutils) 2.25
.1 assertion fail elf32-nios2.c:1038

This message follows gazillions of:

/home/test/outputs/gtkmm3-nios2-internal/host/usr/lib/gcc/nios2-buildroot-linux-gnu/5.3.0/../../../../nios2-buildroot-linux-gnu/bin/ld: FDE encoding in .libs/s
tockid.o(.eh_frame) prevents .eh_frame_hdr table being created.

messages. The link command line is:

libtool: link: /home/test/outputs/gtkmm3-nios2-internal/host/usr/bin/nios2-buildroot-linux-gnu-g++  -fPIC -DPIC -shared -nostdlib /home/test/outputs/gtkmm3-nio
s2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib/crti.o /home/test/outputs/gtkmm3-nios2-internal/host/usr/lib/gcc/nios2-buildroot-linux-gnu/5.3.0
/crtbeginS.o  .libs/applaunchcontext.o .libs/cursor.o .libs/device.o .libs/devicemanager.o .libs/display.o .libs/displaymanager.o .libs/dragcontext.o .libs/eve
nt.o .libs/pixbuf.o .libs/pixbufanimation.o .libs/pixbufanimationiter.o .libs/pixbufformat.o .libs/pixbufloader.o .libs/rectangle.o .libs/rgba.o .libs/screen.o
 .libs/timecoord.o .libs/types.o .libs/visual.o .libs/window.o .libs/color.o .libs/wrap_init.o .libs/general.o   -Wl,-rpath -Wl,/home/test/outputs/gtkmm3-nios2
-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib -Wl,-rpath -Wl,/home/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot
/usr/lib -L/home/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib /home/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-
buildroot-linux-gnu/sysroot/usr/lib/libgiomm-2.4.so /home/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib/libpangomm-1.4.
so /home/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib/libglibmm-2.4.so /home/test/outputs/gtkmm3-nios2-internal/host/u
sr/nios2-buildroot-linux-gnu/sysroot/usr/lib/libgtk-3.so /home/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib/libgdk-3.s
o /home/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib/libpangocairo-1.0.so /home/test/outputs/gtkmm3-nios2-internal/hos
t/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib/libpango-1.0.so /home/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib/lib
atk-1.0.so /home/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib/libcairo-gobject.so /home/test/outputs/gtkmm3-nios2-inte
rnal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib/libgio-2.0.so /home/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/l
ib/libcairomm-1.0.so /home/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib/libcairo.so /home/test/outputs/gtkmm3-nios2-in
ternal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib/libsigc-2.0.so /home/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/us
r/lib/libgdk_pixbuf-2.0.so /home/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib/libgobject-2.0.so /home/test/outputs/gtk
mm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib/libglib-2.0.so -L/home/test/outputs/gtkmm3-nios2-internal/host/usr/lib/gcc/nios2-buildroo
t-linux-gnu/5.3.0 -L/home/test/outputs/gtkmm3-nios2-internal/host/usr/lib/gcc/nios2-buildroot-linux-gnu/5.3.0/../../../../nios2-buildroot-linux-gnu/lib -L/home
/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/lib -lstdc++ -lm -lc -lgcc_s /home/test/outputs/gtkmm3-nios2-internal/host/usr/l
ib/gcc/nios2-buildroot-linux-gnu/5.3.0/crtendS.o /home/test/outputs/gtkmm3-nios2-internal/host/usr/nios2-buildroot-linux-gnu/sysroot/usr/lib/crtn.o  -Os   -pth
read -Wl,-soname -Wl,libgdkmm-3.0.so.1 -o .libs/libgdkmm-3.0.so.1.1.0

Steps to reproduce:

$ git clone git://git.busybox.net/buildroot
$ cd buildroot
$ cat > .config <<EOF
BR2_nios2=y
BR2_GCC_VERSION_5_X=y
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_PACKAGE_GTKMM3=y
EOF
$ make olddefconfig
$ make

(this will build a nios2 toolchain from scratch, then build all the dependencies of gtkmm3 and finally fail at the gtkm33 link step)

I apologize for not providing a simpler/faster way of reproducing, but since the issue appears at link time, it is not trivial to provide all the necessary object files and shared libraries.
Comment 1 Nick Clifton 2016-01-19 11:30:55 UTC
Hi Thomas,

  I just tried to reproduce the problem, following the steps that you suggested, and nothing went wrong....  Please could you check that the bug still exists for you.

  I was running the build on an x86_64 machine running Fedora 23, perhaps that makes a difference ?

Cheers
  Nick
Comment 2 Thomas Petazzoni 2016-01-19 14:03:00 UTC
(In reply to Nick Clifton from comment #1)
> Hi Thomas,
> 
>   I just tried to reproduce the problem, following the steps that you
> suggested, and nothing went wrong....  Please could you check that the bug
> still exists for you.
> 
>   I was running the build on an x86_64 machine running Fedora 23, perhaps
> that makes a difference ?
> 
> Cheers
>   Nick

Thanks Nick for testing! After reporting this bug, we have marked the gtkmm3 package as not available on nios2, as a temporary workaround. So in fact, your build is not building gtkmm3.

Could you instead do:

$ git clone git://git.busybox.net/buildroot
$ cd buildroot
$ git checkout 09649f2a305e0b9d52555c35c24178255aa298df
$ cat > .config <<EOF
BR2_nios2=y
BR2_GCC_VERSION_5_X=y
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_PACKAGE_GTKMM3=y
EOF
$ make olddefconfig
$ make

Thanks a lot!
Comment 3 Nick Clifton 2016-01-19 16:26:17 UTC
Created attachment 8912 [details]
Fix assertion, reduce number of messages about FDE encoding

Hi Thomas,

  Thanks - I can now reproduce the problem.

  The assertion failures were due to a thinko - the test was not allowing for negative values.  The FDE encoding warnings are correct, but there really are too many of them.

  So please try out this patch.  It should fix the assertion and reduce the number of warnings about FDE encoding to 10.  If this works for you then I will commit it to the mainline sources.

Cheers
  Nick
Comment 4 Thomas Petazzoni 2016-01-19 16:29:25 UTC
(In reply to Nick Clifton from comment #3)
> Created attachment 8912 [details]
> Fix assertion, reduce number of messages about FDE encoding
> 
> Hi Thomas,
> 
>   Thanks - I can now reproduce the problem.
> 
>   The assertion failures were due to a thinko - the test was not allowing
> for negative values.  The FDE encoding warnings are correct, but there
> really are too many of them.
> 
>   So please try out this patch.  It should fix the assertion and reduce the
> number of warnings about FDE encoding to 10.  If this works for you then I
> will commit it to the mainline sources.
> 
> Cheers
>   Nick

Thanks for the patch! Note that I am not able to do a runtime test as I don't have any NIOS2 platform, so all I can do is a build time test.

Regarding the FDE encoding warnings, what do they mean exactly?
Comment 5 Nick Clifton 2016-01-19 16:57:02 UTC
Hi Thomas,

(In reply to Thomas Petazzoni from comment #4)
> Regarding the FDE encoding warnings, what do they mean exactly?

They mean that the binary search table that is part of the .eh_frame_hdr section cannot be created.  This happens because the (compiler generated) debug information for the entries in the .eh_frame section use absolute addresses not PC-relative addresses.  That means that at run time those addresses will have to be relocated (to wherever the library is being loaded).  Hence it is not safe to create a binary search table in the .eh_frame_hdr section as the addresses are not fixed.

  In practice the warning is not serious.  It just means that exception handling might be slower than it could be, but it should still work.

Cheers
  Nick
Comment 6 Thomas Petazzoni 2016-01-19 16:59:50 UTC
(In reply to Nick Clifton from comment #5)

> (In reply to Thomas Petazzoni from comment #4)
> > Regarding the FDE encoding warnings, what do they mean exactly?
> 
> They mean that the binary search table that is part of the .eh_frame_hdr
> section cannot be created.  This happens because the (compiler generated)
> debug information for the entries in the .eh_frame section use absolute
> addresses not PC-relative addresses.  That means that at run time those
> addresses will have to be relocated (to wherever the library is being
> loaded).  Hence it is not safe to create a binary search table in the
> .eh_frame_hdr section as the addresses are not fixed.
> 
>   In practice the warning is not serious.  It just means that exception
> handling might be slower than it could be, but it should still work.

Great, thanks a lot for the explanation! I will try your patch soon and report back.
Comment 7 romain.naour 2016-02-06 13:38:46 UTC
Hi Nick, Thomas,

Thanks for your patch!
I tried it over binutils 2.26 release which is currently broken for nios2 toolchain.

First we need to backport [1] to be able to build glibc.
Then I applied your patch and build gtkmm3 package.
Also the same issue with qt (4.8.7) is fixed [2].

But not for imagemagick package which initially failed with [3] and now fail with:

  CC       magick/magick_libMagickCore_6_Q16_la-pixel.lo
/tmp/ccXCSISE.s: Assembler messages:
/tmp/ccXCSISE.s:13821: Error: r31 cannot be used with jmp; use ret instead
/tmp/ccXCSISE.s:14446: Error: r31 cannot be used with jmp; use ret instead
Makefile:8776: recipe for target 'magick/magick_libMagickCore_6_Q16_la-pixel.lo' failed
make[3]: *** [magick/magick_libMagickCore_6_Q16_la-pixel.lo] Error 1

I wanted to let you know this issue.
It's ok to disable imagemagick for now.

Binutils 2.26 is not upstream yet, I pushed a branch in github [4] if you want to try using this config:

$ cat > .config <<EOF
BR2_nios2=y
BR2_COMPILER_PARANOID_UNSAFE_PATH=y
BR2_GLIBC_VERSION_2_22=y
BR2_BINUTILS_VERSION_2_26_X=y
BR2_GCC_VERSION_5_X=y
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_PACKAGE_IMAGEMAGICK=y
EOF

Best regards,
Romain

[1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=a7be2893a6449e64fe6cfcdd8700b0a367a69f19

[2] http://autobuild.buildroot.net/results/59f/59fdd94bfaf4f6fb7367f5b2f0b56e2acdd371c7/build-end.log

[3] http://autobuild.buildroot.net/results/0bf/0bf3a2a284b7d4712ab1530562d3b8164fc75e88/build-end.log

[4] https://github.com/RomainNaour/buildroot/tree/nios2-binutils
Comment 8 Sourceware Commits 2016-02-10 11:27:20 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=83da6e748c8f105f07e17f53aa6b99ed7867ff5f

commit 83da6e748c8f105f07e17f53aa6b99ed7867ff5f
Author: Nick Clifton <nickc@redhat.com>
Date:   Wed Feb 10 11:25:59 2016 +0000

    Correct assertion in NIOS2 linker to allow signed 16-buit immediate values.
    
    	PR 19405
    	* elf32-nios2.c (nios2_elf32_install_imm16): Allow for signed
    	immediate values.
    	* elf-eh-frame.c (_bfd_elf_discard_section_eh_frame): Limit the
    	number of messages about FDE encoding preventing .eh_frame_hdr
    	generation.
Comment 9 Nick Clifton 2016-02-10 11:31:00 UTC
Hi Romain. Hi Thomas.

  OK - I have applied the patch and I am closing this PR.

This:

> /tmp/ccXCSISE.s:13821: Error: r31 cannot be used with jmp; use ret instead
> /tmp/ccXCSISE.s:14446: Error: r31 cannot be used with jmp; use ret instead

is a seperate bug, and very likely a gcc bug rather than a binutils one.  (Assuming that gas is correct in saying that r31 cannot be used with jmp).  

Please could you file a new, gcc, bug report, preferably with the source file and gcc command line that triggers the problem, so that it can be investigated.

Cheers
  Nick