Skip to content

Commit

Permalink
Pass GCC offload data to the LTO backend
Browse files Browse the repository at this point in the history
Fixes #1190
  • Loading branch information
rui314 committed Feb 19, 2024
1 parent 4c35523 commit 64c2084
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions elf/input-files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ void ObjectFile<E>::initialize_sections(Context<E> &ctx) {
const ElfShdr<E> &shdr = this->elf_sections[i];
std::string_view name = this->shstrtab.data() + shdr.sh_name;

if ((shdr.sh_flags & SHF_EXCLUDE) &&
name.starts_with(".gnu.offload_lto_.symtab.")) {
this->is_gcc_offload_obj = true;
continue;
}

if ((shdr.sh_flags & SHF_EXCLUDE) && !(shdr.sh_flags & SHF_ALLOC) &&
shdr.sh_type != SHT_LLVM_ADDRSIG && !ctx.arg.relocatable)
continue;
Expand Down
12 changes: 12 additions & 0 deletions elf/lto-unix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,18 @@ std::vector<ObjectFile<E> *> do_lto(Context<E> &ctx) {
for (Symbol<E> *sym : ctx.arg.undefined)
sym->referenced_by_regular_obj = true;

// Object files containing .gnu.offload_lto_.* sections need to be
// given to the LTO backend. Such sections contains code and data for
// peripherails (typically GPUs).
for (ObjectFile<E> *file : ctx.objs) {
if (!file->is_lto_obj && file->is_gcc_offload_obj) {
PluginInputFile pfile = create_plugin_input_file(ctx, file->mf);
int claimed = false;
claim_file_hook(&pfile, &claimed);
assert(!claimed);
}
}

// all_symbols_read_hook() calls add_input_file() and add_input_library()
LOG << "all symbols read\n";
if (PluginStatus st = all_symbols_read_hook(); st != LDPS_OK)
Expand Down
1 change: 1 addition & 0 deletions elf/mold.h
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,7 @@ class ObjectFile : public InputFile<E> {
std::map<u32, u32> gnu_properties;
bool needs_executable_stack = false;
bool is_lto_obj = false;
bool is_gcc_offload_obj = false;
bool is_rust_obj = false;

u64 num_dynrel = 0;
Expand Down
2 changes: 1 addition & 1 deletion elf/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void resolve_symbols(Context<E> &ctx) {

bool has_lto_obj = false;
for (ObjectFile<E> *file : objs)
if (file->is_lto_obj)
if (file->is_lto_obj || file->is_gcc_offload_obj)
has_lto_obj = true;

if (has_lto_obj) {
Expand Down

0 comments on commit 64c2084

Please sign in to comment.