[llvm-dev] llvm-link: why link '@llvm.global_ctors' into dest file even it's not used in dest file?

Ronan KERYELL via llvm-dev llvm-dev at lists.llvm.org
Thu Jan 3 20:38:10 PST 2019


>>>>> 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


More information about the llvm-dev mailing list