This is the mail archive of the
mailing list for the binutils project.
Re: [PATCH] ld: add support for LOG2() in linker scripts
- From: Hans-Peter Nilsson <hp at bitrange dot com>
- To: Clemens Lang <clemens dot lang at fau dot de>
- Cc: binutils at sourceware dot org, raimue at cs dot fau dot de
- Date: Mon, 22 Jul 2013 18:26:26 -0400 (EDT)
- Subject: Re: [PATCH] ld: add support for LOG2() in linker scripts
- References: <20130719124523 dot GA4031 at towel dot neverpanic dot de>
On Fri, 19 Jul 2013, Clemens Lang wrote:
> I recently needed linker sections to have a size that is a power of two,
> because MPUs on ARM devices conforming to PMSAv7 only support region
> sizes that are powers of two. It seems there was no way to do that in
> a linker script so far. Previous solutions I've seen involved linking
> the binary twice and automatically adjusting the linker script depending
> on the binary linked in the first step.
> Please find attached a patch against the GNU ld source to add a unary
> LOG2() function, returning the binary logarithm of its argument, rounded
> towards 0. The implementation also returns 0 for a zero argument.
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)?