]> granicus.if.org Git - clang/commitdiff
[OpenMP][Driver] Put target binary for each offload target into a
authorAlexey Bataev <a.bataev@hotmail.com>
Tue, 30 May 2017 18:57:51 +0000 (18:57 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Tue, 30 May 2017 18:57:51 +0000 (18:57 +0000)
separate section, by Sergey Dmitriev

Linker script that is generated by the clang driver for creating fat binary puts target binaries for all offload targets into a single ELF section .omp_offloading. This is not convenient because it greatly complicates operations with the final fat binary once it is linked. For example extracting target binary for a particular target from such fat executable would not be an easy task if you have more than one offload target.

Attached patch changes clang driver to put target binary for each
offload target into a separate ELF section .omp_offloading.<target
triple>.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304229 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains/Gnu.cpp
test/Driver/openmp-offload.c

index 1a398fd8a7739e8b1d0c5d1fdfad064e3acb4e32..d50f8e21f62f9724b674d49692ecf6a1681e2031 100644 (file)
@@ -278,20 +278,20 @@ static void AddOpenMPLinkerScript(const ToolChain &TC, Compilation &C,
 
   LksStream << "SECTIONS\n";
   LksStream << "{\n";
-  LksStream << "  .omp_offloading :\n";
-  LksStream << "  ALIGN(0x10)\n";
-  LksStream << "  {\n";
 
-  for (auto &BI : InputBinaryInfo) {
-    LksStream << "    . = ALIGN(0x10);\n";
+  // Put each target binary into a separate section.
+  for (const auto &BI : InputBinaryInfo) {
+    LksStream << "  .omp_offloading." << BI.first << " :\n";
+    LksStream << "  ALIGN(0x10)\n";
+    LksStream << "  {\n";
     LksStream << "    PROVIDE_HIDDEN(.omp_offloading.img_start." << BI.first
               << " = .);\n";
     LksStream << "    " << BI.second << "\n";
     LksStream << "    PROVIDE_HIDDEN(.omp_offloading.img_end." << BI.first
               << " = .);\n";
+    LksStream << "  }\n";
   }
 
-  LksStream << "  }\n";
   // Add commands to define host entries begin and end. We use 1-byte subalign
   // so that the linker does not add any padding and the elements in this
   // section form an array.
index 097dc7d17faafa19a11904a75f3b1f16e699a223..39eb41e6ac088db96d6f510040f6c220100f6f66 100644 (file)
 // CHK-LKS-ST: INPUT([[T2BIN:.+\.out-openmp-x86_64-pc-linux-gnu]])
 // CHK-LKS: SECTIONS
 // CHK-LKS: {
-// CHK-LKS:   .omp_offloading :
+// CHK-LKS:   .omp_offloading.powerpc64le-ibm-linux-gnu :
 // CHK-LKS:   ALIGN(0x10)
 // CHK-LKS:   {
-// CHK-LKS:     . = ALIGN(0x10);
 // CHK-LKS:     PROVIDE_HIDDEN(.omp_offloading.img_start.powerpc64le-ibm-linux-gnu = .);
 // CHK-LKS:     [[T1BIN]]
 // CHK-LKS:     PROVIDE_HIDDEN(.omp_offloading.img_end.powerpc64le-ibm-linux-gnu = .);
-// CHK-LKS:     . = ALIGN(0x10);
+// CHK-LKS:   }
+// CHK-LKS:   .omp_offloading.x86_64-pc-linux-gnu :
+// CHK-LKS:   ALIGN(0x10)
+// CHK-LKS:   {
 // CHK-LKS:     PROVIDE_HIDDEN(.omp_offloading.img_start.x86_64-pc-linux-gnu = .);
 // CHK-LKS:     [[T2BIN]]
 // CHK-LKS:     PROVIDE_HIDDEN(.omp_offloading.img_end.x86_64-pc-linux-gnu = .);