-
Notifications
You must be signed in to change notification settings - Fork 3k
GCC: remove -fno-delete-null-pointer-checks #12023
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
Conversation
For GCC we're being cautious by passing the `-fno-delete-null-pointer-checks`. This option prevents some optimisation opportunities, so removing it can reduce code size. One particular optimisation loss occurs in `Callback` where a test similar to this occurs: extern void myfunc(); inline void foo(void (*fnptr)()) { if (fnptr) { do A; } else { do B; } }; foo(myfunc); With `-fno-delete-null-pointer-checks`, the compiler does not assume that `&myfunc` is non-null, and inserts the "null check" - seeing if the address is 0. But performing that test of the address is incorrect anyway - if myfunc actually could be at address 0, we'd still want to do A. Anyway, we do not have an equivalent option enabled for either Clang or IAR, and we have performed clean-ups avoiding issues with apparently-null vector tables in Clang already, for example ARMmbed#10534. Therefore it should(TM) be safe to remove the option for GCC. We do not have general data or code at address 0, only vectors are likely to be there, so it does not make sense to be globally restricting code generation for that.
Something to consider - I'll need to check what the saving looks like. It will be fairly small; we'll have to balance chance of compiler doing something unexpected versus that saving. |
@kjbracey-arm, thank you for your changes. |
Should we leave it there in debug? |
Hard to say. I can see downsides with either choice. My inclination is to just let GCC default to whatever judgement it makes for I've checked, and saving on a full client build is:
That's with current |
@bulislaw @kjbracey-arm what is the status of this now ? |
I think it needs discussion/review. Might be worth doing 1 CI run to see if any issues are seen - I'd hope it's green straight off. |
CI started |
Test run: FAILEDSummary: 1 of 11 test jobs failed Failed test jobs:
|
Could you retrigger CI? I think that was a spurious failure. Review/discussion still required. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved after talking to @kjbracey-arm.
CI started |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
This PR does not contain release version label after merging. |
Summary of changes
For GCC we're being cautious by passing the
-fno-delete-null-pointer-checks
. This option prevents some optimisation opportunities, so removing it can reduce code size.One particular optimisation loss occurs in
Callback
where a test similar to this occurs:With
-fno-delete-null-pointer-checks
, the compiler does not assume that&myfunc
is non-null, and inserts the "null check" - seeing if the address is 0. But performing that test of the address is incorrect anyway - if myfunc actually could be at address 0, we'd still want to doA.Anyway, we do not have an equivalent option enabled for either Clang or IAR, and we have performed clean-ups avoiding issues with apparently-null vector tables in Clang already, for example #10534.
Therefore it should(TM) be safe to remove the option for GCC. We do not have general data or code at address 0, only vectors are likely to be there, so it does not make sense to be globally restricting code generation for that.
Impact of changes
Will reduce image size. Particularly when
Callback
is in use. Increased optimisation may require code adjustments, exposing undefined behaviourMigration actions required
If code fails, address undefined behaviour. Eg this null check may now be removed:
Correct to:
Documentation
None
Pull request type
Test results
Reviewers