This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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

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[1]. 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)?

brgds, H-P

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]