[MLton-user] experimental release 20051109
Matthew Fluet
fluet@cs.cornell.edu
Mon, 14 Nov 2005 22:19:10 -0500 (EST)
> I tried compiling with -codegen c -profile time using the following
> two versions of {Declare,}ProfileLabel on my Linux machine with gcc
> 3.3.5.
>
> ----------------------------------------------------------------------
> #define DeclareProfileLabel(l) \
> void l()
> #define ProfileLabel(l) \
> __asm__ __volatile__ (".globl _" #l "\n_" #l ":" : : )
> ----------------------------------------------------------------------
> #define DeclareProfileLabel(l) \
> extern void l () asm (#l "_internal")
> #define ProfileLabel(l) \
> __asm__ __volatile__ (#l "_internal:" : : )
> ----------------------------------------------------------------------
>
> Both of them failed, when trying to run the executable, with
>
> Max profile label is 0 -- something is wrong.
>
> Am I doing something wrong?
There are actually two DeclareProfileLabel macros; one in include/main.h
and one in include/c-chunk.h. They both need to agree on what to call the
label from assembly. Then, because we are extern importing the symbol, C
won't attempt to make the symbol visible outside the single object file.
So, we can use the .globl trick from the __APPLE_CC__ branch. So, the
following appears to work:
#define DeclareProfileLabel(l) \
extern void l () asm (#l "_internal")
#define ProfileLabel(l) \
__asm__ __volatile__ (".globl " #l "_internal\n" #l "_internal :" : : )
Note that the DeclareProfileLabel macro needs to appear both in main.h and
c-chunk.h.
Actually, I don't know why files with c-chunk.h need to declare their
profile labels. C doesn't see these labels at all.
Also, I don't recall why we add the _internal suffix to profile labels in
C, but if we adopt the above, then the x86-codegen needs to emit profile
labels with the same suffix. (Which is a trivial change.)