Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Check undefined init_priority static object dependency #20065

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR20066
Status NEW
Importance P enhancement
Reported by Albert Zeyer (ich@az2000.de)
Reported on 2014-06-17 09:15:45 -0700
Last modified on 2018-10-10 07:43:08 -0700
Version unspecified
Hardware PC All
CC ganna@apple.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Example:

header.h:

extern int a;
extern int b;

a.cpp:

#include "header.h"
int a = 2;

b.cpp:

#include "header.h"
int b = a;

main.cpp:

#include <stdio.h>
#include "header.h"

__attribute__((constructor))
static void init() {
    printf("init: %i %i\n", a, b);
}

int main() {}

---

a and b will both get the same init_priority (I think it's
DEFAULT_INIT_PRIORITY = 65535), and thus it's not well defined whether a or b
is initialized first.

I would like to have a check, if the initialization of a global/static variable
depends on another global/static variable (int b = a), its init_priority must
be a  bigger value than of all its dependencies.

---

In case that you wont implement this feature in the (near) future, maybe you
can give some guidance about what I need to do to implement such a static check
myself.
Quuxplusone commented 10 years ago
Currently, the clang static analyzer does not have cross implementation file
analysis, so there is not enough infrastructure to implement this effectively.

Check out the initialization order checking with Address Sanitizer and see if
that is something you might be able to use instead:
http://clang.llvm.org/docs/AddressSanitizer.html

For more info, use cfe-dev mailing list.