Fangqing Du via llvm-dev
2019-Jan-02 22:51 UTC
[llvm-dev] llvm-link: why link '@llvm.global_ctors' into dest file even it's not used in dest file?
Hi all, Recently I do some jobs based on llvm-link tool. I wonder why link '@llvm.global_ctors' into dest file, even it's not used in dest file? And how can I remove it? Thank you all in advance! Fangqing Xilinx Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190102/283cdd91/attachment.html>
Mehdi AMINI via llvm-dev
2019-Jan-03 23:15 UTC
[llvm-dev] llvm-link: why link '@llvm.global_ctors' into dest file even it's not used in dest file?
Hi, On Wed, Jan 2, 2019 at 2:52 PM Fangqing Du via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi all, > > Recently I do some jobs based on llvm-link tool. > I wonder why link '@llvm.global_ctors' into dest file, even it's not used > in dest file? >This is a "magic" global variable: https://llvm.org/docs/LangRef.html#the-llvm-global-ctors-global-variable It is implicitly used by the loader of the program before entering main(). Think about how a C++ global variable constructor can register itself and the "destination file" you're mentionning can query this registry.> And how can I remove it? >Like other global variables? You need to transform the module yourself before linking it (if you believe it is safe to do so). -- Mehdi -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190103/99f1a843/attachment.html>
Ronan KERYELL via llvm-dev
2019-Jan-04 04:38 UTC
[llvm-dev] llvm-link: why link '@llvm.global_ctors' into dest file even it's not used in dest file?
>>>>> On Thu, 3 Jan 2019 15:15:15 -0800, Mehdi AMINI via llvm-dev <llvm-dev at lists.llvm.org> said:Mehdi> Hi, Mehdi> On Wed, Jan 2, 2019 at 2:52 PM Fangqing Du via llvm-dev <llvm-dev at lists.llvm.org> wrote: > Hi all, > Recently I do some jobs based on llvm-link tool. I wonder > why link '@llvm.global_ctors' into dest file, even it's not > used in dest file? Mehdi> This is a "magic" global variable: Mehdi> https://llvm.org/docs/LangRef.html#the-llvm-global-ctors-global-variable Mehdi> It is implicitly used by the loader of the program before Mehdi> entering main(). Mehdi> Think about how a C++ global variable constructor can Mehdi> register itself and the "destination file" you're mentionning Mehdi> can query this registry. But it is true that the dead-code elimination phases could remove it when not used... > And how can I remove it? Mehdi> Like other global variables? You need to transform the module Mehdi> yourself before linking it (if you believe it is safe to do Mehdi> so). In our SYCL compiler I wrote a pass to remove it: https://github.com/triSYCL/llvm/blob/sycl/master/lib/SYCL/remove_global_empty_cdtors.cpp Look at https://github.com/triSYCL/triSYCL/blob/master/doc/architecture.rst for some context. -- Ronan KERYELL