Table Of ContentThe Definitive Guide
to GCC
KURT WALL AND WILLIAM VON HAGEN
APress Media, LLC
The Definitive Guide to GCC
Copyright ©2004 by Kurt Wall and William von Hagen
Originally published by Apress in 2004
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.
ISBN 978-1-59059-109-3 ISBN 978-1-4302-0704-7 (eBook)
DOI 10.1007/978-1-4302-0704-7
Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement of the trademark.
Technical Reviewer: Gene Sally
Editorial Board: Steve Anglin, Dan Appleman, Gary Cornell, James Cox, Tony Davis, John
Franklin, Chris Mills, Steven Rycroft, Dominic Shakeshaft, Julian Skinner, Martin Streicher, Jim
Sumser, Karen Watterson, Gavin Wray, John Zukowski
Assistant Publisher: Grace Wong
Project Manager: Sofia Marchant
Copy Editor: Ami Knox
Production Manager: Kari Brooks
Production Editor: Janet Vaii
Proofreader: Elizabeth Berry
Compositor and Artist: Kinetic Publishing Services, llC
Indexer: Valerie Perry
Cover Designer: Kurt Krames
Manufacturing Manager: Tom Debolski
The information in this book is distributed on an "as is" hasis, without warranty. Although every
precaution bas been taken in the preparation of this work, neither the author(s) nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.
To my teachers, Miss Rhodes, Mrs. Walker, Mrs. Burnette, Miss Nearhoof,
Mrs. Conley, Mrs. Lee, Mr. Bundy, and Mrs. Dunn; and to the schools in which
they worked ·their magic: Randolph, Madison Pike Elementary School,
Westlawn Junior High School, and S.R. Butler High School.
-Kurt Wall
For Dorothy Fisher-! couldn't do it without you!
And for Becky Gable-thanks for all your help with the schematics
over the years!
-Bill von Hagen
Contents at a Glance
About the Authors ................................................. xi
About the Technical Reviewer .................................... xii
Acknowledgments ................................................... xiii
Introducing GCC and The Definitive Guide to GCC ............... xv
Chapter 1 Building GCC ......................................... 1
Chapter 2 Installing GCC on DOS and Windows Platforms .... 39
Chapter 3 Basic GCC Usage .................................... 59
Chapter 4 Advanced GCC Usage ................................ 101
Chapter 5 Optimizing Code with GCC ........................ . 135
Chapter 6 Performing Code Analysis with GCC ............... 147
Chapter 7 Using Autoconf and Automake ...................... 187
Chapter 8 Using Libtool ...................................... 221
Chapter 9 Troubleshooting GCC ............................... 245
Chapter 10 Using GCC's Online Help .......................... 265
Chapter 11 GCC Command-Line Options ......................... 283
Chapter 12 Additional GCC Resources ......................... 347
Appendix A Building and Installing Glibc .................... 363
Appendix B Machine and Processor-Specific
Options for GCC ................................... 403
Index .............................................................. 497
v
Contents
About the Authors ..............................................
xi
About the Technical Reviewer ...............................
xii
Acknowledgments ................................................
xiii
Introducing GCC and The Definitive Guide to GCC ..... xv
Chapter 1 Building GCC ....................................... 1
Why Build GCC from Source? ........................................ 1
What Is New in GCC 3? ............................................ 24
Chapter 2 Installing GCC on DOS and Windows
Platforms ...........................................
39
Installing Cygwin ................................................. 39
Installing DJGPP .................................................. 47
Chapter 3 Basic GCC Usage .................................
59
General Options ................................................... 59
Controlling GCC' s Output ......................................... 62
Compiling C Dialects .............................................. 69
Using GCC with C++ ................................................ 74
Controlling the Preprocessor ..................................... 77
Modifying the Directory Search Path ............................ 78
Controlling the linker ........................................... 82
Passing Options to the Assembler ................................ 86
Enabling and Disabling Warning Messages ........................ 86
Adding Debugging Information ..................................... 94
vii
Contents
Chapter 4 Advanced GCC Usage ............................ 101
Customizing GCC Using Environment Variables .................. 101
Customizing GCC with Spec Files and Spec Strings ............ 103
GCC' s C and Extensions .......................................... 108
Chapter 5 Optimizing Code with GCC .................... 135
A Whirlwind Tour of Compiler Optimization Theory ............ 135
Processor-Independent Optimizations ............................ 138
Processor-Specific Optimizations ............................... 145
Chapter 6 Performing Code Analysis with GCC. ....... 147
Test Coverage Using GCC and gcov ............................... 148
Chapter 1 Using Autoconf and Automake ................ 187
Unix Software Configuration, Autoconf, and Automake ......... 187
Installing and Configuring Autoconf and Automake ............. 191
Configuring Software with Autoconf and Automake .............. 200
Running configure Scripts ....................................... 218
Chapter 8 Using Libtool. .................................. 221
Introduction to Libraries ....................................... 221
What Is Libtool? ................................................. 226
Downloading and Installing Libtool ............................. 228
Using Libtool ..................................................... 232
Troubleshooting Libtool Problems ........ ....................... 243
Getting More Information About Libtool ........................ 244
Chapter 9 Troubleshooting GCC. .......................... 245
Coping with Known Bugs and Misfeatures ........................ 245
Resolving Common Problems ....................................... 247
Resolving Build and Installation Problems ..................... 262
viii
Contents
Chapter 10 Using GCC's Online Help ...................... 265
What Is GNU Info? ................................................ 265
Getting Started, or Instructions for the Impatient .......... 267
The Beginner's Guide to Using GNU Info ........................ 269
Stupid Info Tricks ............................................... 279
Chapter 11 GCC Command-Line Options .................... 283
Alphabetical List of GCC Options ............................... 284
Alphabetical List of GCC Assembler Options ................... 336
Alphabetical List of GCC Linker Options ....................... 336
Alphabetical List of GCC Preprocessor Options ................ 338
GCC Option Reference ............................................. 344
Chapter 12 Additional GCC Resources .................... 347
Usenet Resources for GCC ........................................ 347
Mailing Lists for GCC ........................................... 352
World Wide Web Resources for GCC ............................... 358
Publications About GCC and Related Topics ..................... 359
Appendix A Building and Installing Glibc .............
363
What Is in Glibc? ................................................ 363
Alternatives to Glibc ........................................... 365
Why Build Glibc from Source? ................................... 367
Previewing the Build Process ................................... 374
Recommended Tools for Building Glibc .......................... 376
Downloading and Installing Source Code ........................ 379
Configuring the Source Code ..................................... 385
Compiling Glibc .................................................. 388
Testing the Build ................................................ 390
Installing Glibc ................................................. 390
Getting More Information About Glibc .......................... 400
Appendix B Machine and Processor-Specific
Options for GCC ................................
403
Alpha Options ..................................................... 405
Alpha/VMS Options ................................................ 411
ix
Contents
AMD x86-64 Options ............................................... 412
AMD29K Options ................................................... 413
ARC Options ....................................................... 415
ARM Options ....................................................... 416
AVR Options ....................................................... 422
Clipper Options .................................................. 424
Convex Options ................................................... 424
CRIS Options ...................................................... 425
D30V Options ...................................................... 428
HS/300 Options ................................................... 429
HP/PA (PAIRISC) Options ......................................... 430
i386 and AMD x86-64 Options .................................... 432
IA-64 Options ..................................................... 438
Intel 960 Options ................................................ 440
M32R Options ...................................................... 442
M68oxo Options ................................................... 443
M68hc1x Options .................................................. 447
M88K Options ...................................................... 447
MCore Options ..................................................... 451
MIPS Options ...................................................... 452
MMIX Options ...................................................... 460
MN10200 Options .................................................. 461
MN10300 Options .................................................. 462
NS32K Options ..................................................... 462
PDP-11 Options ................................................... 464
PowerPC (PPC) Options ........................................... 466
RS/6000 Options .................................................. 478
RT Options ........................................................ 478
S/390 and zSeries Options ....................................... 479
SH Options ........................................................ 480
SPARC Options ..................................................... 482
System V Options ................................................. 487
TMS320(3x/C4x Options ............................................ 488
V850 Options ...................................................... 491
VAX Options ....................................................... 492
Xstormy16 Options ................................................ 492
Xtensa Options ................................................... 492
Index ............................................................. 497
X
About the Authors
Kurt Wall first touched a computer in 1980 when he learned
FORTRAN on an IBM mainframe of forgotten vintage; happily,
computer technology has improved considerably since then.
A professional technical writer by trade and a historian by
training, Kurt has a diverse working history. These days, Kurt
works for TimeSys Corporation in Pittsburgh, Pennsylvania.
His primary responsibility is managing TimeSys' Content
Group, or as it is known in-house, the artists' colony. In addi
tion to directing production of the technical and end-user documentation for
TimeSys' embedded Unux operating system and development tools, he also
writes much of the documentation for TimeSys' embedded Unux products.
Kurt has written all or parts of 15 books on Unux system administration and
programming topics. In his spare time ... he has no spare time. Kurt, who
dislikes writing about himself in the third person, receives entirely too much
e-mail at kwall@kurtwerks.com.
Bill von Hagen holds degrees in computer science, English
writing, and art history. Bill has worked with Unix systems
since 1982, during which time he has been a system admin
istrator, writer, systems programmer, development manager,
drummer, operations manager, and (now) product man
ager. Bill has written a number of books including Hacking
the TiVo, Lima Filesystems, Installing Red Hat Linux 7, and
SGML for Dummies, contributed to Red Hat 7 Unleashed,
and coauthored the Mac OS X Power User's Guide with Brian Proffitt. Bill has
written articles and software reviews for publications including Linux Magazine,
Mac Tech, Linux Format (UK), and Mac Directory. He has also written extensive
online material for CMP Media, Unux Planet, and Corel. An avid computer col
lector specializing in workstations, he owns more than 200 computer systems.
You can contact Bill at wvh@vonhagen.org.
xi