[PATCH] D28523: [ThinLTO] Ensure objects from static libraries linked in correct order

Teresa Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 10 11:49:15 PST 2017


tejohnson created this revision.
tejohnson added reviewers: mehdi_amini, pcc.
tejohnson added a subscriber: llvm-commits.

I recently discovered that ThinLTO native objects links sometimes
occur in a different order than the objects were selected out of
static libraries by the native linker. The ThinLTO ModuleMap
is built (e.g. for gold-plugin) in the original order the objects are
listed in the library. However, the linker may select for inclusion
a later object in a static library first, based on the strong references
it satisfies. It's copies of weak symbols may then be prevailing instead
of an earlier object in the same library. However, the native objects
are linked in the order they were added to the ModuleMap, which would
result in the wrong copy of a weak function being selected in the final
native link for ThinLTO, resulting in incorrect behavior.

Since the linker doesn't provide the native object ordering to the
plugin, we can deduce the correct ordering among modules defining
the same weak symbol based on the prevailing symbols
in the combined index. With this patch we use a stable topological
sort to sort the ModuleMap based on the partial ordering provided by
the combined index.


https://reviews.llvm.org/D28523

Files:
  include/llvm/LTO/LTO.h
  lib/LTO/LTO.cpp
  test/tools/gold/X86/Inputs/thinlto_weak_library1.ll
  test/tools/gold/X86/Inputs/thinlto_weak_library2.ll
  test/tools/gold/X86/thinlto_weak_library.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28523.83840.patch
Type: text/x-patch
Size: 12440 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170110/799cfa29/attachment.bin>


More information about the llvm-commits mailing list