[PATCH] ld: add support for LOG2() in linker scripts

Clemens Lang clemens.lang@fau.de
Tue Jul 23 15:26:00 GMT 2013


On Mon, Jul 22, 2013 at 06:26:26PM -0400, Hans-Peter Nilsson wrote:
> But why the floor of the log2; why round towards 0?
> 
> I'd think rounding against infinity, but with 0 yielding 0,
> would be more useful, yielding the required power of 2 of the
> memory size to contain the region.  You wouldn't be interested
> in 75k yielding "16" (as 64k); for anything above 64k up to 128k
> you'd want "17"; a 128k memory is needed.  That seems to match
> your requirement description as well.
> 
> How about tweaking this to instead yield the ceiling of the log2
> (with 0 yielding 0)?

I agree that this is more useful in the context of linker scripts. I
initially didn't implement it this way, because it seemed uncommon to me
that a function called "LOG2" returning an integer rounds towards
infinity.

What about two variants of the funtion, LOG2FLOOR and LOG2CEIL? Or
should I just ignore the ambiguity and have LOG2 round up?

-- 
Clemens Lang



More information about the Binutils mailing list