Linux Programming Tools Unveiled


In the recent years, Linux, a public domain, freely available Unix variant has attracted the people very much. Today's complex production environments demands superior application performance. Linux is having extraordinary advantages such as: complete source code access, availability of exceptional optimization, testing tools. This book is to explore this facet of Linux.

First chapter starts with Linux success stories with emphasis on facilities and tools available in Linux for SW development. Second chapter explains about gcc (GNU) toolchain in detail. How to combine C and C++, C and Java, and C and Fortran also described in a lucid manner.

Third chapter deals with how command line arguments can be handled by C/C++ programs with getopt , argp library. Fourth chapter discusses about environment variables and their management. System limits are explored in fifth chapter with their implication of program performance. Sixth chapter explains about how assembly programming can be done under Linux. How to mix C and assembly is discussed in detail. Also, how system calls can be called from assembly, how modules can be developed in assembly are high-lighted. A bare boot (OS) program creation is discussed at the end.

How static and dynamic libraries are developed and commissioned in Linux is explained. How Libtool can be used for library development is discussed at the end. Eighth chapter deals with Lex/Yacc tools to be used in compiler development. Memory management, memory errors, Linux memory management, etc., are described in ninth chapter with illustrative examples. A popularly used tool for detecting memory errors, Electric Fence, is explained with concept oriented examples. A chapter on Valgrind is explains how memory can be checked for memory leaks, segment violations, analyze the cache performance in an illustrative manner. Tenth chapter describes memory mapping of files. It emphasizes the need for memory mapping; especially for large files and the impact on program’s performance.

Gnu debugger (gdb) is detailed in chapter 11. The chapters on gcov and gprof explains about profiling of a C program to improve its performance. Chapters on make, rcs, SW tools explains how they can be used for SW development in practice.

About the Editor

N. B. Venkateswarlu got his B. Tech from SV University, Tirupathy, M. Tech from IIT-Kanpur and Ph.D from BITS, Pilani on the topic of “Some Efficient Serial & Parallel Image Processing Algorithms”. He started his teaching career in the Computer Science Dept. of BITS Pilani, and was a Visiting Fellow at the University of Leeds, UK, during 1993-95. Currently, he is a senior Professor and Head, IT Department at GVP College of Engg, Madhurawada, Visakapatnam. He is also the founder Director of the RITCH Center at Visakhapatnam. He has published widely in International Journals and Conferences. He authored few more titles related to UNIX/Linux.

Linux Programming Tools Unveiled


Chapter 1 

Programmers View of Linux

1.1 A Glance At Success Stories Of  Linux
1.2 So What Makes Linux So Popular? 
1.3 Salient Features of Linux
1.4 Simple View of  An Operating System: Linux an Example
1.5 The x86 Linux boot process
1.6 Programming for Linux using GNU Tools
1.7 Conclusions

Chapter 2 

Compiling  C and C++ Programs Under Linux

2.1 Introduction to C Compiler
2.1.1 Understanding the compilation steps in C compiler
2.2 Detailed Analysis of Compilation Process
2.2.1 Running The Resulting Program
2.2.2 The C Preprocessor 
2.2.3 The Assembler 
2.2. 4 Creating Object Files but not linked files
2.2. 5 Creating Debug-Ready Code
2.2.6 Creating Optimized Code
2.2.7 Getting Extra Compiler Warnings
2.2. 8 Linking Libraries
2.2.9 Monitoring Compilation Times
2.2.10 Specifying Include Directories Along The Command Line
2.2.11 Size Command
2.2.12 The strip command
2.2.13 The as command
2.2.14 The led command
2.2.15 Creating Dynamic Executable and Static Executable
2.2.16 Indent Command
2.2.17 splint command
2.2.18 Use of cc1 command 
2.3 Functions with Variable number of arguments
2.4. Compiling A Multi-Source "C" Programs
2.5 How main() is executed on Linux
2.6 What Linux Does for Executable File
2.7. Compiling A Single-Source "C++" Program
2.8 Combining C and C++ programs
2.9 How to use C/C++ functions in Java
2.10 Using Fortran in C/C++
2.11 Conclusions

