Skip to content

Do not assume 0x0 to be an unusable address#628

Merged
OlegHahm merged 1 commit intoRIOT-OS:masterfrom
Kijewski:fno-delete-null-pointer-checks
Feb 5, 2014
Merged

Do not assume 0x0 to be an unusable address#628
OlegHahm merged 1 commit intoRIOT-OS:masterfrom
Kijewski:fno-delete-null-pointer-checks

Conversation

@Kijewski
Copy link
Copy Markdown
Contributor

@Kijewski Kijewski commented Feb 5, 2014

I just ran into the problem that GCC assumes that a pointer cannot be NULL, if you have accessed it previously, e.g.

unsigned *x = ...;
printf("%p is %u\n", (void *) x, *x);
if (!x) break;
else ...

The problem is that 0x0 is a perfectly fine address to read from without an MMU / paging.
So it is completely unreasonable that the if (!x) is dropped without any sort of warning.

@OlegHahm
Copy link
Copy Markdown
Member

OlegHahm commented Feb 5, 2014

Wouldn't it make sense to add this flag in a CPU dependent Makefile then?

@Kijewski
Copy link
Copy Markdown
Contributor Author

Kijewski commented Feb 5, 2014

Counter question: is there any CPU where you cannot access 0x0?

@OlegHahm
Copy link
Copy Markdown
Member

OlegHahm commented Feb 5, 2014

I guess on most platforms without a MMU having a pointer to address 0x0 indicates a problem in 99% of all cases, but maybe I do not understand the change you propose.

@Kijewski
Copy link
Copy Markdown
Contributor Author

Kijewski commented Feb 5, 2014

Reading from 0x0 might be seldom reasonable, true.
But that the compiler drops the check at any optimization level but -O0 is not sane for kernel programming.
Just google "linux fno-delete-null-pointer-checks" to see how much fun other people had with that "optimization". :)

@OlegHahm
Copy link
Copy Markdown
Member

OlegHahm commented Feb 5, 2014

Ok, after reading the GCC manpage, I think I see your point. ACK from my side.

OlegHahm added a commit that referenced this pull request Feb 5, 2014
Do not assume 0x0 to be an unusable address
@OlegHahm OlegHahm merged commit 535c49a into RIOT-OS:master Feb 5, 2014
@Kijewski Kijewski deleted the fno-delete-null-pointer-checks branch February 5, 2014 19:26
@mehlis
Copy link
Copy Markdown
Contributor

mehlis commented Feb 8, 2014

clang does not know this parameter....throws a warning for every unit it has to compile.
can we find a solution for that?

@LudwigKnuepfer
Copy link
Copy Markdown
Member

Open an issue - nobody looks at merged/closed PRs/issues for problems to fix.

@Kijewski Kijewski restored the fno-delete-null-pointer-checks branch February 9, 2014 23:48
@Kijewski Kijewski deleted the fno-delete-null-pointer-checks branch February 9, 2014 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants