[PATCH] D18095: Add __attribute__((linkonce_odr_linkage))

John McCall via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 22 14:19:38 PDT 2016


rjmccall added a comment.

Yes, you should just stick with your post-processing pass or something like it.

The design of linkonce_odr linkage is that such definitions will only be emitted when they are actually used.  Even with this attribute, a translation unit that consists solely of:

  __attribute__((linkonce_odr_linkage)) void foo() {}

would naturally be emitted as an empty object file.  It is possible that Clang as patched will not do this, because you haven't updated the places that implement lazy code emission to be aware of the new attribute.  However, that strikes me as a bug, not a guaranteed aspect of the semantics of the attribute.  Furthermore, LLVM module-level optimizations could also theoretically drop the function body at any time as soon as they see that it is unused.

It seems to me that the right solution is for the definitions to remain strong and then only be selectively brought in when necessary to satisfy dependencies.  That could be done with a post-pass that makes the definitions linkonce_odr, or perhaps with an IR linker that simulates static-archive behavior.


http://reviews.llvm.org/D18095





More information about the cfe-commits mailing list