Displaying 2 results from an estimated 2 matches for "so_init_fn".
Did you mean:
__init_fn
2020 Jun 12
2
Issue with __attribute__((constructor)) and -Os -fno-common
...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" to some non-zero
value? I mean this for instance:
extern int val;
static void __attribute__((constructor)) so_init_fn(void)
{
val = 1;
}
I would expect the main program to return 2, not 1.
Last thing, if I define "val" as volatile, the programs behaves as expected.
Are we in "unspecified, just don't do this" territory here?
Thanks,
--
Jerome
>
> On Thu, Jun 11, 2020 at 10:12 A...
2020 Jun 11
2
Issue with __attribute__((constructor)) and -Os -fno-common
Hi,
I think that Clang erroneously 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[])