Hi Martin (and all),
I wrote:
You dereference dev in line 132, so if it's really 0, will you then ever reach this check?? (I don't know if in romstage *NULL is caught.)
You wrote:
yes, if it's 0, we still reach the code. I've changed it to not dereference it before checking it though.
Per default, after any *ptr, GCC assumes a SEGFAULT would occur if ptr was ==0, so if control flow does reach the following code ptr must be !=0. ==> After any *ptr GCC will optimize away all ptr==0 or !=0 checks. I know that because I recently hunted a related bug for a week (U-Boot, ARM, different project) until I looked at the actual assembly code.
Are you sure romstage (or maybe even ramstage?) will *NULL without segfaulting and just continue? And is romstage compiled with GCC (+ CAR) or is romcc used?
In that case "-fno-delete-null-pointer-checks" must be added to the GCC options. http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
I greped a bit, looks like it's not in any Makefiles yet.
Could someone who knows Coreboot's make/build system better than me maybe help, please?
Thanks Jens
* Jens Rottmann JRottmann@LiPPERTembedded.de [130306 17:29]:
Hi Martin (and all),
I wrote:
You dereference dev in line 132, so if it's really 0, will you then ever reach this check?? (I don't know if in romstage *NULL is caught.)
You wrote:
yes, if it's 0, we still reach the code. I've changed it to not dereference it before checking it though.
Per default, after any *ptr, GCC assumes a SEGFAULT would occur if ptr was ==0, so if control flow does reach the following code ptr must be !=0. ==> After any *ptr GCC will optimize away all ptr==0 or !=0 checks. I know that because I recently hunted a related bug for a week (U-Boot, ARM, different project) until I looked at the actual assembly code.
Are you sure romstage (or maybe even ramstage?) will *NULL without segfaulting and just continue? And is romstage compiled with GCC (+ CAR) or is romcc used?
In that case "-fno-delete-null-pointer-checks" must be added to the GCC options. http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
I greped a bit, looks like it's not in any Makefiles yet.
Could someone who knows Coreboot's make/build system better than me maybe help, please?
Does this option exist on all newer GCCs? e.g everything 4.2 and up? In that case we can just stuff it into the Makefile. Otherwise we should add a check in xcompile.
Thanks Jens
-- coreboot mailing list: coreboot@coreboot.org http://www.coreboot.org/mailman/listinfo/coreboot
On 03/06/2013 09:29 AM, Jens Rottmann wrote:
Hi Martin (and all),
I wrote:
You dereference dev in line 132, so if it's really 0, will you then ever reach this check?? (I don't know if in romstage *NULL is caught.)
You wrote:
yes, if it's 0, we still reach the code. I've changed it to not dereference it before checking it though.
Per default, after any *ptr, GCC assumes a SEGFAULT would occur if ptr was ==0, so if control flow does reach the following code ptr must be !=0. ==> After any *ptr GCC will optimize away all ptr==0 or !=0 checks. I know that because I recently hunted a related bug for a week (U-Boot, ARM, different project) until I looked at the actual assembly code.
Are you sure romstage (or maybe even ramstage?) will *NULL without segfaulting and just continue? And is romstage compiled with GCC (+ CAR) or is romcc used?
In that case "-fno-delete-null-pointer-checks" must be added to the GCC options. http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
I greped a bit, looks like it's not in any Makefiles yet.
Could someone who knows Coreboot's make/build system better than me maybe help, please?
Thanks Jens
Jens, I'm pretty sure, but I'm not *COMPLETELY* positive about this. I had to add this check because I kept getting null pointers due to an issue with the unterminated #pragma pack(1) in the porting.h file - that was messing my pointers up pretty badly. I'll work on checking this issue directly and respond back with what I find out. Martin
On Wed, Mar 6, 2013 at 8:29 AM, Jens Rottmann JRottmann@lippertembedded.de wrote:
Per default, after any *ptr, GCC assumes a SEGFAULT would occur if ptr was ==0, so if control flow does reach the following code ptr must be !=0. ==> After any *ptr GCC will optimize away all ptr==0 or !=0 checks. I know that because I recently hunted a related bug for a week (U-Boot, ARM, different project) until I looked at the actual assembly code.
And here I thought that no-delete-null-pointer-checks had been taken out after all the problems it caused. Silly me. I wonder how many of the gcc compiler writers understand C's original purpose :-) I was quite shocked when I read of this "optimization" some years ago.
Yeah, we need to ensure -fno-delete-null-pointer-checks is set on any compiler foolish enough to implement this sort of thing.
ron