[LLVMdev] __used__ attributes in llvm-gcc's crtstuff.c

Woongsik Choi
Tue, 14 Dec 2010 11:26:43 -0000

Hello,

I'm wondering why only some global static variables are marked with
__used__ attributes in llvm-gcc/gcc/crtstuff.c.

GCC compiles crtstuff.c with -fno-toplevel-reorder option, which ensures
that
unused static globals are not removed during optimization. However, since
LLVM does not support that option, I presume __used__ attribute is used
instead.

For example, __CTOR_LIST__[1] definition is changed as follows:

STATIC func_ptr __CTOR_LIST__[1]
/* LLVM LOCAL begin */
#ifdef __llvm__
  __attribute__ ((__used__, aligned(sizeof(func_ptr))))
#else
  __attribute__ ((__unused__, aligned(sizeof(func_ptr))))
#endif
/* LLVM LOCAL end */
  = { (func_ptr) (-1) };

Note that __unused__ just suppresses the warning that __CTOR_LIST__ is not
used.

My question is that why some global static variables, such as
__frame_dummy_init_array_entry
and __do_global_dtors_aux_fini_array_entry, are not given __used__
attributes.
It seems that llvm-gcc removes these variables and causes .init_array and
.fini_array section
to be empty. Linker complains about this as in "ld: warning: .init_array
section has zero size".
Also, I verified that frame_dummy and __do_global_dtors_aux functions are
not executed.

I have configured llvm-gcc for armv6 target and given
--enable-initfini-array option.

I tried to give __used__ attribute to every global static variable in
crtstuff.c and
it caused no problem for me so far.

Would it be any problem in doing so?

Best regards,
Woongsik Choi
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20101214/799d4643/attachment.html>