[Bug c++/104712] -fkeep-inline-functions causing link errors (debian but not godbolt?)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104712 ajrh at ajrh dot net changed: What|Removed |Added CC||ajrh at ajrh dot net --- Comment #6 from ajrh at ajrh dot net --- Created attachment 52525 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52525=edit mention -ffunction-sections -Wl,-gc-sections in gcov manual On deeper investigation the original code had lots of unused inlined explicit template specializations, and a few of these had constants missing the 'inline' keyword. So gcc is behaving perfectly.Apologies for the misleading testcase. I understand better now:--keep-inline-functions is correctly generating lots of otherwise dead code, and of course some of it might not link. Though I only wanted to link it in order to run gcov to find and remove all the dead code, an amusing catch-22. Am I correct that a good way to fix this sometimes will be to use -ffunction-sections -Wl,-gc-sections ?E.g. in the example below: extern int i; inline int f(const char *x) { return i; } int main(int argc, char *argv[]) { return !!argc; } gcc -o x --coverage x.cpp && {x; gcov x} File 'x.cpp' Lines executed:100.00% of 2 gcc -o x --coverage -fkeep-inline-functions x.cpp && {x; gcov x} x.cpp:(.text._Z1fPKc[_Z1fPKc]+0x1c): undefined reference to `i' g++ -o x --coverage -fkeep-inline-functions -ffunction-sections -Wl,-gc-sections x.cpp && {x; gcov x} File 'x.cpp' Lines executed:50.00% of 4 If that's right it might be useful to mention as a hint in the manual. Attached a texi patch if so. Thank you all for the help.
[Bug c++/104712] -fkeep-inline-functions causing link errors (debian but not godbolt?)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104712 Jakub Jelinek changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #5 from Jakub Jelinek --- Yeah, but I can't reproduce a problem with it in the short testcase. Note, if you want to see on godbolt what you see on Debian, use -fpie -pie options.
[Bug c++/104712] -fkeep-inline-functions causing link errors (debian but not godbolt?)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104712 --- Comment #4 from Jonathan Wakely --- The in-class declaration is the definition if it's inline and has an initializer.
[Bug c++/104712] -fkeep-inline-functions causing link errors (debian but not godbolt?)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104712 --- Comment #3 from Andrew Pinski --- (In reply to ajrh from comment #2) > Oh drat, reduced test cases are maddening... it's an inline static const > in my original. I'll try to reduce something again. I think even with inline static const, you still have to have a definition depending on how it is used.
[Bug c++/104712] -fkeep-inline-functions causing link errors (debian but not godbolt?)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104712 --- Comment #2 from ajrh at ajrh dot net --- Oh drat, reduced test cases are maddening... it's an inline static const in my original. I'll try to reduce something again.
[Bug c++/104712] -fkeep-inline-functions causing link errors (debian but not godbolt?)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104712 Andrew Pinski changed: What|Removed |Added Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED --- Comment #1 from Andrew Pinski --- You only have a declaration and not a definition. You need to add: int C::XYZZY; And that will fix the issue you are seeing.