Mon 04 Nov 2002 10:50:28 PM UTC, original submission:
The functions in the .ctors section, which should get called during runtime initialization, are being removed when using linker garbage collection.
I compiled using the 2.0 release with the following options:
$ m6812-elf-gcc -v
Reading specs from /cygdrive/c/m6812-elf-tools/lib/gcc-lib/m6812-elf/3.0.4/specs
Configured with: ./configure --target=m6812-elf --program-prefix=m6812-elf- --prefix=/cygdrive/c/m6812-elf-tools --exec-prefix=/cygdrive/c/m6812-elf-tools --enable-languages=c,c++
Thread model: single
gcc version 3.0.4 m68hc1x-20020922
$ m6812-elf-gcc -m68hc12 -mshort -mauto-incdec -msoft-reg-count=0 -Wall -ggdb -Os -mrelax -finline -ffixed-z -fomit-frame-pointer -fno-rtti -fno-exceptions -fshort-enums -ffunction-sections -c foo.cpp
and I link with:
$ m6812-elf-gcc -m68hc12 -mshort -mauto-incdec -msoft-reg-count=0 -Wl,-T,m68hc12elfb.x -Wl,-N -Wl,-M -Wl,--gc-sections -Wl,--cref -Wl,-m,m68hc12elfb -o foo.elf
As an example, I created foo.cpp:
---------------------------------------------------
static int foo(void);
int foo(void)
{
volatile int baz = 0x42;
return baz;
}
int bar = foo();
---------------------------------------------------
When compiled with -Wl,--gc-sections, bar is not initialized. When I remove -Wl,--gc-sections, bar is correctly initialized to 0x42.
|