Chapter 3

Command Line Arguments

3.1 Introduction
3.2 Program Argument Syntax Conventions
3.3 Parsing Program Arguments 
3.3.1 Parsing program options using `getopt'
3.3.2 Parsing Long Options with `getopt_long'
3.3.3 Parsing Program Options with Argp
3.3.4 A Program Using Multiple Combined Argp Parsers
3.3.5 Use of POPT Library
3.3.6 CLIG Package
3.3.7 SuperGetOpt Library
3.3.8 argtable2 Library
3.4 Conclusions

Chapter 4

4. 1 Introduction to Environmental Variables
4.1.1 How can I read the whole environment?
4.1.2 How can I get/set an environment variable from a program?
4.2 Conclusions
Chapter  5
System Limits
5.1 Introduction
5.2 Setting user resource limits
5.2.1 Setting limits via the Shell
5.2.2 The system calls getrlimit() and setrlimit() 
5.2.3 Setting limits via PAM modules
5.3  Conclusions
Chapter 6
Assembly Programming Under Linux
6.1  Introduction
6.1.1 The advantages of Assembly
6.1.2 The disadvantages of Assembly
6.1.3 How to achieve efficient code
6.2 Writing Assembly Programs Under Linux
6.2.1The stack Operations 
6.2.2What is THE stack for Programmer?
6.2.3 Working with the stack
6.2.4 How gcc works with the stack
6.2.5 Parameter Passing and Value Return
6.2.6 How to Run system calls from Assembly
6.3 Mixing C and Assembly
6.3.1 GCC Inline Assembly
6.3.2 Extended inline assembly
6.4 How to Create Small Executable Files
6.4.1 Coding Methodology
6.5. How To Create Loadable Modules in Assembly
6.6 A Glimpse of Writing a Bootstrap program
6.7 Debugging C Program with  functions in Assembly
6.8 Conclusions

Chapter 7


7.1 Introduction
7.1.1 Shared (Dynamic) vs Static Libraries
7.1.2 Unix ANSI C Object Library & Header Organization
7.1.3 Linking An Object Library to an Application
7.2 How to Create a Static Object Library
7.2.1 Finding Out What's Inside an Object Library
7.2.2 Linking with Created Library
7.2.3 Updating an Object Library
7.2.4 Removing and Extracting Object Files from a Library
7.3 How to Create a Shared  Object Library
7.3.1 Using PIC For Building Shared Libraries
7.3.2 Using prelink and LD_BIND_NOW
7.3.3 More about negative side effects of text relocations in shared libraries
7.3.4 So, why not use -fPIC building as default for all applications?
7.3.5 Creating  shared library
7.3.6 soname
7.3.7 ldconfig
7.3.8 Loading shared libs at runtime
7.4 Dynamically Loaded (DL) Libraries
7.4.2 dlerror()
7.4.3 dlsym()
7.4.4 dlclose()
7.5 Unix C++ Class Library & Header Organization
7.5.1 C++ Class Libraries
7.6 Libtool: An Automatic Library Development Tools
7.6.1 Motivation for writing libtool 
7.6.2 Implementation issues 
7.6.3 Other implementations 
7.6.4 A postmortem analysis of other implementations 
7.6.5 Creating object files 
7.6.6 Linking libraries 
7.6.7 Linking executables 
7.7 The command prelink
7.8 Conclusions
Chapter 8
Lex & Yacc
8.1 Introduction
8.2 Lex Specification File
8.2.1 The Definitions Section
8.2.2 The Rules Section
8.2.3 The User Code Section
8.2.4 Patterns
8.2.5 How the input is matched
8.3 Yacc – A Parser generator
8.3.1 The Yacc Specification Rules
8.3.2 Use of Pseudovariables
8.4 Conclusions

