[nhc-users] A question about the Kernel module
Malcolm Wallace
Malcolm.Wallace at cs.york.ac.uk
Fri Jan 25 08:12:29 EST 2008
pierric <w.pierric at gmail.com> wrote:
> I read through the Makefile in Kernel module, and found the
> followings: ${SOBJS}: ${OBJDIR}/%.o: %.c
> ${CC} -S ${CFLAGSNOOPT} -o - $< |\
> sed -e '/.align 32/s/32/4/' -e '/.p2align 5/s/5/2/' |\
> ${CC} -c -x assembler-with-cpp ${CFLAGSNOOPT} -o $@ -
> what frustrated me is the sed, which does some replacement. So my
> question is why we make these replacement , from .align 32 to .align
> 4?
We call this the "evil mangler", which is similar in purpose to the
"evil mangler" in GHC, although a lot smaller and simpler. Basically,
sometimes the C compiler (gcc) generates assembler code which does not
fit the assumptions of the Haskell compiler. The "evil mangler"
post-processes the assembler code to fix these mistakes.
nhc98 generates bytecodes, stored in a large array of words. We also
need the linker to be able to use pointers into the middle of the array,
which we achieve by splitting the array into smaller pieces. Each
small array is declared in the correct sequence so that when they are
placed together contiguously in memory, it is possible to index from
_either_ the beginning of the large array, _or_ from any of the smaller
arrays. For instance:
unsigned begin[] = { 12, 11, 9, 3 };
unsigned f[] = { 0, 42, 0, 0 };
The number "42" is located at positions: begin[5] _and_ f[1].
Unfortunately, some versions of gcc do not place these two arrays next
to each other in memory. The ".align 32" (equivalently ".p2align 5")
instruction inserts some extra zero-padded space. Hence, we need to
post-process the code to remove or change the alignment.
Regards,
Malcolm
More information about the Nhc-users
mailing list