xref: /openbsd/usr.sbin/crunchgen/crunchgen.8 (revision 264ca280)
1.\"	$OpenBSD: crunchgen.8,v 1.8 2014/11/15 14:41:03 bentley Exp $
2.\"
3.\"
4.\" Copyright (c) 1994 University of Maryland
5.\" All Rights Reserved.
6.\"
7.\" Permission to use, copy, modify, distribute, and sell this software and its
8.\" documentation for any purpose is hereby granted without fee, provided that
9.\" the above copyright notice appear in all copies and that both that
10.\" copyright notice and this permission notice appear in supporting
11.\" documentation, and that the name of U.M. not be used in advertising or
12.\" publicity pertaining to distribution of the software without specific,
13.\" written prior permission.  U.M. makes no representations about the
14.\" suitability of this software for any purpose.  It is provided "as is"
15.\" without express or implied warranty.
16.\"
17.\" U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
19.\" BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
21.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
22.\" IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23.\"
24.\" Author: James da Silva, Systems Design and Analysis Group
25.\"			   Computer Science Department
26.\"			   University of Maryland at College Park
27.\"
28.Dd $Mdocdate: November 15 2014 $
29.Dt CRUNCHGEN 8
30.Os
31.Sh NAME
32.Nm crunchgen
33.Nd generates build environment for a crunched binary
34.Sh SYNOPSIS
35.Nm crunchgen
36.Bk -words
37.Op Fl EfMq
38.Op Fl c Ar c-file-name
39.Op Fl D Ar src-root
40.Op Fl e Ar exec-file-name
41.Op Fl L Ar lib-dir
42.Op Fl m Ar makefile-name
43.Op Fl O Ar objdir-name
44.Ar conf-file
45.Ek
46.Nm crunchgen
47.Fl h
48.Op Fl f Ar keep-list-file
49.Op Fl k Ar keep-symbol
50.Ar object-file ...
51.Sh DESCRIPTION
52A crunched binary is a program made up of many other programs linked
53together into a single executable.
54The crunched binary main() function determines which component program
55to run by the contents of argv[0].
56The main reason to crunch programs together is for fitting as many programs
57as possible onto an installation or system recovery floppy.
58.Pp
59.Nm
60reads in the specifications in
61.Ar conf-file
62for a crunched binary, and generates a Makefile and accompanying
63top-level C source file that when built create the crunched executable
64file from the component programs.
65For each component program,
66.Nm
67can optionally attempt to determine the object (.o) files that make up
68the program from its source directory Makefile.
69This information is cached in a file named
70.Pa <conf-name>.cache
71between runs.
72.Pp
73.Nm
74is later run again with the
75.Fl h
76flag to eliminate link-time conflicts between the component programs by
77hiding all unnecessary symbols.
78Some symbols may be left visible via the
79.Fl k Ar keep-symbol
80and
81.Fl f Ar keep-list-file
82options.
83The
84.Ar keep-list-file
85must contain a list of symbols to keep visible, one symbol per line.
86Note that the C compiler prepends an underscore in front of
87symbols, so to keep the C function
88.Dq foo
89visible, the option
90.Dq -k _foo
91must be used.
92.Pp
93After
94.Nm
95is run, the crunched binary can be built by running
96.Dq make -f <conf-name>.mk .
97The component programs' object files must already be built.
98An
99.Dq objs
100target, included in the output makefile,
101will run make in each component program's source dir to build the object
102files for the user.
103This is not done automatically since in release engineering circumstances
104it is generally not desirable to be modifying objects in other directories.
105.Pp
106The options are as follows:
107.Bl -tag -width indent
108.It Fl c Ar c-file-name
109Set output C file name to
110.Ar c-file-name .
111The default name is
112.Dq Ao conf-name Ac Ns \&.c .
113.It Fl D Ar src-root
114Assume that relative source directory specifications begin with
115.Ar src-root .
116.It Fl E
117Don't prepend stub names with an underscore.
118Used for architectures that don't have underscore prepended to symbol names,
119such as ELF architectures.
120.It Fl e Ar exec-file-name
121Set crunched binary executable file name to
122.Ar exec-file-name .
123The default name is
124.Dq Aq conf-name .
125.It Fl f
126Flush cache.
127Forces the recalculation of cached parameters.
128.It Fl h
129Hide all unnecessary symbols.
130Note that this is done on some ELF architectures by marking the symbol
131local, while the
132.Fl M
133option causes it to mangle the symbol name to hide the symbol.
134It is therefore not advisable to try to run
135.Xr nm 1
136on a crunched object file.
137This is due to the nature of the ELF symbol table
138and how some architectures use the symbol attributes for their GOT build.
139.It Fl L Ar lib-dir
140Try to obtain libraries from
141.Ar lib-dir .
142.It Fl M
143On ELF architectures mangle the symbol instead of marking it global;
144necessary for some architectures due to GOT usage.
145.It Fl m Ar makefile-name
146Set output Makefile name to
147.Ar makefile-name .
148The default name is
149.Dq Ao conf-name Ac Ns \&.mk .
150.It Fl O Ar objdir-name
151Specify an object directory to use.
152It defaults to
153.Dq obj ,
154though for cross building purposes it can be used to specify
155obj.${HOST}.${MACHINE}.
156Normally used with the make variable ${MAKEOBJDIR}.
157.It Fl q
158Quiet operation.
159Status messages are suppressed.
160.El
161.Sh CRUNCHGEN CONFIGURATION FILE COMMANDS
162.Nm
163reads specifications from the
164.Ar conf-file
165that describe the components of the crunched binary.
166In its simplest use, the component program names are merely listed
167along with the top-level source directories in which their sources
168can be found.
169.Nm
170then calculates (via the source makefiles) and caches the
171list of object files and their locations.
172For more specialized situations, the user can specify by hand
173all the parameters that
174.Nm
175needs.
176.Pp
177The
178.Ar conf-file
179commands are as follows:
180.Bl -tag -width indent
181.It srcdirs Ar dirname ...
182A list of source trees in which the source directories of the
183component programs can be found.
184These dirs are searched using the
185.Bx
186.Dq <source-dir>/<progname>/
187convention.
188Multiple srcdirs lines can be specified.
189The directories are searched in the order they are given.
190.It libdirs Ar dirname
191A list of source trees in which the source directories for supplementary
192libraries can be found.
193.It progs Ar progname ...
194A list of programs that make up the crunched binary.
195Multiple progs lines can be specified.
196.It libs Ar libspec ...
197A list of library specifications to be included in the crunched binary link.
198Multiple libs lines can be specified.
199.It ln Ar progname linkname
200Causes the crunched binary to invoke
201.Ar progname
202whenever
203.Ar linkname
204appears in argv[0].
205This allows programs that change their behavior when
206run under different names to operate correctly.
207.El
208.Pp
209To handle specialized situations, such as when the source is not
210available or not built via a conventional Makefile, the following
211.Ic special
212commands can be used to set
213.Nm
214parameters for a component program.
215.Bl -tag -width indent
216.It special Ar progname No srcdir Ar pathname
217Set the source directory for
218.Ar progname .
219This is normally calculated by searching the specified srcdirs
220for a directory named
221.Ar progname .
222.It special Ar progname No objdir Ar pathname
223Set the obj directory for
224.Ar progname .
225This is normally calculated by looking for a directory named
226.Dq obj
227under the
228.Ar srcdir ,
229and if that is not found, the
230.Ar srcdir
231itself becomes the objdir.
232.It special Ar progname No objs Ar object-file-name ...
233Set the list of object files for program
234.Ar progname .
235This is normally calculated by constructing a temporary makefile that includes
236.Dq srcdir/Makefile
237and outputs the value of $(OBJS).
238.It special Ar progname No objpaths Ar full-pathname-to-object-file ...
239Sets the pathnames of the object files for program
240.Ar progname .
241This is normally calculated by prepending the objdir
242pathname to each file in the objs list.
243.El
244.Pp
245Only the objpaths parameter is actually needed by
246.Nm crunchgen ,
247but it is calculated from objdir and objs,
248which are in turn calculated from srcdir,
249so it is sometimes convenient to specify the earlier parameters and let
250.Nm
251calculate forward from there if it can.
252.Pp
253The makefile produced by
254.Nm
255contains an optional
256.Ar objs
257target that will build the object files for each component program by
258running make inside that program's source directory.
259For this to work the srcdir and objs parameters must also be valid.
260If they are not valid for a particular program, that program is skipped in the
261.Ar objs
262target.
263.Sh EXAMPLES
264Here is an example
265.Nm
266input conf file, named
267.Pa kcopy.conf :
268.Bd -literal -offset indent
269srcdirs /usr/src/bin /usr/src/sbin
270
271progs test cp echo sh fsck halt init mount umount myinstall
272ln test [       # test can be invoked via [
273ln sh -sh       # init invokes the shell with "-sh" in argv[0]
274
275special myprog objpaths /homes/leroy/src/myinstall.o # no sources
276
277libs -lutil -lcrypt
278.Ed
279.Pp
280This conf file specifies a small crunched binary consisting of some
281basic system utilities plus a home-grown install program
282.Dq myinstall ,
283for which no source directory is specified, but its object file is
284specified directly with the
285.Ic special
286line.
287.Pp
288The crunched binary
289.Dq kcopy
290can be built as follows:
291.Bd -literal -offset indent
292% crunchgen -m Makefile kcopy.conf    # gen Makefile and kcopy.c
293% make objs		# build the component programs' .o files
294% make			# build the crunched binary kcopy
295% kcopy sh		# test that this invokes a sh shell
296$			# it works!
297.Ed
298.Pp
299At this point the binary
300.Dq kcopy
301can be copied onto an install floppy
302and hard-linked to the names of the component programs.
303.Sh AUTHORS
304.Nm
305was written by
306.An James da Silva Aq Mt jds@cs.umd.edu .
307.Pp
308Copyright (c) 1994 University of Maryland.  All Rights Reserved.
309.Sh CAVEATS
310While
311.Nm
312takes care to eliminate link conflicts between the component programs
313of a crunched binary, conflicts are still possible between the
314libraries that are linked in.
315Some shuffling in the order of libraries may be required,
316and in some rare cases two libraries may
317have an unresolvable conflict and thus cannot be crunched together.
318.Pp
319Some versions of the
320.Bx
321build environment do not by default build the
322intermediate object file for single-source file programs.
323The
324.Dq make objs
325target must then be used to get those object files built,
326or some other arrangements made.
327