[SERVER-7080] On Solaris, link to backtrace() at run-time or emulate it if not found Created: 20/Sep/12  Updated: 11/Jul/16  Resolved: 01/Jul/13

Status: Closed
Project: Core Server
Component/s: Logging
Affects Version/s: 2.2.0
Fix Version/s: 2.4.6, 2.5.1

Type: Bug Priority: Minor - P4
Reporter: Eric Milkie Assignee: Tad Marshall
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Oracle Solaris


Issue Links:
Depends
is depended on by SERVER-9761 Mongo executables should be built wit... Closed
Related
related to SERVER-7283 Switch to libtcmalloc_and_profiler in... Closed
Backwards Compatibility: Fully Compatible
Operating System: Solaris
Participants:

 Description   

Solaris 11 has a working backtrace() function (which we use for stack traces), but Solaris 10 does not. When present, this function, and related functions backtrace_symbols and backtrace_symbols_fd, are found in libc.so.1, which is generally in /lib/64 (aka /lib/amd64).

We should not have an external reference to backtrace but should instead search for it in libc.so.1 and use it if found. If not found, we should emulate it using printstack() and walkcontext(). This will make the same binary runnable on both Solaris 10 and Solaris 11 and will use the native function on Solaris 11.

References:
https://blogs.oracle.com/mandalika/entry/c_c_printing_stack_trace
man page for walkcontext / printstack

Old description:
backtrace() symbol does not exist on all Solaris (but it apparently exists for our build?)
We should investigate and remove backtrace() support from Solaris

ld.so.1: mongod: fatal: relocation error: file mongod: symbol backtrace:
referenced symbol not found



 Comments   
Comment by auto [ 18/Jul/13 ]

Author:

