search for: init_fn

Displaying 2 results from an estimated 2 matches for "init_fn".

2020 Jun 11
2
Issue with __attribute__((constructor)) and -Os -fno-common
...sly discards a function annotated with __attribute__((constructor)) when flags -Os -fno-common are given. Test case below. What do you think? Thanks. ----8<--------8<--------8<--------8<--------8<--------8<-------- $ cat ctor.c int val; static void __attribute__((constructor)) init_fn(void) { val = 1; } int main(int argc, char *argv[]) { return val; } ----8<--------8<--------8<--------8<--------8<--------8<-------- Here is what I observed: - Clang (10.0.0-4ubuntu1) with -Os -fno-common: function init_fn() is NOT emitted, - Clang (10.0.0-4ubun...
2020 Jun 12
2
Issue with __attribute__((constructor)) and -Os -fno-common
...by setting the initial value of "val" to > 1 instead of 0. So, the behavior of this program is preserved. Doesn't look > like erroneous behavior. OK, my example is too simplified indeed. Please consider the following instead: int val; static void __attribute__((constructor)) init_fn(void) { val++; } int main(int argc, char *argv[]) { return val; } With this, clang -Os -fno-common generates a global variable initialized to 1 and discards init_fn(). Now, what happens if the executable is later linked against a shared library which has its own constructor and sets "val&...