| (bfd_get_flavour (abfd) == bfd_target_elf_flavour
? EXEC_P : 0))) == 0)
{
- asection *sec;
+ asection *sec = abfd->sections;
enum bfd_lto_object_type type = lto_non_ir_object;
- struct lto_section lsection = { 0, 0, 0, 0 };
- /* GCC uses .gnu.lto_.lto.<some_hash> as a LTO bytecode information
- section. */
- for (sec = abfd->sections; sec != NULL; sec = sec->next)
- if (strcmp (sec->name, GNU_OBJECT_ONLY_SECTION_NAME) == 0)
- {
- type = lto_mixed_object;
- abfd->object_only_section = sec;
- break;
- }
- else if (strcmp (sec->name, ".llvm.lto") == 0)
- {
- type = lto_fat_ir_object;
- break;
- }
- else if (lsection.major_version == 0
- && startswith (sec->name, ".gnu.lto_.lto.")
- && bfd_get_section_contents (abfd, sec, &lsection, 0,
- sizeof (struct lto_section)))
- {
- if (lsection.slim_object)
- type = lto_slim_ir_object;
- else
- type = lto_fat_ir_object;
+ if (sec == NULL)
+ {
+ /* If there are no sections, check for slim LLVM IR object whose
+ first 4 bytes are: 'B', 'C', 0xc0, 0xde. */
+ bfd_byte llvm_ir_magic[4];
+ if (bfd_seek (abfd, 0, SEEK_SET) == 0
+ && bfd_read (llvm_ir_magic, 4, abfd) == 4
+ && llvm_ir_magic[0] == 'B'
+ && llvm_ir_magic[1] == 'C'
+ && llvm_ir_magic[2] == 0xc0
+ && llvm_ir_magic[3] == 0xde)
+ type = lto_slim_ir_object;
+ }
+ else
+ {
+ struct lto_section lsection = { 0, 0, 0, 0 };
+ /* GCC uses .gnu.lto_.lto.<some_hash> as a LTO bytecode
+ information section. */
+ for (; sec != NULL; sec = sec->next)
+ if (strcmp (sec->name, GNU_OBJECT_ONLY_SECTION_NAME) == 0)
+ {
+ type = lto_mixed_object;
+ abfd->object_only_section = sec;
+ break;
+ }
+ else if (strcmp (sec->name, ".llvm.lto") == 0)
+ {
+ type = lto_fat_ir_object;
+ break;
+ }
+ else if (lsection.major_version == 0
+ && startswith (sec->name, ".gnu.lto_.lto.")
+ && bfd_get_section_contents (abfd, sec, &lsection, 0,
+ sizeof (struct lto_section)))
+ {
+ if (lsection.slim_object)
+ type = lto_slim_ir_object;
+ else
+ type = lto_fat_ir_object;
}
+ }
abfd->lto_type = type;
}
/* TRUE if some sections are to be removed. */
static bool sections_removed;
-#if BFD_SUPPORTS_PLUGINS
-/* TRUE if all GCC LTO sections are to be removed. */
-static bool lto_sections_removed;
-#else
-#define lto_sections_removed false
-#endif
-
/* TRUE if only some sections are to be copied. */
static bool sections_copied;
}
#if BFD_SUPPORTS_PLUGINS
- /* Copy LTO IR file as unknown object. */
- if (!lto_sections_removed
- && this_element->lto_type == lto_slim_ir_object)
+ /* Copy slim LTO IR file as unknown object. */
+ if (this_element->lto_type == lto_slim_ir_object)
ok_object = false;
#endif
if (ok_object)
}
#if BFD_SUPPORTS_PLUGINS
- /* Copy LTO IR file as unknown object. */
- if (!lto_sections_removed
- && ibfd->lto_type == lto_slim_ir_object)
+ /* Copy slim LTO IR file as unknown file. */
+ if (ibfd->lto_type == lto_slim_ir_object)
ok_object = false;
#endif
if (ok_object
#if BFD_SUPPORTS_PLUGINS
/* Check if all GCC LTO sections should be removed, assuming all LTO
- sections will be removed with -R .gnu.lto_.*. * Remove .gnu.lto_.*
- sections will also remove .gnu.debuglto_. sections. LLVM IR
- bitcode is stored in .llvm.lto section which will be removed with
- -R .llvm.lto. */
- lto_sections_removed = (!!find_section_list (".gnu.lto_.*", false,
- SECTION_CONTEXT_REMOVE)
- || !!find_section_list (".llvm.lto", false,
- SECTION_CONTEXT_REMOVE));
- /* NB: Must keep .gnu.debuglto_* sections unless all GCC LTO sections
+ sections will be removed with -R .gnu.lto_.*. Remove .gnu.lto_.*
+ sections will also remove .gnu.debuglto_.* sections.
+
+ NB: Must keep .gnu.debuglto_* sections unless all GCC LTO sections
will be removed to avoid undefined references to symbols in GCC LTO
debug sections. */
- if (!lto_sections_removed)
+ if (!find_section_list (".gnu.lto_.*", false, SECTION_CONTEXT_REMOVE))
find_section_list (".gnu.debuglto_*", true, SECTION_CONTEXT_KEEP);
#endif
] \
]
-if { [check_lto_fat_available] } {
- run_lto_binutils_test [list \
- [list \
- "strip" \
- "-R .gnu.*lto_* -N __gnu_lto_v1" \
- "strip-1a.o" \
- "strip-1a-s-all.o" \
- {{nm -n strip-1a-s-all.nd}} \
- ] \
- [list \
- "strip" \
- "-R .gnu.*lto_* -N __gnu_lto_v1" \
- "libstrip-1a.a" \
- "libstrip-1a-s-all.a" \
- {{nm -n strip-1a-s-all.nd}} \
- ] \
- ]
-}
+run_lto_binutils_test [list \
+ [list \
+ "strip" \
+ "-R .gnu.*lto_* -N __gnu_lto_v1" \
+ "strip-1a.o" \
+ "strip-1a-s-all.o" \
+ {{nm -n strip-1a-s-all.nd}} \
+ ] \
+ [list \
+ "strip" \
+ "-R .gnu.*lto_* -N __gnu_lto_v1" \
+ "libstrip-1a.a" \
+ "libstrip-1a-s-all.a" \
+ {{nm -n strip-1a-s-all.nd}} \
+ ] \
+]
run_cc_link_tests [list \
[list \