Skip to content

Commit

Permalink
tests/open_wrapper: Handle the Ubuntu 64-bit time_t apocalypse
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.
  • Loading branch information
RAOF committed Mar 18, 2024
1 parent 8e5f965 commit 7ce2002
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 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,39 @@
* 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.
*/
/* 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
/*
* 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 +59,22 @@
#include <fcntl.h>
#include <boost/throw_exception.hpp>

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


namespace mtf = mir_test_framework;

namespace
Expand Down

0 comments on commit 7ce2002

Please sign in to comment.