<br><div>Hello,</div><div><br></div><div>I'm wondering why only some global static variables are marked with </div><div>__used__ attributes in llvm-gcc/gcc/crtstuff.c. </div><div><br></div><div>GCC compiles crtstuff.c with -fno-toplevel-reorder option, which ensures that </div>
<div>unused static globals are not removed during optimization. However, since </div><div>LLVM does not support that option, I presume __used__ attribute is used instead.</div><div><br></div><div>For example, __CTOR_LIST__[1] definition is changed as follows:</div>

<div><br></div><div><div>STATIC func_ptr __CTOR_LIST__[1]</div><div>/* LLVM LOCAL begin */</div><div>#ifdef __llvm__</div><div>  __attribute__ ((__used__, aligned(sizeof(func_ptr))))</div><div>#else  </div><div>  __attribute__ ((__unused__, aligned(sizeof(func_ptr))))</div>

<div>#endif  </div><div>/* LLVM LOCAL end */</div><div>  = { (func_ptr) (-1) };</div></div><div><br></div><div>Note that __unused__ just suppresses the warning that __CTOR_LIST__ is not used.</div><div><br></div><div>My question is that why some global static variables, such as __frame_dummy_init_array_entry</div>
<div>and __do_global_dtors_aux_fini_array_entry, are not given __used__ attributes. </div><div>It seems that llvm-gcc removes these variables and causes .init_array and .fini_array section </div><div>to be empty. Linker complains about this as in "ld: warning: .init_array section has zero size".</div>

<div>Also, I verified that frame_dummy and __do_global_dtors_aux functions are not executed.</div><div><br></div><div>I have configured llvm-gcc for armv6 target and given --enable-initfini-array option.</div><div><br></div>

<div>I tried to give __used__ attribute to every global static variable in crtstuff.c and </div><div>it caused no problem for me so far.</div><div><br></div><div>Would it be any problem in doing so?</div><div><br></div><div>

Best regards,</div><div>Woongsik Choi</div><div><br></div>