http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57838
Bug ID: 57838 Summary: GCC does not obey #pragma long_calls with builtins and -Os on cortexM3 Product: gcc Version: 4.7.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: zgtamuam84 at snkmail dot com Created attachment 30470 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30470&action=edit C code I am compiling an application for the cortexM3 where stdlib is in ROM and the applictaion runs in RAM. To call ROM from RAM I need to use long-calls. so I build as follows: gcc -mcpu=cortex-m3 -mthumb -Wall -Wextra -std=gnu99 -Os -c test.c The resulting disassembly shows that memset wasn't called via a long-call method: test.o: file format elf32-littlearm Disassembly of section .text.startup: Disassembly of section .text.startup: 00000000 <main>: 0: b508 push {r3, lr} 2: f7ff fffe bl 0 <tfunc> 6: 2100 movs r1, #0 8: 2264 movs r2, #100 ; 0x64 a: 4802 ldr r0, [pc, #8] ; (14 <main+0x14>) c: f7ff fffe bl 0 <memset> 10: 2000 movs r0, #0 12: bd08 pop {r3, pc} 14: 00000000 .word 0x00000000 The tfunc() call is a short-jump as expected, but the memset() call is also short which is not expected. removing -Os, or compiling with -fno-builtin or removing the #pragma no_long_calls all work-around the issue and generate a long-call to memset(). In my application, I want non standard-lib functions to use short-calls (thus the '#pragma no_long_calls' after header inclusion), and I want builtins to be used when possible (thus I don't want to use -fno-builtin) I have tested on gcc 4.6.2 and 4.7.3, both of which exhibit this behavior.