On 09/19/2015 03:32 PM, Sören Brinkmann wrote:
Hi Andrew,
On Sat, 2015-09-19 at 11:34AM -0700, pins...@gmail.com wrote:
On Sep 19, 2015, at 11:00 AM, Sören Brinkmann <soren.brinkm...@xilinx.com>
wrote:
Hi,
I recently came across some bug in my program that I could narrow down
to the snipped below (also attached with a Makefile).
extern unsigned int _vector_table;
You need the attribute weak here if the location of _vector_table can be a null
pointer.
Indeed, that fixes the problem. Would you have any additional background
why the 'weak' is required in this case? To me it sounded like the
'-fno-delete-null-pointer-checks' should be sufficient.
-fno-delete-null-pointer-checks prevents GCC from removing tests
for null pointers after such pointers have been dereferenced. For
example, in the following function, GCC normally eliminates the
second if statement because the first statement lets it assume
that p is not null (otherwise dereferencing it would be undefined).
int foo (int *p) {
if (*p == 0) return 0;
if (p == 0) return 1;
return 2;
}
The option doesn't affect other assumptions such as that every
object and function in a program lives at a valid, non-null
address.
Martin