BDE 4.14.0 Production release
Loading...
Searching...
No Matches
balst_objectfileformat.h
Go to the documentation of this file.
1/// @file balst_objectfileformat.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// balst_objectfileformat.h -*-C++-*-
8#ifndef INCLUDED_BALST_OBJECTFILEFORMAT
9#define INCLUDED_BALST_OBJECTFILEFORMAT
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup balst_objectfileformat balst_objectfileformat
15/// @brief Provide platform-dependent object file format trait definitions.
16/// @addtogroup bal
17/// @{
18/// @addtogroup balst
19/// @{
20/// @addtogroup balst_objectfileformat
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#balst_objectfileformat-purpose"> Purpose</a>
25/// * <a href="#balst_objectfileformat-classes"> Classes </a>
26/// * <a href="#balst_objectfileformat-description"> Description </a>
27/// * <a href="#balst_objectfileformat-dwarf-information"> DWARF Information </a>
28/// * <a href="#balst_objectfileformat-implementation-note"> Implementation Note </a>
29/// * <a href="#balst_objectfileformat-usage"> Usage </a>
30/// * <a href="#balst_objectfileformat-example-1-accessing-balst-objectfileformat-information-at-run-time"> Example 1: Accessing balst::ObjectFileFormat Information at Run Time </a>
31///
32/// # Purpose {#balst_objectfileformat-purpose}
33/// Provide platform-dependent object file format trait definitions.
34///
35/// # Classes {#balst_objectfileformat-classes}
36///
37/// - balst::ObjectFileFormat: namespace for object file format traits
38///
39/// @see
40///
41/// # Description {#balst_objectfileformat-description}
42/// This component defines a set of traits that identify and
43/// describe a platform's object file format properties. For example, the
44/// `balst::ObjectFileFormat::ResolverPolicy` trait is ascribed a "value" (i.e.,
45/// `Elf` or `Xcoff`) appropriate for each supported platform. The various
46/// stack trace traits are actually types declared in the
47/// `bdescu_ObjectFileFormat` `struct`. These types are intended to be used in
48/// specializing template implementations or to enable function overloading
49/// based on the prevalent system's characteristics. #defines are also
50/// provided by this component to facilitate conditional compilation depending
51/// upon object file formats.
52///
53/// ## DWARF Information {#balst_objectfileformat-dwarf-information}
54///
55///
56/// DWARF is a format for detailed debugging information. It is not a complete
57/// format, but is used within other formats. It is used within ELF on Linux,
58/// but not (yet) on Solaris at Bloomberg (currently the ELF format on Solaris
59/// still uses STABS). It is used within the Mach-O format (also known as the
60/// `Dladdr` format in this file) used on Darwin. It is also used by the Clang
61/// compiler (which uses ELF).
62///
63/// For all these platforms, parsing the DWARF information is necessary for the
64/// stack trace to get source file names and line numbers (the ELF format gives
65/// source file names, but only in the case of file-scope static functions).
66///
67/// DWARF is implemented for g++ versions earlier than 7.1.0 on Linux.
68///
69/// ### Implementation Note {#balst_objectfileformat-implementation-note}
70///
71///
72/// Linux g++ 7.1.0 uses DWARF version 4, while g++ 5.4.0 and before use DWARF
73/// version 3. At the moment the required system header, `dwarf.h`, is not
74/// available in the Bloomberg production build `chroot` environment, so
75/// support for dwarf formats is disabled.
76///
77/// DWARF support on Clang is problematic and not currrently implemented, see
78/// the long comment in balst_resolverimpl_elf.cpp, which explains exactly how
79/// it could be implemented when that becomes a priority.
80///
81/// We have not yet investigated implementing DWARF for Dladdr (Darwin).
82///
83/// ## Usage {#balst_objectfileformat-usage}
84///
85///
86/// This section illustrates intended use of this component.
87///
88/// ### Example 1: Accessing balst::ObjectFileFormat Information at Run Time {#balst_objectfileformat-example-1-accessing-balst-objectfileformat-information-at-run-time}
89///
90///
91/// The templated (specialized) `typeTest` function returns a unique, non-zero
92/// value when passed an object of types
93/// `balst::ObjectFileFormat::{Elf,Xcoff,Windows}`, and 0 otherwise.
94/// @code
95/// template <typename TYPE>
96/// int typeTest(const TYPE &)
97/// {
98/// return 0;
99/// }
100///
101/// int typeTest(const balst::ObjectFileFormat::Elf &)
102/// {
103/// return 1;
104/// }
105///
106/// int typeTest(const balst::ObjectFileFormat::Xcoff &)
107/// {
108/// return 2;
109/// }
110///
111/// int typeTest(const balst::ObjectFileFormat::Windows &)
112/// {
113/// return 3;
114/// }
115///
116/// int main() ...
117/// @endcode
118/// We define an object `policy` of type `balst::ObjectFileFormat::Policy`,
119/// which will be of type `...::Elf`, `...::Xcoff`, or `...::Windows`
120/// appropriate for the platform.
121/// @code
122/// balst::ObjectFileFormat::Policy policy;
123/// @endcode
124/// We now test it using `typeTest`:
125/// @code
126/// assert(typeTest(policy) > 0);
127///
128/// #if defined(BALST_OBJECTFILEFORMAT_RESOLVER_ELF)
129/// assert(1 == typeTest(policy));
130/// #endif
131///
132/// #if defined(BALST_OBJECTFILEFORMAT_RESOLVER_XCOFF)
133/// assert(2 == typeTest(policy));
134/// #endif
135///
136/// #if defined(BALST_OBJECTFILEFORMAT_RESOLVER_WINDOWS)
137/// assert(3 == typeTest(policy));
138/// #endif
139/// }
140/// @endcode
141/// @}
142/** @} */
143/** @} */
144
145/** @addtogroup bal
146 * @{
147 */
148/** @addtogroup balst
149 * @{
150 */
151/** @addtogroup balst_objectfileformat
152 * @{
153 */
154
155#include <balscm_version.h>
156
157#include <bsls_platform.h>
158
159
160
161namespace balst {
162 // ======================
163 // class ObjectFileFormat
164 // ======================
165
166/// This `struct` is named `ObjectFileFormat` for historical reasons, what
167/// it really determines is resolving strategy. Linux, for example, can be
168/// resolved using either the `Elf` or `Dladdr` policies. We choose `Elf`
169/// for linux because that mode of resolving yields more information.
171
172 struct Elf {}; // resolve as elf object
173
174 struct Xcoff {}; // resolve as xcoff object
175
176 struct Windows {}; // format used on Microsoft Windows platform
177
178 struct Dladdr {}; // resolve using the 'dladdr' call
179
180 struct Dummy {};
181
182#if defined(BSLS_PLATFORM_OS_SOLARIS) || \
183 defined(BSLS_PLATFORM_OS_LINUX)
184
185 typedef Elf Policy;
186# define BALST_OBJECTFILEFORMAT_RESOLVER_ELF 1
187
188# if defined(BSLS_PLATFORM_OS_LINUX) && defined(BSLS_PLATFORM_CMP_GNU)
189# define BALST_OBJECTFILEFORMAT_RESOLVER_DWARF 1
190# endif
191
192#elif defined(BSLS_PLATFORM_OS_AIX)
193
194 typedef Xcoff Policy;
195# define BALST_OBJECTFILEFORMAT_RESOLVER_XCOFF 1
196
197#elif defined(BSLS_PLATFORM_OS_WINDOWS)
198
199 typedef Windows Policy;
200# define BALST_OBJECTFILEFORMAT_RESOLVER_WINDOWS 1
201
202#elif defined(BSLS_PLATFORM_OS_DARWIN)
203
204 typedef Dladdr Policy;
205# define BALST_OBJECTFILEFORMAT_RESOLVER_DLADDR 1
206
207#else
208
209 typedef Dummy Policy;
210# error unrecognized platform
211# define BALST_OBJECTFILEFORMAT_RESOLVER_UNIMPLEMENTED 1
212
213#endif
214
215};
216} // close package namespace
217
218
219
220#endif
221
222// ----------------------------------------------------------------------------
223// Copyright 2015 Bloomberg Finance L.P.
224//
225// Licensed under the Apache License, Version 2.0 (the "License");
226// you may not use this file except in compliance with the License.
227// You may obtain a copy of the License at
228//
229// http://www.apache.org/licenses/LICENSE-2.0
230//
231// Unless required by applicable law or agreed to in writing, software
232// distributed under the License is distributed on an "AS IS" BASIS,
233// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
234// See the License for the specific language governing permissions and
235// limitations under the License.
236// ----------------------------- END-OF-FILE ----------------------------------
237
238/** @} */
239/** @} */
240/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition balst_objectfileformat.h:161
Definition balst_objectfileformat.h:178
Definition balst_objectfileformat.h:180
Definition balst_objectfileformat.h:172
Definition balst_objectfileformat.h:176
Definition balst_objectfileformat.h:174
Definition balst_objectfileformat.h:170
Dummy Policy
Definition balst_objectfileformat.h:209