bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Gold Bug and Patches


From: Nobody
Subject: Gold Bug and Patches
Date: Thu, 19 Dec 2019 07:06:10 +0000

Hey, y'all!


I was playing with directly invoking ld and then ld.gold to link c++
files, instead of using g++.

I inadvertently passed the -nostartfiles to the linker.

Since the linkers do not recognize this option, they interpreted it as
" -n -ostartfiles".

GNU ld created 2.2 Meg output files which seemed to work.

In ld.gold, the -n caused an assertion in this code in output.cc (line 4773)


  if (this->type_ == elfcpp::PT_GNU_RELRO)
    {
      uint64_t page_align = parameters->target().abi_pagesize();
      uint64_t segment_end = this->vaddr_ + this->memsz_;
      if (parameters->incremental_update())
        {
          // The INCREASE_RELRO calculation is bypassed for an incremental
          // update, so we need to adjust the segment size manually here.
          segment_end = align_address(segment_end, page_align);
          this->memsz_ = segment_end - this->vaddr_;
        }
      else
        gold_assert(segment_end == align_address(segment_end, page_align));
    }

It makes sense that if -n (do not page align data) is specified,
the data would not be page aligned, but I was not sure whether to
simply test options->nmagic() and options->omagic() before the
assertion, or if I should tell gold to page align PT_GNU_RELRO
sections in spite of the -n or -N flags.

I thought, however, that it would be a good idea for ld.gold to
ignore the -nostartfiles parameter, as it does the -nodefaultlibs
parameter, so I'm enclosing a patch to do that.

While debugging the issue, I found an annoying problem with running
the /tmp/ld-run-a.out.sh files which are created when main.cc is
compiled with the -DDEBUG option:  the bash process was reporting an
unexpected EOF on the script.  I've seen this before, it comes from
truncating a running script, so I am also enclosing a patch to cause
the write_debug_script function to create the new script as
/tmp/ld-run-a.out.sh-new, and then rename it to it's final name.


If somebody tells me what the proper behavior would be if -n is
specified and there is a PT_GNU_RELRO section, I could fix that
as well.

Thanks for ld.gold, it is SO MUCH faster than ld!


-------
http://ElectNobody.comĀ -- Vote for Nobody
Because Nobody should rule you ... but you!


Attachment: gold.debug.patch
Description: Text Data

Attachment: gold.nostartfiles.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]