Bug 30794 - PowerPC port of gold fails with: internal error in add_output_section_to_load, at gold/output.cc:4097
Summary: PowerPC port of gold fails with: internal error in add_output_section_to_loa...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-08-24 13:31 UTC by Nick Clifton
Modified: 2023-08-25 02:42 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Clifton 2023-08-24 13:31:50 UTC
For the PowerPC port of gold:

  % gold/ld-new -m elf32ppc -shared /dev/null -o test
  gold/ld-new: error: /dev/null: file is empty
  gold/ld-new: internal error in add_output_section_to_load, at gold/output.cc:4097

Note - the input file does not appear to be relevant.  This example uses /dev/null, but the same bug has been reported with other, non-empty input files:

  https://bugzilla.redhat.com/show_bug.cgi?id=2234396
Comment 1 Alan Modra 2023-08-24 23:40:47 UTC
Caused by commit 5a97377e5513, specifically this code added to Target_powerpc::do_relax
+      if (parameters->options().output_is_position_independent())
+       this->rela_dyn_size_
+         = this->rela_dyn_section(layout)->current_data_size();

The problem here is that if .rela.dyn isn't already created then the call to rela_dyn_section creates is, and as this comment says
	  // Annoyingly, we need to make these sections now whether or
	  // not we need them.  If we delay until do_relax then we
	  // need to mess with the relaxation machinery checkpointing.
Comment 2 Sourceware Commits 2023-08-25 02:04:06 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d537f77ef3b18a5fbfd598643aaad957652e9608

commit d537f77ef3b18a5fbfd598643aaad957652e9608
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Aug 25 09:12:18 2023 +0930

    PR30794, PowerPC gold: internal error in add_output_section_to_load
    
    Caused by commit 5a97377e5513, specifically this code added to
    Target_powerpc::do_relax
    +      if (parameters->options().output_is_position_independent())
    +       this->rela_dyn_size_
    +         = this->rela_dyn_section(layout)->current_data_size();
    
    The problem here is that if .rela.dyn isn't already created then the
    call to rela_dyn_section creates it, and as this comment in
    Target_powerpc::do_finalize_sections says:
              // Annoyingly, we need to make these sections now whether or
              // not we need them.  If we delay until do_relax then we
              // need to mess with the relaxation machinery checkpointing.
    We can't be creating sections in do_relax.
    
            PR 30794
            * powerpc.cc (Target_powerpc::do_relax): Only set rela_dyn_size_
            for size == 64, and assert that rela_dyn_ already exists.
            Tidy code setting plt_thread_safe, which also only needs to be
            set when size == 64 for ELFv1.
Comment 3 Sourceware Commits 2023-08-25 02:41:25 UTC
The binutils-2_41-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=60834ae1eb7b4f87598cfa79abdc72221415ac9e

commit 60834ae1eb7b4f87598cfa79abdc72221415ac9e
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Aug 25 09:12:18 2023 +0930

    PR30794, PowerPC gold: internal error in add_output_section_to_load
    
    Caused by commit 5a97377e5513, specifically this code added to
    Target_powerpc::do_relax
    +      if (parameters->options().output_is_position_independent())
    +       this->rela_dyn_size_
    +         = this->rela_dyn_section(layout)->current_data_size();
    
    The problem here is that if .rela.dyn isn't already created then the
    call to rela_dyn_section creates it, and as this comment in
    Target_powerpc::do_finalize_sections says:
              // Annoyingly, we need to make these sections now whether or
              // not we need them.  If we delay until do_relax then we
              // need to mess with the relaxation machinery checkpointing.
    We can't be creating sections in do_relax.
    
            PR 30794
            * powerpc.cc (Target_powerpc::do_relax): Only set rela_dyn_size_
            for size == 64, and assert that rela_dyn_ already exists.
            Tidy code setting plt_thread_safe, which also only needs to be
            set when size == 64 for ELFv1.
    
    (cherry picked from commit d537f77ef3b18a5fbfd598643aaad957652e9608)
Comment 4 Alan Modra 2023-08-25 02:42:11 UTC
Fixed.