r1 is not backed up when calling to naked function

Bug #1809607 reported by Alexander Zilberkant
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
Fix Released
Undecided
Unassigned

Bug Description

According to AAPCS r1 register is a caller-save and can be used as a scratch register by called function.
Thus toolchain should generate registers backing up code in caller function , before branching to callee.

The problem is emphasized in PR https://github.com/ARMmbed/mbed-os/pull/9128

In our case, callee is a naked function (call_mem) which modifies r1 register. There are no instructions generated to backup up r1 register in test_memory() before branching to naked function.

Thus i assume it is a bug in a tool chain.

Revision history for this message
stewo (wolfer-y) wrote : [Autoreply] [Bug 1809607] [NEW] r1 is not backed up when calling to naked function

Ich bin bis 07.01. nicht im Haus und kann Ihre Nachricht daher leider nicht bearbeiten. In dringenden Fällen wenden Sie sich bitte an <email address hidden> bzw. für technische Fragen an <email address hidden>.

I am out of office until January 7th and won't be able to read your message. In urgent cases, please refer to <email address hidden> or for technical questions to <email address hidden>.

Mit freundlichen Grüßen / Best regards

Steffen Wolfer

--
Dipl.-Inform. Steffen Wolfer
Software Engineer Embedded Systems

WEISS ROBOTICS GmbH & Co. KG
Karl-Heinrich-Käferle-Str. 8
D-71640 Ludwigsburg, Germany

Phone: +49 7141 94702-22
Fax: +49 7141 94702-99
http://www.weiss-robotics.com

Sitz der Gesellschaft: Ludwigsburg
Registergericht Stuttgart, HRA725006

Pers. haftende Gesellschafterin:
Weiss Robotics Verwaltungs-GmbH, Sitz Ludwigsburg
Registergericht Stuttgart, HRB73310
Geschäftsführer: Dr. Karsten Weiß

Public bug reported:

According to AAPCS r1 register is a caller-save and can be used as a scratch register by called function.
Thus toolchain should generate registers backing up code in caller function , before branching to callee.

The problem is emphasized in PR https://github.com/ARMmbed/mbed-
os/pull/9128

In our case, callee is a naked function (call_mem) which modifies r1
register. There are no instructions generated to backup up r1 register
in test_memory() before branching to naked function.

Thus i assume it is a bug in a tool chain.

** Affects: gcc-arm-embedded
     Importance: Undecided
         Status: New

--
You received this bug notification because you are subscribed to GNU Arm
Embedded Toolchain.
Matching subscriptions: Älles
https://bugs.launchpad.net/bugs/1809607

Title:
  r1 is not backed up when calling to naked function

Status in GNU Arm Embedded Toolchain:
  New

Bug description:
  According to AAPCS r1 register is a caller-save and can be used as a scratch register by called function.
  Thus toolchain should generate registers backing up code in caller function , before branching to callee.

  The problem is emphasized in PR https://github.com/ARMmbed/mbed-
  os/pull/9128

  In our case, callee is a naked function (call_mem) which modifies r1
  register. There are no instructions generated to backup up r1 register
  in test_memory() before branching to naked function.

  Thus i assume it is a bug in a tool chain.

To manage notifications about this bug go to:
https://bugs.launchpad.net/gcc-arm-embedded/+bug/1809607/+subscriptions

Revision history for this message
Andreas Fritiofson (andreas-fritiofson) wrote :

The referenced code doesn't include the modified register in the clobber list of the inline asm. Does adding r1 there fix the problem?

Revision history for this message
Alexander Zilberkant (alzix) wrote : Re: [Bug 1809607] Re: r1 is not backed up when calling to naked function

yes

On Wed, May 29, 2019 at 11:26 AM Andreas Fritiofson <
<email address hidden>> wrote:

> The referenced code doesn't include the modified register in the clobber
> list of the inline asm. Does adding r1 there fix the problem?
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1809607
>
> Title:
> r1 is not backed up when calling to naked function
>
> Status in GNU Arm Embedded Toolchain:
> New
>
> Bug description:
> According to AAPCS r1 register is a caller-save and can be used as a
> scratch register by called function.
> Thus toolchain should generate registers backing up code in caller
> function , before branching to callee.
>
> The problem is emphasized in PR https://github.com/ARMmbed/mbed-
> os/pull/9128
>
> In our case, callee is a naked function (call_mem) which modifies r1
> register. There are no instructions generated to backup up r1 register
> in test_memory() before branching to naked function.
>
> Thus i assume it is a bug in a tool chain.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/gcc-arm-embedded/+bug/1809607/+subscriptions
>

Revision history for this message
Vikas Katariya (jainvikas8) wrote :

Hi,

   Is this issue related to the compiler?
   Please, could you do the needful to update this ticket?

Thanks.

Revision history for this message
Ramana Radhakrishnan (ramana) wrote :

No this isn't. If the register isn't in the clobber list or the output list, there's no way the compiler can divine what's happening here. See documentation here for more - https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html

I would reject this ticket as user error and thus invalid.

regards
Ramana

Changed in gcc-arm-embedded:
status: New → Invalid
Changed in gcc-arm-embedded:
status: Invalid → Fix Released
Revision history for this message
Richard Sandiford (rsandifo-arm) wrote :

I think it was actually a genuine bug, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85593
This ticket predates the fix, but the fix was included in the latest release (2019-q3-update).

Note that naked functions must only have basic asms, not extended asms, so the asm pointed
to in the bug description was correct not to have a clobber list.

Thanks,
Richard

Revision history for this message
Ramana Radhakrishnan (ramana) wrote :

ACtually I've just been told I'm wrong and I'd misunderstood this.

This should be reopened.

Revision history for this message
Ramana Radhakrishnan (ramana) wrote :
Revision history for this message
Vikas Katariya (jainvikas8) wrote :

Please could you clarify:
* Does extended asm apply to naked functions?
* Should the caller of naked function backup the registers?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.