[llvm-dev] linkonce expected behavior?

Andrew Kelley via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 24 18:09:02 PDT 2017


http://llvm.org/docs/LangRef.html#linkage-types says:

Globals with “linkonce” linkage are merged with other globals of the same
name when linkage occurs. This can be used to implement some forms of
inline functions, templates, or other code which must be generated in each
translation unit that uses it, but where the body may be overridden with a
more definitive definition later. Unreferenced linkonce globals are allowed
to be discarded. Note that linkonce linkage does not actually allow the
optimizer to inline the body of this function into callers because it
doesn’t know if this definition of the function is the definitive
definition within the program or whether it will be overridden by a
stronger definition. To enable inlining and other optimizations, use
“linkonce_odr” linkage.

This makes me think that linkonce globals will not be optimized out of an
.o file, but they can be deleted by the linker. Here's some IR I have:

define linkonce i128 @__udivmodti4(i128, i128, i128*) local_unnamed_addr #0
!dbg !264 {
....
}

When I run:

opt -O3 -S compiler_rt.ll

It deletes the function. Is this expected behavior?

Is there a linkage type that lets the linker merge functions of the same
name but does not let the optimizer delete the function?

(let me know if providing the entire .ll file would be helpful)

Regards,
Andrew Kelley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171024/ee652e8c/attachment.html>


More information about the llvm-dev mailing list