Hello again,
I'm continuing my work on an ARM Cortex-M port of the D Runtime.
I now have a repository
(https://github.com/JinShil/D_Runtime_ARM_Cortex-M_study) and a
wiki
(https://github.com/JinShil/D_Runtime_ARM_Cortex-M_study/wiki/1.0-Introduction)
for anyone interested. I'm doing my best to document the entire
process.
I tried playing with GDC/GCC optimizations recently, and noticed
that it breaks the following simple code from my "Hello World"
experiment
(http://wiki.dlang.org/Extremely_minimal_semihosted_%22Hello_World%22)
void OnReset()
{
while(true)
{
// Create semihosting message
uint[3] message =
[
2, //stderr
cast(uint)"hello\r\n".ptr, //ptr to string
7 //size of string
];
//Send semihosting command
SendCommand(0x05, &message);
}
}
Compiling with...
arm-none-eabi-gdc -O1 start.d -o start.o
... works fine, but compiling with...
arm-none-eabi-gdc -O2 start.d -o start.o
... or ...
arm-none-eabi-gdc -O3 start.d -o start.o
... does not.
I traced this down to the -finline-small-functions and
-fipa-cp-clone options, so if I compile with...
arm-none-eabi-gdc -O2 -fno-inline-small-functions start.d -o
start.o
... or ...
arm-none-eabi-gdc -O3 -fno-inline-small-functions
-fno-ipa-cp-clone start.d -o start.o
... it works fine.
Comparing the assembly generated with...
arm-none-eabi-gdc -O1 start.d -o start.o
... and ...
arm-none-eabi-gdc -O2 start.d -o start.o
... I can see that the "hello\r\n" string constant vanishes from
the assembly file with the -O2 option.
"So what's the question, Mike?" I hear you say:
1. Is this just one of the consequences of using -O2/-O3, and I
should just suck it up and deal with it?
2. Is this potentially a bug in the GCC backend?
3. Is this potentially a bug in GDC or the DMD frontend?
Thanks for the help,
Mike