optimization bug: -O3 (-finline?) sometimes fails to keep a copy of a function.
Doug Kilpatrick
doug@visix.com
Mon Feb 2 13:44:00 GMT 1998
Test case consists of two files: driver.cxx and main.cxx
/* ------------- driver.cxx: ---------------- */
#include <stdio.h>
typedef void *(*fooFunc)(void *, void *, unsigned int);
typedef struct driver_struct
{
fooFunc foo;
fooFunc bar;
fooFunc baz;
} driver_struct;
static void * foo(void *vp, void *vp2, unsigned int ui)
{
printf("Foo.\n");
return NULL;
}
static const driver_struct driver = { foo, foo, foo };
void *api_hook(void *vp, void *vp2, unsigned int ui)
{
return driver.foo(vp,vp2,ui);
}
/*------------------- main.cxx: ------------------- */
#include <stdlib.h>
extern void* api_hook(void *vp, void *vp2, unsigned int ui);
int main(int argc, char *argv[])
{
return ((api_hook(NULL,NULL,0) == NULL));
}
Demonstration of the problem:
% g++ -O3 -c driver.cxx
% g++ -O3 -c main.cxx
% g++ -o a.out driver.o main.o
driver.o(.rodata+0x8): undefined reference to `foo(void *, void *,
unsigned int)'
driver.o(.rodata+0xc): undefined reference to `foo(void *, void *,
unsigned int)'
driver.o(.rodata+0x10): undefined reference to `foo(void *, void *,
unsigned int)'
collect2: ld returned 1 exit status
% g++ -O2 -c driver.cxx
% g++ -o a.out driver.o main.o
% ./a.out
Foo.
%
Doug
-- doug@visix.com
More information about the Gcc-bugs
mailing list