-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix multiple definition errors #262
Conversation
be106ae
to
b35f69b
Compare
Have you encountered the cause for the multiple definitions here (been a while since I've looked at the C-ext)? Why is this the best fix? |
Thank you for your pull request, but I don't think I agree with this solution. My speculation is that some behavior has changed in GCC 10. Are you able to repro this with GCC 8 or 9? Clang? The source code should only result in a single definition for these values (I didn't spot check them all), but enough to be pretty confident about this). If some compiler behavior results in these symbols being defined multiple times, I don't think that simply ignoring this / allowing it is a good workaround. If there is some other error in our make files that allow this, we should fix that. Allowing multiple definitions seems like it could lead to unpredictable / undefined behaviro. |
@dalehamel Thanks for information. I do speculate that is behaviour change of GCC 10. Let me go back to you after I verify this hypothesis. |
@dalehamel I can confirm that GCC9 does not have this same issue. I think the issue is related GCC10 Ref: https://gcc.gnu.org/gcc-10/porting_to.html
## Default to -fno-common
A common mistake in C is omitting extern when declaring a global variable in a header file. If the header is included by several files it results in multiple definitions of the same variable. In previous GCC versions this error is ignored. GCC 10 defaults to -fno-common, which means a linker error will now be reported. To fix this, use extern in header files when declaring global variables, and ensure each global is defined in exactly one C file. If tentative definitions of particular variables need to be placed in a common block, __attribute__((__common__)) can be used to force that behavior even in code compiled without -fcommon. As a workaround, legacy C code where all tentative definitions should be placed into a common block can be compiled with -fcommon.
int x; // tentative definition - avoid in header files
extern int y; // correct declaration in a header file |
This reverts commit b35f69b.
This is news to me, it is such a common practice that it's a little funny to call it a mistake... I guess because they are for variables an not function declarations, I can see why. In your PR i see you're going with the attribute approach, I am curious how this will work with Clang. As an aside, we should probably try building semian with clang just to enforce good portability practices. Why did you choose this approach over just |
Good one. Let me come back to you on that.
I am not feeling 100% confident with semian codebase at this stage. Therefore I am leaning toward solution that is the least disruptive. |
@damianthe I confirm my PR also work on clang9 and clang10. |
f972b0a
to
0c85fa4
Compare
@damianthe I've amended the PR with |
I am going to close this PR instead. Once GCC10 has become default on all mainstream Linux distros, I think we could look into this issue again. |
Re-open this PR because GCC 10.1 is officially released. |
I believe the core team would address the issue so I am closing this PR. Thanks all for helping with PR review. |
What
This PR addresses failed compilation with GCC 10
which was reported in #261:
GCC 10 now default
-fno-common
. Many linker errors are now reported.