Chapter 9

Unix Memory Management
9.1 Introduction
9.1.1 Memory Protection
9.2 Run-time Management Of Virtual Memory
9.2.1 Signals: SIGSEGV & SIGBUS
9.2.2 Load On Demand
9.2.3 Read-Only Memory
9.2.4 Shared Memory
9.2.5 Memory Managers
9.2.6 Memory Alignment
9.3 C Runtime Memory Management
9.3.1 Program Memory Segments
9.3.2 The Stack And Local Variables
9.3.3 Free()
9.4 Electric Fence Library For Testing Memory Errors
9.5 Conclusions

Chapter 10

Memory Mapped Files

10.1 Memory Mapping
10.2 Reading Large files with File Mapping
10.2.1 Local Copies (Read-Only Access Under Windows)
10.2.2 Unmapping the file
10.3 Conclusions

Chapter 11

GNU Debugger

11.1 Introduction
11.1.1 Bugs and Debugging
11.2 Debugging using gdb
11.2.1 Commands at gdb prompt
11.3 An Introduction to Kdbg
11.4 Debugging with DDD
11.5 Conclusions

Chapter 12

GCOV: A coverage Testing Tool

12.1 Introduction
12.2 gcov
12.3 Conclusions

Chapter 13


13.1 Introduction
13.2 Design Aims of a Profiler
13.3 Instrumentation Methods.
13.4 About GPROF system call.
13.6 Conclusions

Chapter 14

Valgrind and Alleyoop

14. 1 Introduction
14.2 Using and understanding the Valgrind core
14.2.1 Getting started
14.2.2 Reporting of errors
14.2.3 Suppressing errors
14.3 Command-line flags for the Valgrind core
14.3.1 Basic Options
14.3.2 Error-related options
14.3.3 Rare options
14.3.4 Setting default options
14.3.5 The Client Request mechanism
14.3.6 Support for POSIX Pthreads
14.3.7 Handling of signals
14.3.8 Limitations
14.3.9 Programs which are known not to work are:
14.4 Background Behind Valrind
14.4.1 The translation/instrumentation engine
14.4.2 Tracking the status of memory
14.5 MemCheck
14.5.1 An example run
14.5. 2 Kinds of bugs that memcheck can find
14.5.3 Explanation of error messages from Memcheck
14.5.4 Use of uninitialised values
14.5.6 Illegal frees
14.5.7 Passing system call parameters with inadequate read/write permissions
14.5.8 Overlapping source and destination blocks
14.5.9 Writing suppressions files
14.5.10 Details of Memcheck's checking machinery
14.5.11 Putting it all together
14.5.12 Memory leak detection
14.5.13 Client Requests
14.6 Cachegrind: a cache-miss profiler
14.6.1 Cache profiling
14.6.2 Overview
14.6.3 Cache simulation specifics
14.6.4 Profiling programs
14.6.5 Output file
14.6.6 Cachegrind options
14.6.7 Annotating assembler programs
14.6.8 Accuracy
14.7 Kinds of bugs that Addrcheck can find
14.8 Helgrind: a data-race detector
14.9 Massif: a heap profiler
14.10 Alleyoop: A front end for Valgrind
14.11 Conclusions

Chapter 15


15.1 Introduction
15.2 Syntax of Makefiles 
15.2.1 Options and parameters to make: 
15.2.2 Dependencies
15.2.3 Rules 
15.2.4 Options to be used with make command
15.3 Conclusions

Chapter 16
Revision Control System
16.1 Introduction
16.1.1 Creation of a file under RCS management :
16.1.2 ci-check in command :
16.1.3 co-check out COMMAND
16.2 Conclusions
Chapter 17
SW Distribution Tools
17. 1 tar Command
17.2 Redhat Packet Manager(RPM)
17.3 PAX
17.4 SW Patching
17.5 Conclusions