[net.micro.amiga] Question about Alink

wen_2@h-sc2.UUCP (A. Wen) (05/12/86)

*** I refuse to believe in the lin

Is it possible for those of us outside of West Chester and Los Gatos to use
Alink to produce short executables?  For example, is it possible to link a
"hello, world" to a less-than-10K executable, and how is this done?  I know
it IS done, (look in c: for examples) but can I do it, too?
 
			A. Wen
			wen@harvunxu.BITNET
			wen%h-sc4@harvard.HARVARD.EDU
	

dillon@PAVEPAWS.BERKELEY.EDU.UUCP (05/15/86)

	The problem isn't with Alink....  My guess is Lattice didn't put
together their library correctly.

NOTE: ********* When I talk about libraries in this message, I'm talking about
LINK libraries.... the things you specify in  ALINK, NOT run-time libraries.

* What is a Library

	A Library is made up of any number of object files.  If your source file
makes a call to a function in a library, the entire object file that function
resides in is then picked out of the library and included.  Here's an example:

**************
source file:
	open(..)
	write(...)

library:  (This is ONE library)
	-------- object module 1 -------
	open  
	read
	write
	close
	-------- object module 2 -------
	printf
	sprintf
	-------- object module 3 -------
	fopen
	 . .   etc.....
**************
	Now, you source program calls open() and write(), So object module 1
will be linked in as part of the executable (the ENTIRE object module 1).
Additionaly, if a routine in an included object module makes a call to another
object module, the other object module is included also.  So if open() made
a call to  printf() (for some strange reason), then object module 2 would also
be included, even though you didn't call  printf() from your source program.

	The same goes to cross-library calls.  If open() made a call to, say
Lock(), which resided in a different (but also specified in ALINK) library, 
then the particular object module Lock() exists in would also be linked into
the executable.

WHERE ALINK WENT WRONG

	Amiga libraries are nice in that you simply have to pile object files
together, but this method of doing things leaves much to be desired.  For one,
nowhere is there a sorted names list.  Alink must seek around all over the 
library to find named routines and object modules.  It seems to me that it 
would have been very simple to modify the library format to make Alink go 
faster.  How often do you make libraries?  Even if you do create libraries
frequently, the command to put them together in a better format would take
no longer than the appending one object file on another anyway. 

	Additionaly, Alink takes too much memory.... it really is a hog. On
my 512K Amiga, I can barely have my modem program running while doing an
Alink.

	Alink is slow.  It shouldn't be.  I see no reason for it to be slow.
A compiler, yes, An assembler, maybe, but a linker? no way.

WHERE LATTICE WENT WRONG

	It's Lattice's fault that the executable's are so big.  I don't know
who the idiot was over there allowed it to be released in such a state.  It's
probably no single person's fault, but it seems just plain STUPID.... I doubt
it would take more than 40 hours programming to fix the problem.  There are
two possibilities that I can think of:

	1) Lattice chunked too many functions in it's object files before
	   putting them together to form the library

	2) Lattice has cross links from one object file to another causing
	   massive amounts of inclusion at link time of routines which 
	   would otherwise not be used.


						-Matt

hr@uicsl.UUCP (05/15/86)

RE:
	"Is it possible for those of us outside of West Chester and
	Los Gatos to use Alink to produce short executables?"

Yes. Search your Lattice C documentation. Basically, you should not
use any "Level 1 I/O routines". I remove as many Lattice routines
as I can, turn off stack checking, and adjust the Alink args.

Thus,

main()
{
	printf("Hello World\n");
	exit(0);
}

would become:

Putstr(str)
char	*str;
{
	Write(Output(),str,strlen(str));
}

main()
{
	Putstr("Hello World\n");	/* I may write a Printf someday */
	Exit(0);
}

LC2 would be given the -v switch.
Alink would get Astartup.obj instead of Lstartup.obj.
The library order is reversed (Amiga.lib+Lattice.lib).

The result should be under 5KB. Check the manuals for more information
and corrections to the above. (Unfortunately, some of the information
may be in addenda not included with the manual).
----

	harold ravlin		{ihnp4,pur-ee}!uiucdcs!uicsl!hr

higgin@cbmvax.cbm.UUCP (Paul Higginbottom) (05/15/86)

In article <928@h-sc2.UUCP> wen_2@h-sc2.UUCP writes:
>
>Is it possible for those of us outside of West Chester and Los Gatos to use
>Alink to produce short executables?  For example, is it possible to link a
>"hello, world" to a less-than-10K executable, and how is this done?  I know
>it IS done, (look in c: for examples) but can I do it, too?
> 
>			A. Wen
>			wen@harvunxu.BITNET
>			wen%h-sc4@harvard.HARVARD.EDU
>	

----

The programs written by Amiga were not linked using ALINK, nor were they
compiled under Lattice.  Some are BCPL programs, and others are compiled
on Sun computers under another compiler.

I would guess that the current state of the libraries and the Lattice compiler
make it impossible to make "hello" in under 10K.

I'm not sure if using "puts()" instead of printf() might help, if such a
function exists under Lattice.

As I said before, hello.c compiles and links to 4720 bytes under Aztec C.

To re-iterate on size, a friend re-wrote the echo command in assembler, and
it was less than 30 bytes!!!!

	Regards,
		Paul Higginbottom

Disclaimer: I do not work for Commodore, and my opinions are at least my own.

bruceb@amiga.UUCP (05/15/86)

In article <928@h-sc2.UUCP> wen_2@h-sc2.UUCP (A. Wen) writes:
>Is it possible for those of us outside of West Chester and Los Gatos to use
>Alink to produce short executables?  I know
>it IS done, (look in c: for examples) but can I do it, too?

Some (lots) of the C: programs were written in BCPL.  You might
try Manx or the next rev of Lattice.  The lattice people are
working on this "problem" now.  Then there's allways 68000 assemble :-)!
--Bruce Barrett

stan@amiga.UUCP (05/17/86)

In article <928@h-sc2.UUCP> wen_2@h-sc2.UUCP (A. Wen) writes:
>
>Is it possible for those of us outside of West Chester and Los Gatos to use
>Alink to produce short executables?  For example, is it possible to link a
>"hello, world" to a less-than-10K executable, and how is this done?  I know
>it IS done, (look in c: for examples) but can I do it, too?
> 

	The problem is that you are linking in the Lattice C run time
	library.  In order to avoid this (and thus have a much smaller
	hello world) you need to do two things.  First link with Astartup
	(vs. LStartup) and second remove lc.lib from the list of libraries
	that you link with.

	While this will achieve the smaller program size, there are a few
	caveats you be be aware of.  1)  Most of the "standard" C functions
	are not available.  2)  Printf is a kludge.  Be sure to always use
	the format %lx or %ld or %l...  3)  Use this at your own risk, it
	is the interface that was around before Lattice C and hasn't beeen
	touched in ages.

	Hope this helps.

bruceb@amiga.UUCP (Bruce Barrett) (05/19/86)

In article <247@cbmvax.cbmvax.cbm.UUCP> higgin@cbmvax.UUCP (Paul
 Higginbottom) writes:
>In article <928@h-sc2.UUCP> wen_2@h-sc2.UUCP writes:
>
>The programs written by Amiga were not linked using ALINK, nor were they
>compiled under Lattice.  Some are BCPL programs, and others are compiled
>on Sun computers under another compiler.

Not exactly correct Paul.  Alink is the *only* linker we use.  We use it
for BCPL, C and assembly programs.  What we do not generally use is the
Lattice C libraries.  For (most of) the CLI commands "we" use the BCPL
libraries.  If you, the developer can get away with undocumented and 
limited functions (as we can) you too can use the amiga.lib library for
things like printf().  To do this:
	Link using "alink astartup.obj+foo.o LIB amiga.lib+lc.lib"
(you still need lc.lib for things the Lattice compiler relies on.)
	Compile printf as: printf("%ld %ls %lx %;f\n", int, char, ...);
Note the "l" is necessary.
Hope this helps!!
--Bruce Barrett

randy@cbmvax.UUCP (05/20/86)

In article <928@h-sc2.UUCP> wen_2@h-sc2.UUCP writes:
>Is it possible for those of us outside of West Chester and Los Gatos to use
>Alink to produce short executables?  For example, is it possible to link a
>"hello, world" to a less-than-10K executable, and how is this done?  I know
>it IS done, (look in c: for examples) but can I do it, too?
> 

	The problem with "huge" executables is a result of using
the Lattice library, LC.LIB. These are not the most efficiently
coded routines by any means.

	One possible solution is to not use LC.LIB and instead
rely on Amiga.lib to provide the needed functionality. Amiga.lib
contains a partial implementation of the typical 'C' functions
e.g. printf. But -- these are not complete implementations!!
And, there is no documentation for these functions. So, the only
way to know for sure is to try it. For the most part,
unless you are trying to write , or port, a 'portable' program
you should have no trouble. Remember to use Astartup.obj instead
of Lstartup.obj.

   	Following this advice, the example program "hello.c"
can be reduced to about 4k bytes (I think). It is the Lattice
implementation of printf that is a real killer!


-- 
     + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 
Randy Weiner -- Commodore Business Machines <<Amiga Technical Support>>
		uucp: {ihnp4|seismo|caip}!cbmvax!randy
		arpa: cbmvax!randy@seismo
		(or)  randy@cbmvax.UUCP@{seismo | harvard}
		TEL:  215-431-9180

daveh@cbmvax.cbm.UUCP (Dave Haynie) (05/20/86)

In article <928@h-sc2.UUCP> wen_2@h-sc2.UUCP writes:
>*** I refuse to believe in the lin
>
>Is it possible for those of us outside of West Chester and Los Gatos to use
>Alink to produce short executables?  For example, is it possible to link a
>"hello, world" to a less-than-10K executable, and how is this done?  I know
>it IS done, (look in c: for examples) but can I do it, too?

First of all, the programs in C: were compiled under Greenhill's C, not
Lattice.  The reason Lattice programs get so big is that the Lattice object
modules in the Lattice linker library contain too many functions each.  
ALINK includes ALL of the code in any object module referenced, even if
only one function from within those objects is used.  If Lattice were to
distribute a library in which each function (or very small group of
closely-related functions) were in a separate object module, your code
would shrink quite a bit.  Why this isn't done, who knows?  You'd think
that Lattice is feeling some of the heat from Aztec's C, which doesn't have
this problem.

-- 

Dave Haynie    {caip,inhp4,allegra,seismo}!cbmvax!daveh
               "There, beyond the bounds of your weak imagination
                Lie the noble towers of my city, bright and gold"
								-Genesis

daveh@cbmvax.cbm.UUCP (Dave Haynie) (05/20/86)

In article <247@cbmvax.cbmvax.cbm.UUCP> higgin@cbmvax.UUCP (Paul Higginbottom) writes:
>
>As I said before, hello.c compiles and links to 4720 bytes under Aztec C.
>
>To re-iterate on size, a friend re-wrote the echo command in assembler, and
>it was less than 30 bytes!!!!
>
>	Regards,
>		Paul Higginbottom
>
>Disclaimer: I do not work for Commodore (just steal their VAX time), and my 
>opinions are at least my own.

But of course, there's no practical difference on the Amiga between a 30
byte program and a 488 byte program.  Every file must take up at least two
blocks, one for the file header and one for the first data block.  That's
two 512 byte blocks.  Each data block has an overhead of six (if I remember
correctly) longwords for link pointers, back pointers, sequence numbers,
checksum, etc.  



-- 

Dave Haynie    {caip,inhp4,allegra,seismo}!cbmvax!daveh
               "There, beyond the bounds of your weak imagination
                Lie the noble towers of my city, bright and gold"
								-Genesis

jimm@amiga.UUCP (05/22/86)

In article <263@cbmvax.cbmvax.cbm.UUCP> daveh@cbmvax.UUCP (Dave Haynie) writes:
>
>First of all, the programs in C: were compiled under Greenhill's C, not
>Lattice.  The reason Lattice programs get so big is that the Lattice object
>modules in the Lattice linker library contain too many functions each.  

>ALINK includes ALL of the code in any object module referenced, even if
>only one function from within those objects is used.

Yes, this is how alink works.  On the suns we use Greenhills, alright,
but we use the same alink  and the same amiga.lib (more or less) that one
finds on a "lattice" development disk.

The extra code comes from the lattice lib and it's start-up module.
It has appeared in this newsgroup: using the different levels of 
lattice i/o functions brings in different amounts of code from lc.lib.
The startup code even knows how to get a window open for standard output,
when a program is opened from the workbench.

peter@baylor.UUCP (Peter da Silva) (05/24/86)

> In article <928@h-sc2.UUCP> wen_2@h-sc2.UUCP writes:
> >
> >Is it possible for those of us outside of West Chester and Los Gatos to use
> >Alink to produce short executables?  For example, is it possible to link a
> >"hello, world" to a less-than-10K executable, and how is this done?  I know
> >it IS done, (look in c: for examples) but can I do it, too?

Don't call in stdio. Try this:

_main()
{
	write(1, "Hello world\n", 12);
}

Or if you're not into counting:

_main()
{
	writes(1, "Hello world\n");
	_exit();
}

writes(fd, s)
int fd;
char *s;
{
	return write(fd, s, strlen(s));
}

strlen(s)
char *s;
{
	int len = 0;

	while(*s) {
		s++;
		len++;
	}
	return len;
}

Or you can even use the AmigaDos calls instead of the UNIX-style calls
and get it down near the 30 byte mark.
-- 
-- Peter da Silva
-- UUCP: ...!shell!{baylor,graffiti}!peter; MCI: PDASILVA; CIS: 70216,1076