[Driver][Bundler] Improve bundling of object files.
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 15 Aug 2019 17:15:35 +0000 (17:15 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 15 Aug 2019 17:15:35 +0000 (17:15 +0000)
commit2d5b64590137522b1600252bfd18a73ed7030ed3
tree22e6d71313f84fa100478763618c17448dc47737
parentf5b3bb8d586c78a2706c0956e0e5435374b6adb2
[Driver][Bundler] Improve bundling of object files.

Summary:
Previously, object files were bundled using partial linking. It resulted
in the following structure of the bundled objects:
```
<host_code>
clang-offload-bundle
__CLANG_OFFLOAD_BUNDLE__<target>
<target_code>
```
But when we tried to unbundle object files, it worked correctly only for
the target objects. The host object remains bundled. It produced a lot of
junk sections in the host object files and in some cases may caused
incorrect linking.

Patch improves bundling of the object files. After this patch the
bundled object looks like this:

```
<host_code>
clang-offload-bundle
__CLANG_OFFLOAD_BUNDLE__<target>
<target_code>
__CLANG_OFFLOAD_BUNDLE__<host>
<host_code>
```

With this structure we are able to unbundle the host object files too so
that after unbundling they are the same as were before.
The host section is bundled twice. The bundled section is used to
unbundle the original host section.

Reviewers: yaxunl, tra, jlebar, hfinkel, jdoerfert

Subscribers: caomhin, kkwli0, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65819

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@369019 91177308-0d34-0410-b5e6-96231b3b80d8
test/Driver/clang-offload-bundler.c
tools/clang-offload-bundler/ClangOffloadBundler.cpp