https://sourceware.org/bugzilla/show_bug.cgi?id=32870

            Bug ID: 32870
           Summary: [ARM32] Error occurs when linking with LLVMgold.so
                    plugin under LTO optimization
           Product: binutils
           Version: 2.41
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: dongjianqiang2 at huawei dot com
  Target Milestone: ---

Reproduction environment:  
- Toolchain: LLVM 15.0.4 + binutils 2.41 
- testcase main.c: int main() {  return 0;}
- Flags: clang main.c -flto=thin -O2 -fuse-ld=ld -v --save-temps
-Wl,-plugin-opt=save-temps 
- Core dump info: ld: main.o (symbol from plugin): Number of symbols in input
file has increased from 0 to 1
- bt info: elf32_arm_output_arch_local_syms (output_bfd=0x5555557eddc0,
info=0x5555557870c0 <link_info>, flaginfo=0x7fffffffd930, func=0x55555563ff32
<elf_link_output_symstrtab>) at /binutils-gdb/bfd/elf32-arm.c:18362
18362                   if (local_iplt[i] != NULL

(gdb) p *input_bfd
$6 = {filename = 0x5555558499b0 "main.o (symbol from plugin)", xvec =
0x555555783200 <elf32_le_vec>, iostream = 0x555555808980, iovec =
0x555555775180 <_bfd_memory_iovec>, lru_prev = 0x0,
  lru_next = 0x0, where = 90, mtime = 0, id = 4294967292, flags = 71696, format
= bfd_object, direction = read_direction, last_io = bfd_io_read, cacheable = 0,
target_defaulted = 1, opened_once = 0,
  mtime_set = 0, no_export = 0, output_has_begun = 0, has_armap = 0,
is_thin_archive = 0, no_element_cache = 0, selective_search = 0,
is_linker_output = 0, is_linker_input = 0,
  plugin_format = bfd_plugin_unknown, lto_output = 0, lto_slim_object = 0,
read_only = 0, plugin_dummy_bfd = 0x0, origin = 0, proxy_origin = 0,
section_htab = {table = 0x555555864a10,
    newfunc = 0x5555555d25a2 <bfd_section_hash_newfunc>, memory =
0x555555857df0, size = 4051, count = 1, entsize = 304, frozen = 0}, sections =
0x555555852f28, section_last = 0x555555852f28,
  section_count = 1, archive_plugin_fd = -1, archive_plugin_fd_open_count = 0,
archive_pass = 0, alloc_size = 16069, start_address = 0, outsymbols = 0x0,
symcount = 0, dynsymcount = 0,
  arch_info = 0x555555775060 <bfd_default_arch_struct>, size = 324, arelt_data
= 0x0, my_archive = 0x0, archive_next = 0x0, archive_head = 0x0,
nested_archives = 0x0, link = {next = 0x555555855980,
    hash = 0x555555855980}, tdata = {aout_data = 0x55555585ba40, aout_ar_data =
0x55555585ba40, coff_obj_data = 0x55555585ba40, pe_obj_data = 0x55555585ba40,
xcoff_obj_data = 0x55555585ba40,
    ecoff_obj_data = 0x55555585ba40, srec_data = 0x55555585ba40, verilog_data =
0x55555585ba40, ihex_data = 0x55555585ba40, tekhex_data = 0x55555585ba40,
elf_obj_data = 0x55555585ba40,
    mmo_data = 0x55555585ba40, trad_core_data = 0x55555585ba40, som_data =
0x55555585ba40, hpux_core_data = 0x55555585ba40, hppabsd_core_data =
0x55555585ba40, sgi_core_data = 0x55555585ba40,
    lynx_core_data = 0x55555585ba40, osf_core_data = 0x55555585ba40,
cisco_core_data = 0x55555585ba40, netbsd_core_data = 0x55555585ba40,
mach_o_data = 0x55555585ba40, mach_o_fat_data = 0x55555585ba40,
    plugin_data = 0x55555585ba40, pef_data = 0x55555585ba40, pef_xlib_data =
0x55555585ba40, sym_data = 0x55555585ba40, any = 0x55555585ba40}, usrdata =
0x55555578a4e0, memory = 0x555555830c80,
  build_id = 0x0}

After analysis, I identified that the main.o (which is a bitcode file) should
not be processed in this context. The fix was implemented by referencing
modifications made in similar cases, and the corresponding patch is attached
below.

diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 3b7cee3de1c..3af964ce034 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -18345,6 +18345,9 @@ elf32_arm_output_arch_local_syms (bfd *output_bfd,
          struct arm_local_iplt_info **local_iplt;
          unsigned int i, num_syms;

+         if (!is_arm_elf (input_bfd))
+           continue;
+
          local_iplt = elf32_arm_local_iplt (input_bfd);
          if (local_iplt != NULL)
            {

Please let me know if you have any questions.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to