BDE 4.39.x 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 `Windows`) 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,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::Windows &)
107/// {
108/// return 3;
109/// }
110///
111/// int main() ...
112/// @endcode
113/// We define an object `policy` of type `balst::ObjectFileFormat::Policy`,
114/// which will be of type `...::Elf`, or `...::Windows` appropriate for the
115/// platform.
116/// @code
117/// balst::ObjectFileFormat::Policy policy;
118/// @endcode
119/// We now test it using `typeTest`:
120/// @code
121/// assert(typeTest(policy) > 0);
122///
123/// #if defined(BALST_OBJECTFILEFORMAT_RESOLVER_ELF)
124/// assert(1 == typeTest(policy));
125/// #endif
126///
127/// #if defined(BALST_OBJECTFILEFORMAT_RESOLVER_WINDOWS)
128/// assert(3 == typeTest(policy));
129/// #endif
130/// }
131/// @endcode
132/// @}
133/** @} */
134/** @} */
135
136/** @addtogroup bal
137 * @{
138 */
139/** @addtogroup balst
140 * @{
141 */
142/** @addtogroup balst_objectfileformat
143 * @{
144 */
145
146#include <balscm_version.h>
147
148#include <bsls_platform.h>
149
150
151
152namespace balst {
153 // ======================
154 // class ObjectFileFormat
155 // ======================
156
157/// This `struct` is named `ObjectFileFormat` for historical reasons, what
158/// it really determines is resolving strategy. Linux, for example, can be
159/// resolved using either the `Elf` or `Dladdr` policies. We choose `Elf`
160/// for linux because that mode of resolving yields more information.
161///
162/// See @ref balst_objectfileformat
164
165 struct Elf {}; // resolve as elf object
166
167 struct Windows {}; // format used on Microsoft Windows platform
168
169 struct Dladdr {}; // resolve using the 'dladdr' call
170
171 struct Dummy {};
172
173#if defined(BSLS_PLATFORM_OS_SOLARIS) || \
174 defined(BSLS_PLATFORM_OS_LINUX)
175
176 typedef Elf Policy;
177# define BALST_OBJECTFILEFORMAT_RESOLVER_ELF 1
178
179# if defined(BSLS_PLATFORM_OS_LINUX) && defined(BSLS_PLATFORM_CMP_GNU)
180# define BALST_OBJECTFILEFORMAT_RESOLVER_DWARF 1
181# endif
182
183#elif defined(BSLS_PLATFORM_OS_WINDOWS)
184
185 typedef Windows Policy;
186# define BALST_OBJECTFILEFORMAT_RESOLVER_WINDOWS 1
187
188#elif defined(BSLS_PLATFORM_OS_DARWIN)
189
190 typedef Dladdr Policy;
191# define BALST_OBJECTFILEFORMAT_RESOLVER_DLADDR 1
192
193#else
194
195 typedef Dummy Policy;
196# error unrecognized platform
197# define BALST_OBJECTFILEFORMAT_RESOLVER_UNIMPLEMENTED 1
198
199#endif
200
201};
202} // close package namespace
203
204
205
206#endif
207
208// ----------------------------------------------------------------------------
209// Copyright 2015 Bloomberg Finance L.P.
210//
211// Licensed under the Apache License, Version 2.0 (the "License");
212// you may not use this file except in compliance with the License.
213// You may obtain a copy of the License at
214//
215// http://www.apache.org/licenses/LICENSE-2.0
216//
217// Unless required by applicable law or agreed to in writing, software
218// distributed under the License is distributed on an "AS IS" BASIS,
219// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
220// See the License for the specific language governing permissions and
221// limitations under the License.
222// ----------------------------- END-OF-FILE ----------------------------------
223
224/** @} */
225/** @} */
226/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition balst_objectfileformat.h:152
Definition balst_objectfileformat.h:169
Definition balst_objectfileformat.h:171
Definition balst_objectfileformat.h:165
Definition balst_objectfileformat.h:167
Definition balst_objectfileformat.h:163
Dummy Policy
Definition balst_objectfileformat.h:195