How to set alignment and READONLY of a brand new section
Nick Clifton
nickc@redhat.com
Mon May 20 14:54:49 GMT 2024
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
More information about the Binutils
mailing list