This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: call instruction question
On Thu, Jan 10, 2013 at 10:09:48AM -0800, Ian Lance Taylor wrote:
> On Wed, Jan 9, 2013 at 2:14 PM, horseriver <horserivers@gmail.com> wrote:
> >
> > 1. why use "fc ff ff ff " in call instruction?
>
> Answered by John Fine.
>
> > 2. In my .c source file ,I have not used strcpy function , so why it is disassembly out here ?
> > after research , I find this call instruction is corresponding to this line :
> >
> > sprintf(acpi_device_name(device), "%s", ACPI_EC_DEVICE_NAME);
> > sprintf is a externel implemented function .
> >
> > but why in disassebly code it is strcpy ?
> >
> > whether something wrong with relocation data?
>
> This is a GCC optimization. GCC converts
> sprintf(buf, "%s", arg);
> into
> strcpy(buf, arg);
> because the operations are equivalent and strcpy is more efficient.
> By default GCC assumes that it can call any function in the C standard
> library.
yes! I understand what you mean !
I should not blame gcc's optimization , but here it has caused an error :
when linking , ld will look for this strcpy's implemention and fill into this .o
file with strcpy's address . In my project , strcpy is implemented in source code.
so I linked this .o file with that .o which has implemented strcpy , but ld reported this to me :
undefined reference to `strcpy' at this .o file
I could not understand this . Is there some advice ?
> To turn off this assumption, use the -fno-hosted option that
> I already mentioned earlier.
>
> Ian