{u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@10gen.com'}

Message: SERVER-7080 Add feature test for execinfo functions to repair build of client driver
Branch: v2.4
https://github.com/mongodb/mongo/commit/3686654879edaea1c2ddb06f34624d2f76841f87

Comment by auto [ 18/Jul/13 ]

Author:

{u'username': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-7080 Emulate backtrace_symbols() and backtrace_symbols_fd() on Solaris 10

backtrace_symbols() returns a block of strings, each containing a
symbolic representation of a location in a stack trace; i.e. a line
of a stack trace. backtrace_symbols() is allowed to (and must)
allocate memory and cannot be used in a signal handler. Add code to
produce lines on Solaris 10 that are similar to those produced by
backtrace_symbols() on Solaris 11.

backtrace_symbols_fd() writes a stack trace to a specified file
descriptor. backtrace_symbols_fd() must not allocate memory and may
be safely used in a signal handler. Add code to produce output on
Solaris 10 that is similar to that produced by backtrace_symbols_fd()
on Solaris 11.
Branch: v2.4
https://github.com/mongodb/mongo/commit/990cb4be620ee4bfbc406b36ba3d5793b0563ee7

Comment by auto [ 18/Jul/13 ]

Author:

{u'username': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-7080 Add code to emulate backtrace()

backtrace() fills a buffer provided by the caller with addresses
constituting a stack trace. This emulation allows the display of
addresses in Solaris 10, which can be used with addr2line to see
code locations.
Branch: v2.4
https://github.com/mongodb/mongo/commit/71082c54a4bb5007445f1a0c19e14aca3567b284

Comment by auto [ 18/Jul/13 ]

Author:

{u'username': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-7080 Link to backtrace, backtrace_symbols and backtrace_symbols_fd at runtime

Do not make direct calls to backtrace, backtrace_symbols or backtrace_symbols_fd,
which are present in Solaris 11 but not in Solaris 10. Instead, see if they are
available in a loaded library (which will be libc.so.1) at runtime and either
call them or call an emulation.
Branch: v2.4
https://github.com/mongodb/mongo/commit/66f4a37277cc2f309851e525e3392a20295cf737

Comment by auto [ 28/Jun/13 ]

Author:

{u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@10gen.com'}

Message: SERVER-7080 Add feature test for execinfo functions to repair build of client driver
Branch: master
https://github.com/mongodb/mongo/commit/bd9ff869615e2611589f4e8795dea3fe9655ad27

Comment by Andy Schwerin [ 28/Jun/13 ]

Breaks client tarball.

Comment by Andrew Morrow (Inactive) [ 28/Jun/13 ]

I think https://github.com/mongodb/mongo/commit/54f25e6292eb565d4eadec1d5d75d286c787c053 broke the "client tarball" build of the C++ client driver on OS X:

scons clientTests
scons: Reading SConscript files ...
Checking for C++ library boost_thread-mt... (cached) yes
Checking for C++ library boost_filesystem-mt... (cached) yes
Checking for C++ library boost_system-mt... (cached) yes
Checking for sasl_version_info(0, 0, 0, 0, 0, 0) in C library sasl2... (cached) yes
scons: done reading SConscript files.
scons: Building targets ...
g++ -o build/mongo/platform/backtrace.o -c -O3 -pthread -D_SCONS -DMONGO_EXPOSE_MACROS -Ibuild -Isrc -Ibuild/mongo -Isrc/mongo -I/opt/local/include -I/opt/local src/mongo/platform/backtrace.cpp
In file included from src/mongo/platform/backtrace.cpp:25:
/usr/include/ucontext.h:43:2: error: #error The deprecated ucontext routines require _XOPEN_SOURCE to be defined
src/mongo/platform/backtrace.cpp: In function 'int mongo::pal::<unnamed>::addrtosymstr(void*, char*, int)':
src/mongo/platform/backtrace.cpp:71: error: 'Dl_info_t' was not declared in this scope
src/mongo/platform/backtrace.cpp:71: error: expected `;' before 'symbolInfo'
src/mongo/platform/backtrace.cpp:72: error: 'symbolInfo' was not declared in this scope
src/mongo/platform/backtrace.cpp:75: error: 'symbolInfo' was not declared in this scope
src/mongo/platform/backtrace.cpp:87: error: 'symbolInfo' was not declared in this scope
src/mongo/platform/backtrace.cpp: In function 'int mongo::pal::backtrace_emulation(void**, int)':
src/mongo/platform/backtrace.cpp:100: error: 'getcontext' was not declared in this scope
src/mongo/platform/backtrace.cpp:106: error: 'walkcontext' was not declared in this scope
scons: *** [build/mongo/platform/backtrace.o] Error 1
scons: building terminated because of errors.

I think the problem is that the tarball SConstruct file doesn't have the configure test for backtrace and friends so MONGO_HAVE_EXECINFO_BACKTRACE isn't defined, and we try to fall back to the emulations, however they don't build on OS X (and, really, shouldn't be used, since OS X does offer the real BSD backtrace routines).

Comment by auto [ 25/Jun/13 ]

Author:

{u'username': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-7080 Emulate backtrace_symbols() and backtrace_symbols_fd() on Solaris 10

backtrace_symbols() returns a block of strings, each containing a
symbolic representation of a location in a stack trace; i.e. a line
of a stack trace. backtrace_symbols() is allowed to (and must)
allocate memory and cannot be used in a signal handler. Add code to
produce lines on Solaris 10 that are similar to those produced by
backtrace_symbols() on Solaris 11.

backtrace_symbols_fd() writes a stack trace to a specified file
descriptor. backtrace_symbols_fd() must not allocate memory and may
be safely used in a signal handler. Add code to produce output on
Solaris 10 that is similar to that produced by backtrace_symbols_fd()
on Solaris 11.
Branch: master
https://github.com/mongodb/mongo/commit/4232b77a2ce5aa078db6f4cf3afedf8a07efb825

Comment by auto [ 21/Jun/13 ]

Author:

{u'username': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-7080 Add code to emulate backtrace()

backtrace() fills a buffer provided by the caller with addresses
constituting a stack trace. This emulation allows the display of
addresses in Solaris 10, which can be used with addr2line to see
code locations.
Branch: master
https://github.com/mongodb/mongo/commit/a5eb3244eb0846bba96ff56289460f38fe26fffb

Comment by auto [ 20/Jun/13 ]

Author:

{u'username': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-7080 Visual Studio – add backtrace.

{cpp,h}

Branch: master
https://github.com/mongodb/mongo/commit/a34ce4ddd3f56daf9bd88b81454632d44788d585

Comment by auto [ 20/Jun/13 ]

Author:

{u'username': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-7080 Link to backtrace, backtrace_symbols and backtrace_symbols_fd at runtime

Do not make direct calls to backtrace, backtrace_symbols or backtrace_symbols_fd,
which are present in Solaris 11 but not in Solaris 10. Instead, see if they are
available in a loaded library (which will be libc.so.1) at runtime and either
call them or call an emulation.
Branch: master
https://github.com/mongodb/mongo/commit/54f25e6292eb565d4eadec1d5d75d286c787c053

Comment by Tad Marshall [ 23/May/13 ]

backtrace works in Oracle Solaris 11.1, at least for a build created on Solaris 11.1. Reports seem to indicate that it does not work in Solaris 10, but I don't have one to test.

Comment by Eric Milkie [ 25/Sep/12 ]

I tried getting a backtrace using our MongoDB test program and it works on Nexenta OS (a defunct OpenSolaris derivative) as well as on SmartOS.

Comment by Eric Milkie [ 21/Sep/12 ]

We do have the 32bit Solaris VM. I am working to get that running again.

Generated at Thu Feb 08 03:13:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.