-
Notifications
You must be signed in to change notification settings - Fork 3k
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 for unit test build on Windows machines #8526
Fix for unit test build on Windows machines #8526
Conversation
I assume we might have a problem with other functions as well. So applying this only to EthernetInterface method is short term fix.
Is it? Isn't this related how gcc defines attribute weak ? I believe it works for elf or .out . What do we generate with Mingw ? Can you provide reference? |
Sorry, you are right, it is the Windows executable that does not support weak, here's the reference:
I agree that the weak attribute is heavily used in mbedOS source code, but we usually compile to target binaries, which are not Windows executables. The only situation I came across when we compile into a Windows executable is when we we try to run unit tests on Windows. I fixed the only compilation error that was being thrown in this situation. I can think of a more general change inside platform/mbed_toolchain.h:
On one hand it makes sense, but on the other, maybe it is wise to stick to the less-intrusive fix? |
This might seem now, but once we have more unittest coverage - more weak problems - we would end up having this exception in more files. I would rather have it in one place with a proper commit. ``
Looks fine to me. I could not find anything that could support weak linkage in MinGW thus unit test should have this as limitation - all symbols are strongly linked (at least for windows). @ARMmbed/mbed-os-core Please review |
I would prefer a generic solution in
|
I too would like to see a more generic fix, but I'm wondering something. @michalpasztamobica @SeppoTakalo Is this PR needed to unblock some new things in CI, or something similar? I agree that this seems like there will be more issues down the road once more unittest are added, but I'm wondering if we aren't doing some premature optimization in suggesting to solve the problem in a generic manner. Thinking out loud. Would bringing this PR in, along with opening a new issue to find a more generic solution be a good path forward for all opinion-holders? |
If issue is blocking CI, then yes I am fine with merging the PR for now with new issue |
In case MINGW is detected - define MBED_WEAK to be empty, as Windows executables cannot handle the weak attribute.
582345b
to
0b3593f
Compare
I tested that the change in platform/mbed_toolchain.h works just as good as my previous, more scattered yet less intrusive fix. I also checked that the target compilation is unaffected (including no crashes at runtime) and that unittests compile and run fine on Linux. This issue was not blocking the whole CI. It was blocking unittests on Windows. I guess most developers use Unix, but even those who use Windows should run a unittest suite before committing anything, so we'd better have it ready for them to use. |
@SeppoTakalo , please review. |
Someone from @ARMmbed/mbed-os-core please review |
/morph build |
@michalpasztamobica One thing - is there anywhere we should document this? I assume with unittest you would not rely on weakly linkage, just making sure this can be captured in the docs somewhere or is that clear to everyone? |
Nothing comes to my mind really... @SeppoTakalo - is there any relevant documentation where we should take a note of this change? |
Build : SUCCESSBuild number : 3465 Triggering tests/morph test |
Test : SUCCESSBuild number : 3256 |
Exporter Build : SUCCESSBuild number : 3088 |
This probably becomes evident for whoever is going to write the Unittest. Unittest writing requires so much more knowledge than what has been written in the documentation, so adding this causes more questions than what it answers. So I'm OK for leaving it unmentioned. |
Description
When building unit tests on windows a linker error is reported when linking
EthernetInterface
test, claiming thatEthernetInterface::get_target_default_instance()
is undefined. This is caused by MinGW not supporting weak attribute.The changes address this issue using preprocessor macro to determine that minGW is being used. MinGW will only be used in case unit tests are built on windows, as every other compilation will run a target compiler (either ARM or target GCC) or a Unix GCC (both on Linux and Mac).
I checked that target code builds fine on Windows and that unit tests are compiling and running on Linux.
Pull request type