Skip to content

Commit

Permalink
tests/open_wrapper: Handle the Ubuntu 64-bit time_t apocalypse (#3290)
Browse files Browse the repository at this point in the history
We're *mostly* insulated from this, but our tests need to intercept
calls to `open`, which means that we're exposed to some glibc internals
that change under `_TIME_BITS=64`.

Fortunately umockdev in the archive has already hit this, so adapt that
fix to our use.

Fixes: #3285
  • Loading branch information
AlanGriffiths authored and mattkae committed Mar 28, 2024
1 parent 72011bd commit 292dad3
Showing 1 changed file with 56 additions and 5 deletions.
61 changes: 56 additions & 5 deletions tests/mir_test_framework/open_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,45 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* As suggested by umockdev, _FILE_OFFSET_BITS breaks our open() interposing,
* as it results in a (platform dependent!) subset of {__open64, __open64_2,
* __open, __open_2} being defined (not just declared) in the header, causing
* the build to fail with duplicate definitions.

/* Because we're trying to interpose libc functions we get exposed to the
* implementation details of glibc.
*
* Due to the 64-bit time_t transition, our previous workaround of
* #undef _FILE_OFFSET_BITS (and thus getting the base entrypoints)
* no longer works; _FILE_OFFSET_BITS must be 64 if _TIME_BITS == 64,
* and it's hard to verify that none of the subsequent headers *don't*
* embed a time_t somewhere.
*
* These runes are taken from the Ubuntu umockdev patch solving the same
* problem there.
*/
#include <features.h>
#ifdef __GLIBC__ /* This is messing with glibc internals, and is not
* expected to work (or be needed) anywhere else.
* (Hello, musl!)
*/
/* Remove gcc asm aliasing so that our interposed symbols work as expected */
#include <sys/cdefs.h>

#include <stddef.h>
extern "C"
{
extern int __REDIRECT_NTH (__ttyname_r_alias, (int __fd, char *__buf,
size_t __buflen), ttyname_r);
}
#ifdef __REDIRECT
#undef __REDIRECT
#endif
#define __REDIRECT(name, proto, alias) name proto
#ifdef __REDIRECT_NTH
#undef __REDIRECT_NTH
#endif
#define __REDIRECT_NTH(name, proto, alias) name proto __THROW
#endif // __GLIBC__
/*
* End glibc hackery (although there is a second block below)
*/
#undef _FILE_OFFSET_BITS

#include "mir_test_framework/open_wrapper.h"
#include "mir_test_framework/interposer_helper.h"
Expand All @@ -32,6 +65,24 @@
#include <fcntl.h>
#include <boost/throw_exception.hpp>

/* Second block of glibc hackery
*
* Fixup for making a mess with __REDIRECT above
*/
#ifdef __GLIBC__
#ifdef __USE_TIME_BITS64
#define clock_gettime __clock_gettime64
extern "C"
{
extern int clock_gettime(clockid_t clockid, struct timespec *tp);
}
#endif
#endif // __GLIBC__
/*
* End glibc hackery
*/


namespace mtf = mir_test_framework;

namespace
Expand Down

0 comments on commit 292dad3

Please sign in to comment.