Last active
February 9, 2020 17:56
-
-
Save kevinushey/cfa848be2d39ddd110f893d9b6c5ac9c to your computer and use it in GitHub Desktop.
Fails to compile with gcc 10 on Fedora Rawhide.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void* callback(const char* name); | |
extern "C" { | |
inline void f1() | |
{ | |
static void (*f)(); | |
f = (void(*)()) callback("f1"); | |
f(); | |
} | |
inline void f2() | |
{ | |
static void (*f)(); | |
f = (void(*)()) callback("f2"); | |
f(); | |
} | |
} // extern "C" | |
int main() | |
{ | |
f1(); | |
f2(); | |
} |
Author
kevinushey
commented
Feb 9, 2020
Line 11 calls callback
, which returns 0
. Then line 12 attempts to call that pointer, which is a NULL dereference. The same for f2
. This is likely undefined behaviour, so you can't say much on the result being right or wrong.
This may be a bit too simplified from the original.
That causes a runtime crash, but that's not the point. The point here is that gcc 10 generates two symbols f
for lines 10 and 17, and they collide. Previous versions of gcc generate _ZZ2f1E1f
and _ZZ2f2E1f
respectively, i.e., f1::f
and f2::f
demangled.
I've removed the implementation of callback()
so at least this should no longer be UB. The underlying issue though is as @Enchufa2 says, with duplicate (and non-mangled) names for f
generated.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment