[PATCH v1 0/7 SECTOR: Support aligning to flash sector boundary

Ulf Samuelsson binutils@emagii.com
Fri Mar 10 17:01:47 GMT 2023


On 2023-03-10 15:13, Michael Matz wrote:
> Hello,
>
> On Fri, 10 Mar 2023, Ulf Samuelsson via Binutils wrote:
>
>> This can be used later to align a sector to the flash boundary using the
>>
>> ALIGN_SECTOR command in an output sector.
> Please consider implementing new features in terms of existing ones.  For
> instance there is already an 'ALIGN' expression, that either takes dot or
> an arbitrary expression to align, to a certain given value.  Your new
> feature is basically just a special value for such alignment, so it makes
> sense to specify _that_ instead of a new top-level expression.  So,
> consider accepting something like:
>
>     ALIGN(TOSECTOR)
>     ALIGN(expr, TOSECTOR)
>
> so that one would write
>
>     . = ALIGN(TOSECTOR)

I considered it, but came to the conclusion that it opens a bag of worms.

To fit this into the grammar, TOSECTOR (or maybe just SECTOR)
needs to be a valid expression, returning the size of the flash sector
where the location counter is.

Since expressions are available everywhere, you run into situations
where it really does not make sense for "SECTOR" to have a value.

It only makes sense when the linker is processing the output section,
and even there, it hardly makes sense to use it except as a way to
finish the output section.

The way it is implemented, it is really more of a subroutine than a 
function.
For each declared sector, there are four assignment statements.
One of them is moderately complex.
It is not uncommon for larger microcontrollers to have 32 or more flash 
sectors.
I do not rule out that microcontrollers will have 64 or even 128 flash 
sectors.

To create an function which collapses 100+ statements into a single 
expression
may stress the expression evaluator in unpredictable ways.

Have the linker been tested with 100-200 lines+ expressions?

Another aspect is what part of the code is affected.
Right now, everything except flex/bison code is inside a new file 
(ldsectors.c)

The alternative that I could consider is to add it in the Output Section 
Description
There you can specify ALIGN_WITH_INPUT which has a similar syntax as 
ALIGN_SECTOR
so alignment is specified either using an expression or a special 
keyword already today.

It may be possible to have ALIGN '(' SECTOR ')' as a statement (not an 
expression)

Best Regards
Ulf Samuelsson


>
> as usual with alignment of dot.  The 'TOSECTOR' token would be the new
> thing and make it do what you wanted with ALIGN_SECTOR.
>
>
> Ciao,
> Michael.


More information about the Binutils mailing list