[llvm-commits] [PATCH] llvm-gcc-4.2/gcc/crtstuff.c : __used__ attributes for all global static variables

Woongsik Choi woongsik.choi at gmail.com
Tue Dec 14 19:03:00 PST 2010


Relating to the article in llvm-dev list,
http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-December/036982.html

attached patch assigns __used__ attributes to all global static
variables llvm-gcc/gcc/crtstuff.c so that they are not removed
as results of optimization.

The affected variables are follows:
- static func_ptr force_to_data[1]
- STATIC void *__JCR_LIST__[]
- static func_ptr __do_global_dtors_aux_fini_array_entry[]
- static func_ptr __frame_dummy_init_array_entry[]
- STATIC EH_FRAME_SECTION_CONST int32 __FRAME_END__[]
- STATIC void *__JCR_END__[1]

STATIC is defined to be 'static' if elf format is used and otherwise
defined empty. I'm not sure whether it will cause some unexpected
behavior on other formats. I think following comment in the code
might concern about this:

STATIC func_ptr __DTOR_END__[1]
/* LLVM LOCAL begin */
#ifdef __llvm__
/* FIXME: Remove when external weak linkage will be alive. */
  __attribute__((__used__, section(".dtors"), aligned(sizeof(func_ptr))))
#else
  __attribute__((unused, section(".dtors"), aligned(sizeof(func_ptr))))
#endif
/* LLVM LOCAL end */
  = { (func_ptr) 0 };
#endif

At least, the patch worked fine on armv6 target under linux.
It solved the problem that frame_dummy and
__do_global_dtors_aux were not called if .init_array and
.fini_array sections are used.

Please verify this patch and apply if it's acceptable.

Best regards,
Woongsik Choi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20101215/6c4efe30/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: crtstuff_used_attr.patch
Type: application/octet-stream
Size: 3481 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20101215/6c4efe30/attachment.obj>


More information about the llvm-commits mailing list