This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Bug ld/21458] ld generates none ARM elf ABI compliant code that causes a hard fault.


Hi Nick

Thanks for the merge.

I can't generate a test case because using gas, the ADR instruction
insists that the label be in the same section and file. So no
relocation is generated because the only code the assembler generates
is PC relative and therefore does not require relocation. I am
guessing this is why the problem was hidden for so long.

Unfortunately we may potentially have another problem. When trying to
generate a test case I came across the following.

The test case below generates incorrect code for the ADR instruction
in conjunction with a thumb_func target..
------------------------

.syntax unified
.thumb
.text
.align 2
.global __testFnPtr
.type __testFnPtr, %function
.thumb_func
__testFnPtr:
   bx lr

.global __testArmThmAluPre
.type __testArmThmAluPre, %function
.thumb_func
__testArmThmAluPre:
    Push {LR}
    ADR R0,__testFnPtr
    BLX R0
    Pop {PC}

-------------------------
this results in the following disassembly

                     __testFnPtr:
000098e8: 0x00007047   bx      lr
                     __testArmThmAluPre:
000098ea: 0x000000b5   push    {lr}
000098ec: 0xaff20800   subw    r0, pc, #8
000098f0: 0x00008047   blx     r0
000098f2: 0x000000bd   pop     {pc}

The problem is that the thumb bit is not set ( subw    r0, pc, #8
results in an even address) and that this code causes a hard fault.

Now I don't know my assembly as well as I should so there might be
wrong/missing directives in the above file. Comment welcome

regards

Andrew Goedhart

On Tue, May 9, 2017 at 1:21 PM, nickc at redhat dot com
<sourceware-bugzilla@sourceware.org> wrote:
> https://sourceware.org/bugzilla/show_bug.cgi?id=21458
>
> Nick Clifton <nickc at redhat dot com> changed:
>
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Status|UNCONFIRMED                 |RESOLVED
>                  CC|                            |nickc at redhat dot com
>          Resolution|---                         |FIXED
>
> --- Comment #5 from Nick Clifton <nickc at redhat dot com> ---
> Hi Andrew,
>
>   I am very sorry for dropping the ball on this PR and not reviewing it until
> now.
>
>   I have gone ahead and checked in your patch.  One thing extra that I would
> like to do is to add a new testcase to the linker testsuite, to make sure that
> this problem stays fixed.  Do you have some (small) assembler sources that can
> be used to trigger this bug ?
>
> Cheers
>   Nick
>
> --
> You are receiving this mail because:
> You are on the CC list for the bug.
> You reported the bug.



-- 
Andrew Goedhart
Tel: +27 84 924 5225
Simple Power Solutions, 14 Heron Way, Pinelands, 7405


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]