symbol duplication problem with -O0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi.

I have a question about optimization option.
When i write/build a test code, system call symbol is different
according to optimization option.

test code

int main(void) {
    struct stat buf;
    if ( stat("test.txt", &buf) < 0 ) {
      printf("error\n");
    } else {
      printf("stat success\n");
    }
    return 0;
}

1. with -O0

$ gcc -O0 -c main.c
$ nm main.o
0000000000000000 T main
                 U puts
                 U stat
$


2. with -O2
$ gcc -O2 -c main.c
$ nm main.o
                 U __xstat
0000000000000000 T main
                 U puts

I don't know why symbol results are different.
Which gcc option in -O1/-O2 make __xstat symbol?
I think using -O0 can make a problem.

ex)
main.c : stat() system call usage
test.c : stat variable declaration(of course, it's not a good declaration).
gcc -O0 main.c test.c

In this case, stat in main.c will refer stat symbol in test.c.
It's a problem.
Which option prevents this problem when -O0 is used?

thank you.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux