public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Clifton <nickc@redhat.com>
To: Massimiliano Cialdi <cialdi@gmail.com>, binutils@sourceware.org
Subject: Re: How to set alignment and READONLY of a brand new section
Date: Mon, 20 May 2024 15:54:49 +0100	[thread overview]
Message-ID: <3ec26bd3-bfac-4729-9cf4-572830dce1d9@redhat.com> (raw)
In-Reply-To: <CABgYhWdThrPPX_gJDMUDE7A+uNDOAouwyYVK=fX-aU2suwvhoQ@mail.gmail.com>

Hi Massimiliano,

> I apologize in advance if this is not the right place for this question.

No this is the right place. :-)


>      .CLI_cmd_section : ALIGN(8)

> Though, inspecting with objdump I see that the section is aligned to 32 bytes:

>   26 .CLI_cmd_section   00000068  0000000000009020  0000000000009020  00008020  2**5  CONTENTS, ALLOC, LOAD, DATA

The ALIGN() directive can only increase an output section's alignment.
It does not force a specified alignment.  So if an input section has
an alignment greater than 8 this will make the output section also
be aligned to this larger value.

You can however override an input section's alignment by using the
SUBALIGN() directive.  So this might work:

   .CLI_cmd_section : ALIGN(8) SUBALIGN(8)

(Without an actual testcase I cannot be sure of this.  For all I know
there may be a linker bug here as well...)


> Also I would like this section to be READONLY, but if I try to impose it I get a warning on the link which I don't know how "serious" it is:
> 
> /usr/bin/ld: /tmp/ccDmg9Dd.o: warning: relocation in read-only section `.CLI_cmd.__CLI_cmd_help'
> /usr/bin/ld: warning: creating DT_TEXTREL in a PIE

It is pretty serious.  The linker is telling you that it needs
to create a run-time relocation that will affect the contents of
a read-only section.  Which is bad because it means that the loader
will have to remove the read-only protection from that section in
order to be able to implement the relocation.

You need to investigate and find out what information this relocation
is trying to store in the .CLI_cmd_section and then decide if a) the
information is not needed and so can be removed from the input or b)
the information is needed and so the .CLI_cmd_section should not be
marked as READONLY.

Cheers
   Nick


      reply	other threads:[~2024-05-20 14:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-18 22:34 Massimiliano Cialdi
2024-05-20 14:54 ` Nick Clifton [this message]

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=3ec26bd3-bfac-4729-9cf4-572830dce1d9@redhat.com \
    --to=nickc@redhat.com \
    --cc=binutils@sourceware.org \
    --cc=cialdi@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).