OSDN Git Service

[ThinLTO/gold] Handle bitcode archives
authorTeresa Johnson <tejohnson@google.com>
Thu, 26 May 2016 01:46:41 +0000 (01:46 +0000)
committerTeresa Johnson <tejohnson@google.com>
Thu, 26 May 2016 01:46:41 +0000 (01:46 +0000)
commitbb83f899dcb636ab50862d21c34e6e0c6012e2c9
tree54a90ecc0eddbae2abc072b4b207667addb3539d
parent3eda57ba2fa307d21730112d7c4907c12b3e8a50
[ThinLTO/gold] Handle bitcode archives

Summary:
Several changes were required for ThinLTO links involving bitcode
archive static libraries. With this patch clang/llvm bootstraps with
ThinLTO and gold.

The first is that the gold callbacks get_input_file and
release_input_file can normally be used to get file information for
each constituent bitcode file within an archive. However, these
interfaces lock the underlying file and can't be for each archive
constituent for ThinLTO backends where we get all the input files up
front and don't release any until after the backend threads complete.
However, it is sufficient to only get and release once per file, and
then each consituent bitcode file can be accessed via get_view. This
required saving some information to identify which file handle is the
"leader" for each claimed file sharing the same file descriptor, and
other information so that get_input_file isn't necessary later when
processing the backends.

Second, the module paths in the index need to distinguish between
different constituent bitcode files within the same archive file,
otherwise they will all end up with the same archive file path.
Do this by appending the offset within the archive for the start of the
bitcode file, returned by get_input_file when we claim each bitcode file,
and saving that along with the file handle.

Third, rather than have the function importer try to load a file based
on the module path identifier (which now contains a suffix to
distinguish different bitcode files within an archive), use a custom
module loader. This is the same approach taken in libLTO, and I am using
the support refactored into the new LTO.h header in r270509. The module
loader parses the bitcode files out of the memory buffers returned from
gold via the get_view callback and saved in a map. This also means that
we call the function importer directly, rather than add it to the pass
pipeline (which was in the plan to do already for other reasons).

Reviewers: pcc, joker.eph

Subscribers: llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D20559

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270814 91177308-0d34-0410-b5e6-96231b3b80d8
test/tools/gold/X86/Inputs/thinlto_archive1.ll [new file with mode: 0644]
test/tools/gold/X86/Inputs/thinlto_archive2.ll [new file with mode: 0644]
test/tools/gold/X86/thinlto_archive.ll [new file with mode: 0644]
tools/gold/CMakeLists.txt
tools/gold/gold-plugin.cpp