[mercury-users] a theoretical problem

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Apr 28 16:49:47 AEST 2003


On 28-Apr-2003, Pieter Laeremans <pieter at kotnet.org> wrote:
> Fergus Henderson writes:
>  > On 24-Apr-2003, Tom Wouters <tom.wouters1 at student.kuleuven.ac.be> wrote:
> 
> First of all thanks very much for this reply !
>
>  > With the `--high-level-code' back-end, there's almost no need for a
>  > runtime system at all -- for example, I can run the N-queens program
>  > from tests/benchmarks/queens.m in the "hlc.gc" grade using a 128-byte
>  > runtime and standard library, plus the Boehm collector, plus the C
>  > standard library.  See the attached "tiny_runtime.c" file.
>  > 
>  > 128-bytes, fantastic!  That will fit in 16K no problem.  However, that's
>  > only half the story.  Of course the problem is that the Boehm collector
>  > and the C library are a lot bigger than 128 bytes.
> 
> Yes it is :-). But when I compile it's size is 's 1.2K.

The compiled size will obviously vary depending on the architecture.
The size I measured was on x86.

> When I compile tiny_runtime.c  with :
> 
> gcc -c -I/usr/local/mercury-0.11.0/lib/mercury/inc/ tiny_runtime.c
>
> Then I try to link it the queens.o genereated by mmc.
> 
> gcc -Wl,--gc-sections queens.o tiny_runtime.o -lgc -o test
> queens.o(.rodata+0x88): undefined reference to `MR_grade_v8_hlc_gc_tags2'
> collect2: ld returned 1 exit status

This is because you compiled queens.o and tiny_runtime.o using different
grades.  If you don't pass any "-D" options to gcc, this is equivalent
to compiling in the "none" grade.

It's better to use the "mgnuc" script rather than invoking gcc directly.
You can pass a "--grade" option to mgnuc, and then "mgnuc" will pass the
appropriate "-D" options to gcc to match the grade that you have selected.

> I guess there 's something wrong with my mercury installation.
> Compiling in the hlc grade doesn't work.
> 
> I get:
> 
> mmc --compile-to-c --grade hlc          queens > queens.err 2>&1
> mgnuc --grade hlc        --      -c queens.c -o queens.o
> queens.c:22: assoc_list.mih: No such file or directory
> queens.c:23: bool.mih: No such file or directory
...
> There isn't a directory for the hlc grade. Is this normal ?  Should I
> compile mercury again ?

The header files and libraries needed for the "hlc" grade aren't installed
by default.  You need to explicitly enable them, e.g. by configuring the
Mercury source distribution using "sh configure --enable-libgrades=hlc"
or "sh configure --enable-libgrades=hlc,hlc.gc,asm_fast", and then doing
"make install_libgrades".  (The last step normally gets done as part of
"make install", but if you've already done "make install" then doing
"make install_libgrades" will be faster than doing "make install" again).

> Why those -ffunctions-sections ?  From the gcc documentation I get :
> 
> "When you specify these options, the assembler and
>      linker will create larger object and executable files and will
>      also be slower."
> 
> This seems undiserable in an embedded environment so I'm not getting
> something.

The reason for using `-ffunction-sections' and `-fdata-sections' is that
`--gc-sections' won't work without them.

For an embedded environment, your program should be small enough that
the speed of assembling and linking your program and the sizes of the
object files are not important.

The size of the final executable is important, of course.  However, I
think using `--gc-sections' will probably reduce the executable size by
more than the increase from `-ffunction-sections' and `-fdata-sections',
because it will avoid large parts of the Mercury runtime being dragged
in by the linker.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list