|
| 1 | +// REQUIRES: x86-registered-target |
| 2 | +// RUN: %clangxx -c %s -o %t_fat.o |
| 3 | +// RUN: %clangxx %t_fat.o -o %t.exe |
| 4 | +// RUN: clang-offload-bundler -type=oo -targets=host-x86_64-unknown-linux-gnu,sycl-x86_64-unknown-linux-gnu -outputs=%t.o,%t_list.txt -inputs=%t_fat.o -unbundle |
| 5 | +// RUN: %t.exe %t_list.txt | FileCheck %s |
| 6 | +// CHECK:11 |
| 7 | +// CHECK:222 |
| 8 | +// CHECK:3333 |
| 9 | + |
| 10 | +#include <cstdint> |
| 11 | +#include <iostream> |
| 12 | +#include <fstream> |
| 13 | +#include <string> |
| 14 | +#include <vector> |
| 15 | +using namespace std; |
| 16 | + |
| 17 | +#define BUNDLE_SECTION_PREFIX "__CLANG_OFFLOAD_BUNDLE__" |
| 18 | +#define BUNDLE_SIZE_SECTION_PREFIX "__CLANG_OFFLOAD_BUNDLE_SIZE__" |
| 19 | + |
| 20 | +#define TARGET0 "host-x86_64-unknown-linux-gnu" |
| 21 | +#define TARGET1 "sycl-x86_64-unknown-linux-gnu" |
| 22 | + |
| 23 | +// Populate section with special names recognized by the bundler; |
| 24 | +// this emulates fat object partially linked from 3 other fat objects. |
| 25 | +// The test uses the bundler to split the bundle into 3 objects and then prints |
| 26 | +// their contents to stdout. |
| 27 | +char str0[] __attribute__((section(BUNDLE_SECTION_PREFIX TARGET0))) = { 0, 0, 0 }; |
| 28 | +int64_t size0[] __attribute__((section(BUNDLE_SIZE_SECTION_PREFIX TARGET0))) = { 1, 1, 1 }; |
| 29 | + |
| 30 | +char str1[] __attribute__((section(BUNDLE_SECTION_PREFIX TARGET1))) = { "11\n222\n3333\n" }; |
| 31 | +int64_t size1[] __attribute__((section(BUNDLE_SIZE_SECTION_PREFIX TARGET1))) = { 3, 4, 5 }; |
| 32 | + |
| 33 | +void cat(const string& File) { |
| 34 | + string Line; |
| 35 | + ifstream F(File); |
| 36 | + if (F.is_open()) { |
| 37 | + while (getline(F, Line)) { |
| 38 | + cout << Line << '\n'; |
| 39 | + } |
| 40 | + F.close(); |
| 41 | + } |
| 42 | + else cout << "Unable to open file " << File; |
| 43 | +} |
| 44 | + |
| 45 | +// main is invoked with the bundler output file as argument - |
| 46 | +// read this file and print their contents to stdout. |
| 47 | +int main(int argc, char **argv) { |
| 48 | + string ListFile(argv[1]); |
| 49 | + string Line; |
| 50 | + ifstream F(ListFile); |
| 51 | + vector<string> OutFiles; |
| 52 | + |
| 53 | + if (F.is_open()) { |
| 54 | + while (getline(F, Line)) { |
| 55 | + OutFiles.push_back(Line); |
| 56 | + } |
| 57 | + F.close(); |
| 58 | + } |
| 59 | + else { |
| 60 | + cout << "Unable to open file " << ListFile; |
| 61 | + return 1; |
| 62 | + } |
| 63 | + |
| 64 | + for (const auto &File : OutFiles) { |
| 65 | + cat(File); |
| 66 | + } |
| 67 | + return 0; |
| 68 | +} |
| 69 | + |
0 commit comments