This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Optimization bug?

On 09/19/2015 03:32 PM, SÃren Brinkmann wrote:
Hi Andrew,

On Sat, 2015-09-19 at 11:34AM -0700, wrote:

On Sep 19, 2015, at 11:00 AM, SÃren Brinkmann <> wrote:


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]