ld: output section alignment and empty section.
KONRAD Frederic
frederic.konrad@adacore.com
Wed Mar 11 14:14:20 GMT 2020
More information about the Binutils mailing list
Wed Mar 11 14:14:20 GMT 2020
- Previous message (by thread): ld: output section alignment and empty section.
- Next message (by thread): ld: output section alignment and empty section.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi Alan,
Le 3/10/20 à 7:42 AM, Alan Modra a écrit :
> On Thu, Mar 05, 2020 at 02:55:44PM +0100, KONRAD Frederic wrote:
>> Hi,
>>
>> I just figured out that the following linker script hunk:
>>
>> . = ALIGN(0x4);
>> .rodata :
>> {
>> . = ALIGN(0x4);
>> }
>>
>> is creating an empty .rodata output section while I was expecting it not to be
>> emited.
>>
>> This is because we flag ". = ALIGN(xxx)" as SEC_KEEP in exp_fold_tree_1.
>>
>> Dropping that for ". = ALIGN(constant)" seems to fix the behavior:
>
> Yes it would, but you could also write the align inside .rodata using
>
> . = ALIGN(. != 0 ? 4 : 1);
>
> That is one of the few forms of assigning to dot that ld recognises as
> *not* resulting in "keep this section". This is documented under node
> "Output Section Discarding" in ld.info.
Arg I missed this..
>
> I don't think there is a good reason to change this behaviour as there
> may even be scripts that rely on a simpler ALIGN to keep the section.
>
>> Is that because strip_excluded_output_sections happens before the relaxation?
>> Could that be a problem in the case of a constant alignment?
>
> Yes and yes. It is possible to create a script that assigns an
> address (before the colon in an output section statement) or alignment
> (after the colon) to a section less than the constant alignment in
> some ". = ALIGN();" statement in that section, and the addresses of
> prior sections conspire to make the alignment do nothing before
> relaxation but to add padding when prior sections change. The patches
> that were reverted with e0a3af227e ran into something like that when I
> tried to make the single operand ALIGN behave like the two operand
> form.
>
>> What do you think?
>
> Fix your script. :-)
>
Agreed I tried the above ". = ALIGN(. != 0 ? 4 : 1)" and it seems to do the job.
Thanks you very much for your input!
- Previous message (by thread): ld: output section alignment and empty section.
- Next message (by thread): ld: output section alignment and empty section.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list