components/stdcxx/README
author Mike Sullivan <Mike.Sullivan@Oracle.COM>
Fri, 27 Apr 2012 13:23:29 -0700
changeset 800 2ad056ed89ec
parent 402 94ae4d75524c
permissions -rw-r--r--
7163771 sha1 should not be used in userland-fetch and userland component/*/Makefile 7164671 BUILD_TOOLS should point to on11update-tools now
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
402
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
     1
Explanation of some unusual compiler flags used when building the
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
     2
Apache Standard C++ Library:
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
     3
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
     4
1. CFLAGS
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
     5
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
     6
All the -D_STRICT_STDC -D_STRICT_STDC__ -D_STDC_C99 -D_ISOC99_SOURCE:
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
     7
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
     8
Since we are building a Standard conforming library, compliance with
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
     9
Strict Standard C is assumed and expected.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    10
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    11
However, the Apache Standard C++ Library provides some extensions to
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    12
the C++ Standard, by allowing some C99 functions. Visibility of C99
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    13
is enabled by passing -D_XPG6 -D_XOPEN_SOURCE=600 in CFLAGS. However,
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    14
Standard C++ disallows _XPG6 and _XOPEN_SOURCE=600, and only allows
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    15
_XPG5 and _XOPEN_SOURCE=500, so for CXXFLAGS we raise _XPG5 and
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    16
_XOPEN_SOURCE=500.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    17
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    18
2. CXXFLAGS
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    19
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    20
-library=no%Cstd :
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    21
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    22
do *NOT*, under any circumstances, use the Solaris libCstd.so.1.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    23
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    24
-library=Crun :
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    25
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    26
Use the Solaris libCrun.so.1. This library is very important: it provides
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    27
the symbols for the Standard C++ exception classes, and it also provides
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    28
the Solaris C++ run-time support.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    29
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    30
-Qoption ccfe ++boolflag:sunwcch=false :
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    31
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    32
do *NOT*, under any circumstances, use the default Studio 12 header
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    33
files for the libCstd.so.1 Solaris C++ Library. This flag is very
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    34
important. We must build the Apache C++ Library using its own header
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    35
files, and we must ignore any other C++ header files.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    36
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    37
-Qoption ccfe +d2,-xgeninl=system :
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    38
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    39
The +d2,-xgeninl=system options causes functions that are generated
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    40
inline also to be generated also as closed functions in the object file.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    41
By default, a function that is always inlined is not actually generated
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    42
unless its address is needed. 
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    43
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    44
-Qoption ccfe -expand=10000 :
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    45
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    46
The C++ front end decides whether to inline a function in part depending
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    47
on a complexity measure. The -expand=N option, where N is a decimal number,
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    48
sets the complexity limit. Functions of greater complexity are not inlined
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    49
by the front end. The default limit is in the range 100-500 depending on
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    50
the optimization level. Setting the limit to 10,000 effectively allows
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    51
inlining of all but the largest functions. 
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    52
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    53
We use these options when building our system libraries for two reasons:
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    54
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    55
2.1. We want to allow maximum inlining of functions to improve runtime
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    56
performance. The size of a library (especially a shared library) is not
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    57
usually important, so we trade size for speed.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    58
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    59
2.2. A library function defined as inline in a standard header will be
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    60
inlined in user code, unless inlining is disabled or the function address
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    61
is taken. If library functions get defined in user code, the program can
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    62
wind up with circular dependencies among the various program parts.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    63
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    64
Explanation:
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    65
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    66
Suppose library function F is defined as inline, but the library uses the
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    67
address of F. Function F will be generated as a closed function in the
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    68
library. If user code also needs the address of F, it will be generated in
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    69
user code. The linker picks the first definition of F it sees, which will
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    70
be in user code in this case, and discards any others. The library then
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    71
calls F in user code instead of the one inside the library. If F is used
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    72
as part of initializing the library, then the library has an initialization
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    73
dependency on the main program. The main program always has an
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    74
initialization dependency on the library. You can wind up with strange
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    75
program failures, since you cannot satisfy the circular dependency.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    76
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    77
To prevent this possibility, we generate F unconditionally as a closed
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    78
function in the library. When a user function needs the address of F,
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    79
the compiler first checks to see whether F is defined in the library.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    80
If so, it just generates a reference to F instead of generating a definition
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    81
of F. There is then only one copy of F in the entire program, and it is in
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    82
the library. 
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    83
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    84
-features=except,rtti,export,extensions,nestedaccess,tmplife,tmplrefstatic :
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    85
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    86
We want to enable specific and Standard-mandated C++ Compiler features,
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    87
and we want to be explicit about them, just in case the default C++
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    88
Compiler default features change in the future. This way, we are guaranteed
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    89
that the Library builds in a consistent way, independent of any future
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    90
updates to the C++ Compiler.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    91
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    92
-template=geninlinefuncs :
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    93
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    94
Instantiate inline member functions for the explicitly instantiated
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    95
class template which were not generated previously.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    96
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    97
-verbose=template :
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    98
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
    99
Be verbose about template instantiations. This is useful for tracking
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   100
what the compiler is doing when instantiating templates, and for debugging,
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   101
in case we end up with undefined class template symbols.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   102
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   103
-xlang=c99 :
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   104
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   105
Assume non-standard compatibility with C99. Allows C programming language
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   106
behavior for objects which were compiled either with the c99 driver, or
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   107
with the cc -xc99=%all driver, and are being linked with the Library.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   108
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   109
-xbuiltin=%none : 
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   110
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   111
No builtins whatsoever.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   112
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   113
-xinline= :
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   114
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   115
(nothing after the '=').
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   116
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   117
We've already told the compiler frontend (with the -Qoption ccfe flags)
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   118
how to inline, and what the inlining limits are. Therefore, do not make any
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   119
other heuristic decisions about inlining (i.e. assume nothing is inlined).
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   120
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   121
-xlibmieee :
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   122
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   123
Cause strict conformance to the IEEE 754 Standard for math routines in
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   124
exceptional cases. The C++ Standard implicitly mandates IEEE 754
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   125
(cf. see libstdcxx4.3lib man page).
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   126
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   127
3. LDFLAGS
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   128
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   129
-lumem :
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   130
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   131
The PAE Group and myself have tested the performance of the Apache Standard
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   132
C++ Library, and determined that linking with libumem provides the best
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   133
malloc(3C) performance. libmtmalloc.so.1 was spending a lot of time chasing
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   134
pointers.
94ae4d75524c 7064836 stdcxx to Userland
Stefan Teleman <stefan.teleman@oracle.com>
parents:
diff changeset
   135