Sat 20 Dec 2008 07:56:14 AM UTC, original submission:
FT_USE_MODULE declares things as:
extern const FT_Module_Class
(or similar for C++). However, the actual types of the variables being declared are often different, e.g., FT_Driver_ClassRec or FT_Renderer_Class. (Some are, indeed, FT_Module_Class.)
This works with most C compilers (since those structs begin with an FT_Module_Class struct), but technically it's undefined behavior.
To quote the ISO/IEC 9899:TC2 final committee draft, section 6.2.7 paragraph 2:
All declarations that refer to the same object or function shall have compatible type; otherwise, the behavior is undefined.
(And these are not compatible types. I read the relevant sections of the standard -- pity me! -- and also consulted with a coworker who's more knowledgeable about the C and C++ standards than I am.)
Most C compilers don't reject (or even detect!) code which has this issue, but the GCC LTO development branch compiler does. (It outputs the types of the objects while generating .o files, along with a bunch of other information, then compares them when doing the final link-time code generation pass.)
The solution is to declare these variables as having the correct types. Easy, if a bit tedious.
I've attached a patch which does this, which was coded against CVS sources checked out this evening.
I've tested it only by compiling with that compiler + with 'stock' GCC (built with GNU make), so some of the changes in the patch are untested. But IMO they're obviously-correct.
|