Section 2.3. Build Environment

2.3. Build Environment

The assessment of the application continues by examining its build environment. When porting applications, it is important to see what tools are used to build the application. In most circumstances, you will find that the build tools used on other UNIX platforms will have similar counterparts on Linux. When examining the build environment, it is also necessary to take note of the build process. Some build processes are straightforward, and others are complex. Complex build processes add to porting difficulty and should be factored in when creating the schedules for the project.

2.3.1. gmake

The make development tool in Linux is the GNU make or gmake. As of this writing, the latest version of gmake is version 3.8, which this section is based on. The gmake home page is located at Note that gmake 3.8 is also available on Solaris, AIX, and HP-UX. Porting the build environment from other UNIX platforms to Linux means using gmake and making sure the makefiles to build the application are correctly ported to build all necessary application modules.

Because gmake conforms to the POSIX standard similarities between other UNIX operating platforms, makefiles and GNU makefiles abound. However, there are still some differences, which are covered in more detail in Chapters 4, 5 and 6.

2.3.2. GNU Binutils

The development tool chain for Linux is made up of other GNU tools known as the GNU binutils. The most commonly used tool in the GNU binutils is the GNU linker, ld, and the GNU assembler, as. The GNU ld

Running ld is usually the last step when compiling source code to produce a program executable. The ld command is responsible for combining object and archive files as well as for reconciling symbol references within the program executable. The GNU linker provides more diagnostic information than other linkers. Although other linkers simply abandon execution when an error is encountered, the GNU ld tries to continue execution whenever possible to further identify the cause of the error.

Although GNU ld has a lot of features to offer, including the use of linker scripts, most of the discussion around GNU ld focuses on the linker command-line options. A simple command-line option that shows how ld links an object file follows:

$ ld -o output /lib/crt0.o foo.o -lc 

This tells ld to produce a file called output as the result of linking the file /lib/crt0.o with foo.o and the library libc.a, which will come from the standard search directories.

GNU ld can also be invoked indirectly through a GNU compiler, such as gcc. When invoking indirectly, all command-line options to the linker must be prefixed by the -Wl option, as in the following example:

$ gcc -Wl,--startgroup foo.o bar.o -Wl,--endgroup 

GNU ld supports many options that are compatible with linker options from other operating systems such as Solaris, AIX, and HP-UX. In each of the main porting chapters for the different operating systems (Chapters 4, 5 and 6), GNU ld options are compared side by side so that the porting engineer has a reference of what linker flags to use when porting from other platforms.

For more information about the ld options, consult the latest GNU ld manual, available from

2.3.3. The GNU as

GNU as is a family of assemblers. If you use (or have used) the GNU assembler on one architecture, you should find a fairly similar environment when you use it on another architecture. Each version has much in common with the others, including object file formats, most assembler directives (often called pseudo-ops), and assembler syntax.

as is primarily intended to assemble the output of the GNU C compiler gcc for use by the linker ld. Nevertheless, GNU has tried to make as assemble correctly everything that other assemblers for the same machine would assemble. Any exceptions are documented explicitly in the Machine Dependent Features of the GNU as manual.[15] This does not mean that as always uses the same syntax as another assembler for the same architecture; for example, GNU is aware of several incompatible versions of the 680x0 assembly language syntax.


Unlike older assemblers, as is designed to assemble a source program in one pass of the source file. This has a subtle impact on the .org directive.

The GNU assembler can be configured to produce several alternative object file formats. For the most part, this does not affect how you write assembly language programs, but directives for debugging symbols are typically different in different file formats. For instance, on some Intel machines (80960, for example), as can be configured to produce either a COFF or an a.out format. On other machines, as can be configured to produce either a COFF or a b.out format. On HPPA systems, as can be configured to produce either SOM or ELF. The default format on Linux systems is ELF.

After the assembler invocation as, the command line may contain options and filenames. Options may appear in any order, and may be before, after, or between filenames. The order of filenames is significant.

A command-line argument that begins with a hyphen (-) is an option. Each option changes the behavior of as. No option changes the way another option works. An option is a - followed by one or more letters; the case of the letter is important. The following shows the syntax used by as:

as f o foo.o foo.s as --help 

The command-line argument of -- (two hyphens) by itself names the standard input file explicitly as one of the files for as to assemble. The following example shows the syntax for --:

as -- [files] 

Some options expect exactly one filename to follow them. The filename may either immediately follow the option's letter (compatible with older assemblers) or it may be the next command argument (GNU standard). These two command lines are equivalent:

as -o my-object-file.o mumble.s as -omy-object-file.o mumble.s 

For more details on each command-line option, refer to the GNU as documentation available from

Another useful feature of GCC is to invoke the GNU assembler from the gcc compiler. To do this, you use the following command:

gcc -c -g -O -Wa,-alh,-L file.c 

The assembler arguments must be separated from each other (and the -Wa) by commas. The preceding command causes a listing to be emitted to standard output with high-level messaging on an assembly source. Notice that two options (-alh and L) are passed on to as with one invocation of Wa. Also, the c option is needed so that the file is compiled without linking.

Other tools included in the binutils package are as follows:

  • addr2line. Translates program addresses into filenames and line numbers. Given an address and an executable, it uses the debugging information in the executable to figure out which filename and line number are associated with a given address.

  • ar. A utility program that creates, modifies, and extracts from archives. An archive is a single file holding a collection of other files in a structure that makes it possible to retrieve the original individual files (called members of the archive). An archive holds libraries of relocatable object files.

  • c++filt. A program that decodes or demangles low-level names into user-level names so that the linker can keep overloaded functions from clashing. Software developers use c++filt to demangle function names when debugging C++ applications.

  • nlmconv. Converts object code into an NLM (Netware Loadable Module). Not used in Linux.

  • nm. Lists the symbols from object files.

  • objcopy. A utility that copies the contents of an object file to another. It can write the destination object file in a format different from that of the source object file.

  • objdump. A utility that displays information about one or more object files. Information displayed by objdump is mostly useful to programmers who are working on the compilation tools, as opposed to programmers who just want their program to compile and work.

  • ranlib. Generates an index to the contents of an archive and stores it in the archive. The index lists each symbol defined by each member of an archive that is a relocatable object file.

  • readelf. Displays information from any ELF format object file. This program performs a similar function to objdump, but it can display more details.

  • size. A utility that lists the section[16] sizesand the total sizefor each of the object files' or archive files' objfile in its argument list. One line of output is generated for each object file or each module in an archive.

    [16] A section is a range of addresses within an object file that may contain data that is treated the same for some particular purpose. An object file written by as has at least three sectionsnamely, text, data, and bss.

  • strings. Prints the printable character sequences that are at least four characters long (or the number given with the options) and are followed by an unprintable character.

  • strip. Discards symbols from object files. Object files may include archives.

  • windres. A compiler for Windows resource files (not used in Linux).

For more detailed information about the GNU binutils, refer to

2.3.4. Integrated Development Environment

In some instances, some applications are built using integrated development environments (IDEs). For those who need to use an IDE for C, C++, or Java, an open-source IDE called Eclipse[17] is available. Eclipse is an open-extensible IDE that works well when developing applications. You can download it from Another open-source IDE for Java that works on Linux is NetBeans. You can download it from

[17] Eclipse plug-ins for C/C++ are also available.

UNIX to Linux Porting. A Comprehensive Reference
UNIX to Linux Porting: A Comprehensive Reference
ISBN: 0131871099
EAN: 2147483647
Year: 2004
Pages: 175 © 2008-2017.
If you may any questions please contact us: