Woongsik Choi
2010-Dec-14 11:26 UTC
[LLVMdev] __used__ attributes in llvm-gcc's crtstuff.c
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>
Anton Korobeynikov
2010-Dec-14 20:47 UTC
[LLVMdev] __used__ attributes in llvm-gcc's crtstuff.c
Hello,> __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,The problem is not that LLVM does not support this option. Though, this is indeed so due to certain reason. All the code is transformed into IR and transformations are performed on it. It will be really bad for the transformations to depend on some magic command line options. Even more, consider e.g. you tried to link two IR files - one with the code with -fno-toplevev-reorder and one - without. What should be done in such case?> I presume __used__ attribute is used instead.This is correct, because this is what in fact the code should do here.> 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.Just bug.> it caused no problem for me so far. > Would it be any problem in doing so?Please prepare the patch and submit to llvm-commit. Thanks! -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
Woongsik Choi
2010-Dec-15 06:06 UTC
[LLVMdev] __used__ attributes in llvm-gcc's crtstuff.c
I have submitted the patch in the following llvm-commits article http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20101213/113762.html Best regards, Woongsik Choi 2010/12/15 Anton Korobeynikov <anton at korobeynikov.info>> Hello, > > > __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, > The problem is not that LLVM does not support this option. Though, > this is indeed so due to certain reason. > All the code is transformed into IR and transformations are performed > on it. It will be really bad for the > transformations to depend on some magic command line options. Even > more, consider e.g. you tried > to link two IR files - one with the code with -fno-toplevev-reorder > and one - without. What should be done > in such case? > > > I presume __used__ attribute is used instead. > This is correct, because this is what in fact the code should do here. > > > 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. > Just bug. > > > it caused no problem for me so far. > > Would it be any problem in doing so? > Please prepare the patch and submit to llvm-commit. Thanks! > > -- > With best regards, Anton Korobeynikov > Faculty of Mathematics and Mechanics, Saint Petersburg State University >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101215/96f6fd3f/attachment.html>
Dimitry Andric
2010-Dec-15 10:19 UTC
[LLVMdev] __used__ attributes in llvm-gcc's crtstuff.c
On 2010-12-14 12:26, Woongsik Choi wrote:> 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....> I tried to give __used__ attribute to every global static variable in > crtstuff.c and > it caused no problem for me so far.Note that upstream gcc has already marked more globals in crtstuff.c as __used__: http://gcc.gnu.org/viewcvs?view=revision&revision=159228 http://gcc.gnu.org/viewcvs?view=revision&revision=159279
Apparently Analagous Threads
- [LLVMdev] __used__ attributes in llvm-gcc's crtstuff.c
- [LLVMdev] Compiling llvm-gcc on amd64 with 32 bits: assembler still carps
- [LLVMdev] datapoint for recent llvm-gcc4 build failures
- [LLVMdev] datapoint for recent llvm-gcc4 build failures
- [LLVMdev] build broken (a different way)