Issue with LTO (-flto) in assembly and C combined

Asked by Mahavir

Please see following code snippet:
--------------------------------------
$ cat x.c
void _exit(int code)
{
 while(1);
}

int add(int a, int b)
{
  return a+b;
}

void main()
{
 __asm volatile ("mov r0, #1");
 __asm volatile ("mov r1, #2");
 __asm volatile ("b add");
}
-------------------------------------

If compiled using following options it gives error,

$ arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -flto x.c
`add' referenced in section `.text' of /tmp/cclOkQHk.ltrans0.ltrans.o: defined in discarded section `.text' of /tmp/cccxizqr.o (symbol from plugin)
collect2: error: ld returned 1 exit status

$ arm-none-eabi-gcc -v
gcc version 4.8.4 20140725 (release) [ARM/embedded-4_8-branch revision 213147]

Based on above I have few questions:

1. Is this code snippet correct (at-least it works without -flto)?
2. Any workarounds to overcome this problem?

Thanks.

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Terry Guo (terry.guo) said :
#1

After the 4.8 releases, the whole LTO has been improved a lot in upstream gcc community. I can confirm that our upcoming 4.9 release fixes this issue. Since the changes are huge, we are not going to backport those changes to 4.8 release. I would suggest you to try the 4.9 major release which will be published in December 2014.

Can you help with this problem?

Provide an answer of your own, or ask Mahavir for more information if necessary.

To post a message you must log in.