Skip to content
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 undefined reference to mag when USE_MAG isn't defined #9290

Merged

Conversation

etracer65
Copy link
Member

@etracer65 etracer65 commented Dec 15, 2019

The mag variable is defined as an extern in compass.h but the implementation in compass.c is bounded by #ifdef USE_MAG. So if USE_MAG is not defined then the mag variable is an undefined reference.

In imu.c the imuMahonyAHRSupdate() function was being passed the elements of mag unconditionally like mag.magADC[X] so in the case that USE_MAG wasn't defined these were invalid null references. Luckily the logic in imuMahonyAHRSupdate() was properly bounded so that it never tried to access these variables. But in the case of a debug build the linker is unable to build a reference to these variables since they're never defined and the compile fails.

Credit to @kmitchel for finding.

The `mag` variable is defined as an `extern` in compass.h but the implementation in compass.c is bounded by `#ifdef USE_MAG`. So if `USE_MAG` is not debined then the `mag` variable is an undefined reference.

In imu.c the `imuMahonyAHRSupdate()` function was being passed the elements of `mag` unconditionally like `mag.magADC[X]` so in the case that `USE_MAG` wasn't defined these were invalid null references. Luckily the logic in `imuMahonyAHRSupdate()` was properly bounded so that it never tried to access these variables. But in the case of a debug build the linker is unable to build a reference to these variables since they're never defined.
@etracer65 etracer65 added this to the 4.2 milestone Dec 15, 2019
@etracer65
Copy link
Member Author

I flagged as 4.2 since while it's technically a bug, it only affects people doing DEBUG builds and probably not needed to cherry-pick into 4.1 maintenance. But there's also no reason why it can't apply to 4.1 maintenance. Probably low risk either way.

@mikeller mikeller modified the milestones: 4.2, 4.1.2 Dec 22, 2019
@mikeller mikeller merged commit 880ee85 into betaflight:master Dec 22, 2019
mikeller added a commit that referenced this pull request Dec 22, 2019
Fix undefined reference to mag when USE_MAG isn't defined
@etracer65 etracer65 deleted the debug_build_mag_undefined_reference branch June 2, 2020 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants