Creating functions in data space

Steve Law law at petsd.UUCP
Tue Mar 11 04:26:14 AEST 1986


> In response to George Tomasevich:
> 
I had missed that one.

> This seems to me to be very machine dependent, even compiler
> dependent. I'm sure that the compiler, in any event, would spit all
> kinds of warnings at you. Perhaps a way around it would be to gain
> access somehow to the memory management register, have a function that
> flips a bit just before calling the data code, and cleans up afterwards.
> Perhaps the problem is that C allows you to have identically named
> functions and variables, but you could get around that as well.
> 
UNIX System V link editor (ld) allows one to put functions in the .data
section of a COFF file.  All you need to do is to create a ld command
file (also called ifile).  For example, the following ifile:

     SECTIONS {
     	 .data: {
     		file1.o (.text)   /* file1.c, file2.c file3.c contain */
     	        file2.o (.text)   /* the functions text that to be    */
     	        file3.o (.text)   /* placed in the .data section of   */
     	        ...               /* the final a.out                  */
     	        }
     	 }

and the following command lines:

     cc -c file1.c file2.c file3.c
     cc -N otherfiles.c ifile

will create an a.out which will have all the functions of file[123].c in
the .data section instead of .text section.  One can also use ifile(s) to
do the following:

     - place data in .text
     - create dummy sections (e.g., store history info)
     - create holes within sections
     - align sections
     - merge sections
     - subsystem linking

and many others.  It is a very powerful tool, but some of its features
are not well documented!!!

				Steve Law

--*-------*-------*-------*-------*-------*-------*--
Name:       I. S. Law (Steve)
UUCP:       ihnp4!vax135!petsd!law
ARPA:	    vax135!petsd!law at BERKELEY
US Mail:    MS 314B; Concurrent Computer Corp.
            106 Apple St; Tinton Falls, NJ 07724
Phone:      (201) 758-7280
--*-------*-------*-------*-------*-------*-------*--



More information about the Comp.lang.c mailing list