from quick look at the kernel, I'd say the kernel is buggy
I'd say used attribute is a must in the #define __videocard struct card_info __attribute__((section(".videocards")))
because when it declares static __videocard var = { ... }; then the compiler has all rights to just nuke those as unused
though I can't reproduce it with:
struct S { int i, j; };
static struct S __attribute__((section ("foobar"))) s = { 1, 2 };
void foo (void)
{
s.i = 2;
s.j = 3;
}
actually, the kernel code is even more insane
struct S { int i, j; void (*p) (void); };
static struct S __attribute__((section ("foobar"))) s;
static void foo (void)
{
s.i = 2;
s.j = 3;
}
static struct S __attribute__((section ("foobar"))) s = { 1, 2, foo };
if this ever worked, it was purely by accident
note that the struct var is static, not marked as used, only used (visibly to the compiler) in a static function that is only referenced from the static struct variable's initializer
but please tell me which gcc would not optimize that away, even 4.1 at -O2 does
seems this got broken 4 years ago though
commit a1a00b58855ccdbedf556b4f5638d5208b454472
Author: Hannes Eder <email address hidden>
Date: Sun Nov 23 19:37:09 2008 +0100
a preprocessed testcase still would be nice to see if for some reason it happens not to be optimized out by month old 4.7 and is right now
but the reduced testcase from what I saw in the kernel code really optimizes to nothing even in 4.1
even 3.4 does, 3.3/3.2 doesn't at -O2
Jakub Jelinek commented on freenode/#gcc:
from quick look at the kernel, I'd say the kernel is buggy _((section( ".videocards" )))
I'd say used attribute is a must in the #define __videocard struct card_info __attribute_
because when it declares static __videocard var = { ... }; then the compiler has all rights to just nuke those as unused
though I can't reproduce it with:
struct S { int i, j; }; _((section ("foobar"))) s = { 1, 2 };
static struct S __attribute_
void foo (void)
{
s.i = 2;
s.j = 3;
}
actually, the kernel code is even more insane
struct S { int i, j; void (*p) (void); }; _((section ("foobar"))) s; _((section ("foobar"))) s = { 1, 2, foo };
static struct S __attribute_
static void foo (void)
{
s.i = 2;
s.j = 3;
}
static struct S __attribute_
if this ever worked, it was purely by accident
note that the struct var is static, not marked as used, only used (visibly to the compiler) in a static function that is only referenced from the static struct variable's initializer
but please tell me which gcc would not optimize that away, even 4.1 at -O2 does
seems this got broken 4 years ago though edf556b4f5638d5 208b454472
commit a1a00b58855ccdb
Author: Hannes Eder <email address hidden>
Date: Sun Nov 23 19:37:09 2008 +0100
a preprocessed testcase still would be nice to see if for some reason it happens not to be optimized out by month old 4.7 and is right now
but the reduced testcase from what I saw in the kernel code really optimizes to nothing even in 4.1
even 3.4 does, 3.3/3.2 doesn't at -O2