Bug 20803 - Sparc R_SPARC_32 reloc with miss-align offset.
Summary: Sparc R_SPARC_32 reloc with miss-align offset.
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.27
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-11 05:49 UTC by Chris Johns
Modified: 2017-03-30 20:13 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Sparc ASM showing the miss-aligned R_SPARC_32 reloc offset. (1.55 KB, text/plain)
2016-11-11 05:49 UTC, Chris Johns
Details
Proposed patch (320 bytes, patch)
2016-11-11 14:04 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Johns 2016-11-11 05:49:20 UTC
Created attachment 9621 [details]
Sparc ASM showing the miss-aligned R_SPARC_32 reloc offset.

I am looking into:

https://devel.rtems.org/ticket/2802 

where a R_SPARC_32 reloc record with a miss-aligned offset results in a crash. We do not expect a R_SPARC_32 to be miss-aligned.

The source is:

https://git.rtems.org/rtems/tree/testsuites/libtests/dl05/dl-o5.cpp

It seems like emit_expr_fix is being called and it calls TC_CONS_FIX_NEW() without the sparc_no_align_cons being true so R_SPARC_32 reloc type is selected in cons_fix_new_sparc.

I do not know if this is an issue in selecting the reloc type, ie sparc_no_align_cons should be true, or the offset should never be miss-aligned.

I attach a .s source file that shows the issue. It has been edited removing the .debug output from gcc.
Comment 1 Nick Clifton 2016-11-11 14:04:19 UTC
Created attachment 9623 [details]
Proposed patch

Hi Chris,

  Please could you try out this patch and let me know if it is enough to solve the problem.

  I am not sure if this approach is the correct way to fix the issue, but it does seem to be the simplest.  As far as I can tell, the relocs in the .eh_frame section can eb unaligned, so using R_SPARC_UA32 seems to be the correct thing to do.  I did look to see if I could enable sparc_no_align_cons when fixing the output for the .eh_frame section, but I could not find an easy way to do this. Hence I went for a hack based on the section name.  Not very subtle, but if it works then that is enough for now.

Cheers
  Nick
Comment 2 Chris Johns 2016-11-14 22:41:43 UTC
(In reply to Nick Clifton from comment #1)
> Created attachment 9623 [details]
> Proposed patch

Thank you for the quick turn around.

> 
>   Please could you try out this patch and let me know if it is enough to
> solve the problem.
> 

Yes, this solves the problem we are seeing.

>   I am not sure if this approach is the correct way to fix the issue, but it
> does seem to be the simplest.  As far as I can tell, the relocs in the
> .eh_frame section can eb unaligned, so using R_SPARC_UA32 seems to be the
> correct thing to do.  I did look to see if I could enable
> sparc_no_align_cons when fixing the output for the .eh_frame section, but I
> could not find an easy way to do this. Hence I went for a hack based on the
> section name.  Not very subtle, but if it works then that is enough for now.

I also had a look and felt any change was a potential issue for some other reason I would not be aware of. We will use this patch in RTEMS until the next binutils release.

Thank you.
Comment 3 cvs-commit@gcc.gnu.org 2016-11-15 15:42:31 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

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

commit 93ca393659ef6714724749950301757f47e5e9fd
Author: Nick Clifton <nickc@redhat.com>
Date:   Tue Nov 15 15:41:27 2016 +0000

    Fix SPARC relocations generated for the .eh_frame section.
    
    	PR gas/20803
    	* config/tc-sparc.c (cons_fix_new_sparc): Use unaligned relocs in
    	the .eh_frame section.
Comment 4 Nick Clifton 2016-11-15 15:44:44 UTC
Patch applied.
Comment 5 Chris Johns 2017-03-30 03:51:29 UTC
I have just tested binutils 2.27 with the patch and 2.28 that contains this patch and the issue is back. The reloc details from readelf are:

Relocation section '.rela.gcc_except_table.exception_dl' at offset 0x51cc contains 2 entries:
 Offset     Info    Type                Sym. Value  Symbol's Name + Addend
00000040  00002a03 R_SPARC_32             00000000   _ZTISt9exception + 0
00000044  00002403 R_SPARC_32             00000000   _ZTI16dl_test_throw_me + 0

Relocation section '.rela.rodata._ZTI16dl_test_throw_me' at offset 0x51e4 contains 2 entries:
 Offset     Info    Type                Sym. Value  Symbol's Name + Addend
00000000  00002c03 R_SPARC_32             00000000   _ZTVN10__cxxabiv117__class_type_infoE + 8
00000004  00002b03 R_SPARC_32             00000000   _ZTS16dl_test_throw_me + 0

The R_SPARC_32 should be R_SPARC_UA32.

I do not know how we reopen this bug.
Comment 6 Chris Johns 2017-03-30 20:13:58 UTC
(In reply to Chris Johns from comment #5)
> I have just tested binutils 2.27 with the patch and 2.28 that contains this
> patch and the issue is back. The reloc details from readelf are:

This was a bug in the RTEMS ELF loader. I am sorry about the noise.