public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Clifton <nickc@redhat.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: Binutils <binutils@sourceware.org>
Subject: Re: Fwd: [PATCH v2] ld: Rewrite lang_size_relro_segment_1
Date: Mon, 24 Jan 2022 16:24:33 +0000	[thread overview]
Message-ID: <5448901b-167d-4423-c99e-557d8178e56d@redhat.com> (raw)
In-Reply-To: <CAMe9rOpdkYZDigz8r_oPbweLnaCJUjx3-L-v-vp-70c0MGOHQw@mail.gmail.com>

Hi H.J.

> Here is the v2 patch to track the maximum section alignment from
> the RELRO segment.  If the maximum page size >= the maximum
> section alignment, we can align the RELRO segment to the maximum
> page size.

I am having some trouble getting my head around this patch, so please
bare with me if I ask some silly questions:

    /* Find the first section in the relro segment. */
    for (sec = link_info.output_bfd->section_last; sec; sec = sec->prev)
      if ((sec->flags & SEC_ALLOC) != 0)
        {
  	if (last_sec_status != relro_sec_before
  	    && sec->alignment_power > max_alignment_power)
  	  max_alignment_power = sec->alignment_power;

  	if (sec->vma >= seg->base
  	    && sec->vma < seg->relro_end - seg->relro_offset)
  	  {
  	    relro_sec = sec;
  	    prev_sec = sec->prev;
  	    last_sec_status = relro_sec_in;
  	  }
  	else
  	  last_sec_status = relro_sec_before;
        }

Questions:
   Should a zero-sized section (with SHF_ALLOC) be treated as a
   viable candidate ?

   Once last_sec_status has been set to relro_sec_before, is there
   any point in continuing the scan ?

   If the section list contains a section which starts beyond the
   end of the segment (ie sec->vma >= seg->relro_end - seg->relro_offset)
   then a) is this an error ?  and b) should its alignment power be
   considered against max_alignment_power ?


    if (relro_sec)
      {
        /* Where do we want to put this section so that it ends as
  	 desired?  */

   By "desired" I assume you mean "with the desired alignment, but
   without any unnecessary padding".  Is that correct ?


       /* Find the first non-empty preceding section.  */
       for (; prev_sec; prev_sec = prev_sec->prev)
	if (prev_sec->size != 0 && (prev_sec->flags & SEC_ALLOC) != 0)
	  break;

   Given that prev_sec is only needed later on, inside an if-statement,
   you could move this loop - potentially saving a bit of time in some
   cases.


   Overall I think that the code could use some more comments, explaining
   what is going on with some examples of how each part of the algorithm
   operates.

Cheers
   Nick


  parent reply	other threads:[~2022-01-24 16:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-11  2:12 [PATCH] elf: Remove the 1-page gap before the RELRO segment H.J. Lu
2022-01-11  5:26 ` Fangrui Song
2022-01-13 12:44 ` Nick Clifton
2022-01-13 12:52 ` Alan Modra
2022-01-13 13:19   ` H.J. Lu
2022-01-14  8:12     ` Alan Modra
2022-01-14  9:37       ` Fangrui Song
2022-01-14 14:58       ` H.J. Lu
2022-01-14 21:55       ` [PATCH] ld: Rewrite lang_size_relro_segment_1 H.J. Lu
2022-01-17  4:08         ` Alan Modra
2022-01-18  4:16           ` [PATCH v2] " H.J. Lu
     [not found]             ` <CAMe9rOpdkYZDigz8r_oPbweLnaCJUjx3-L-v-vp-70c0MGOHQw@mail.gmail.com>
2022-01-24 16:24               ` Nick Clifton [this message]
2022-01-24 21:17                 ` [PATCH v3] " H.J. Lu
2022-01-25 15:05                   ` [PATCH v4] " H.J. Lu
2022-01-26 10:55                     ` Nick Clifton
2022-01-27  0:48                       ` Alan Modra
2022-01-27  2:10                         ` H.J. Lu
2022-01-29  1:01                           ` Alan Modra
2022-01-29  9:06                             ` Fangrui Song
2022-01-29 16:45                             ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5448901b-167d-4423-c99e-557d8178e56d@redhat.com \
    --to=nickc@redhat.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).