A question about the Kernel module

View: New views
2 Messages — Rating Filter:   Alert me  

A question about the Kernel module

by pierric-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi:
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? Thanks.
Best regards.
_______________________________________________
Nhc-users mailing list
Nhc-users@...
http://www.haskell.org/mailman/listinfo/nhc-users

Re: A question about the Kernel module

by Malcolm Wallace :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

pierric <w.pierric@...> 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
_______________________________________________
Nhc-users mailing list
Nhc-users@...
http://www.haskell.org/mailman/listinfo/nhc-users