Choose better deterministic timestamp for zip

This commit is contained in:
Justine Tunney 2022-03-16 16:59:45 -07:00
parent b45d50b690
commit bf62140377
7 changed files with 32 additions and 30 deletions

Binary file not shown.

Binary file not shown.

View file

@ -824,7 +824,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
#if __GNUC__ + 0 >= 9 #if __GNUC__ + 0 >= 9
#define HOT_LABEL __attribute__((__hot__)) #define HOT_LABEL __attribute__((__hot__))
#define COLD_LABEL __attribute__((__hot__)) #define COLD_LABEL __attribute__((__cold__))
#else #else
#define HOT_LABEL #define HOT_LABEL
#define COLD_LABEL #define COLD_LABEL

View file

@ -205,50 +205,44 @@ static bool ftrace_installed = 0;
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD
} TracerObject; } FtracerObject;
static int TracerObject_init(PyObject* self, PyObject *args, PyObject *kwargs) static int FtracerObject_init(PyObject* self, PyObject *args, PyObject *kwargs)
{ {
if (!ftrace_installed) { ftrace_install();
ftrace_install();
ftrace_installed = 1;
ftrace_enabled = 0;
}
return 0; return 0;
} }
static PyObject* TracerObject_enter(PyObject *self, PyObject *Py_UNUSED(ignored)) static PyObject* FtracerObject_enter(PyObject *self, PyObject *Py_UNUSED(ignored))
{ {
ftrace_enabled = 1; ++g_ftrace;
return self; return self;
} }
static PyObject* TracerObject_exit(PyObject *self, PyObject *args) static PyObject* FtracerObject_exit(PyObject *self, PyObject *args)
{ {
ftrace_enabled = 0; --g_ftrace;
return self; return self;
} }
static PyMethodDef TracerObject_methods[] = { static PyMethodDef FtracerObject_methods[] = {
{"__enter__", (PyCFunction) TracerObject_enter, METH_NOARGS, {"__enter__", (PyCFunction) FtracerObject_enter, METH_NOARGS,
"enable ftrace to start logging" "enables c function call logging"},
}, {"__exit__", (PyCFunction) FtracerObject_exit, METH_VARARGS,
{"__exit__", (PyCFunction) TracerObject_exit, METH_VARARGS, "disables c function call logging"},
"disable ftrace to stop logging"
},
{0} {0}
}; };
static PyTypeObject TracerType = { static PyTypeObject FtracerType = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "cosmo.Tracer", .tp_name = "cosmo.Ftracer",
.tp_doc = "wrapping ftrace with a context manager", .tp_doc = "wrapping ftrace with a context manager",
.tp_basicsize = sizeof(TracerObject), .tp_basicsize = sizeof(FtracerObject),
.tp_itemsize = 0, .tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT, .tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericNew, .tp_new = PyType_GenericNew,
.tp_init = (initproc) TracerObject_init, .tp_init = (initproc) FtracerObject_init,
.tp_methods = TracerObject_methods, .tp_methods = FtracerObject_methods,
}; };
PyDoc_STRVAR(ftrace_doc, PyDoc_STRVAR(ftrace_doc,
@ -265,14 +259,12 @@ to work, the concomitant .com.dbg binary needs to be present.");
static PyObject * static PyObject *
cosmo_ftrace(PyObject *self, PyObject *noargs) cosmo_ftrace(PyObject *self, PyObject *noargs)
{ {
PyObject *tracer = PyType_GenericNew(&TracerType, NULL, NULL); PyObject *tracer = PyType_GenericNew(&FtracerType, NULL, NULL);
if (tracer == NULL) Py_RETURN_NONE; if (tracer == NULL) Py_RETURN_NONE;
TracerObject_init(tracer, NULL, NULL); FtracerObject_init(tracer, NULL, NULL);
return tracer; return tracer;
} }
static PyMethodDef cosmo_methods[] = { static PyMethodDef cosmo_methods[] = {
{"exit1", cosmo_exit1, METH_NOARGS, exit1_doc}, {"exit1", cosmo_exit1, METH_NOARGS, exit1_doc},
{"rdtsc", cosmo_rdtsc, METH_NOARGS, rdtsc_doc}, {"rdtsc", cosmo_rdtsc, METH_NOARGS, rdtsc_doc},
@ -321,14 +313,14 @@ PyMODINIT_FUNC
PyInit_cosmo(void) PyInit_cosmo(void)
{ {
PyObject *m; PyObject *m;
if (PyType_Ready(&TracerType) < 0) return 0; if (PyType_Ready(&FtracerType) < 0) return 0;
if (!(m = PyModule_Create(&cosmomodule))) return 0; if (!(m = PyModule_Create(&cosmomodule))) return 0;
PyModule_AddStringConstant(m, "MODE", MODE); PyModule_AddStringConstant(m, "MODE", MODE);
PyModule_AddIntConstant(m, "IMAGE_BASE_VIRTUAL", IMAGE_BASE_VIRTUAL); PyModule_AddIntConstant(m, "IMAGE_BASE_VIRTUAL", IMAGE_BASE_VIRTUAL);
PyModule_AddStringConstant(m, "kernel", GetKernelName()); PyModule_AddStringConstant(m, "kernel", GetKernelName());
PyModule_AddIntConstant(m, "kStartTsc", kStartTsc); PyModule_AddIntConstant(m, "kStartTsc", kStartTsc);
Py_INCREF(&TracerType); Py_INCREF(&FtracerType);
// PyModule_AddObject(m, "Tracer", (PyObject *) &TracerType); // PyModule_AddObject(m, "Tracer", (PyObject *) &TracerType);
return !PyErr_Occurred() ? m : 0; return !PyErr_Occurred() ? m : 0;
} }

View file

@ -31,7 +31,9 @@
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/stdio/append.internal.h" #include "libc/stdio/append.internal.h"
#include "libc/stdio/stdio.h" #include "libc/stdio/stdio.h"
#include "libc/sysv/consts/clock.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
#include "libc/time/time.h"
#include "libc/x/x.h" #include "libc/x/x.h"
#include "third_party/getopt/getopt.h" #include "third_party/getopt/getopt.h"
#include "third_party/python/Include/abstract.h" #include "third_party/python/Include/abstract.h"
@ -711,6 +713,8 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int ec; int ec;
timestamp.tv_sec = 1647414000; /* determinism */
/* clock_gettime(CLOCK_REALTIME, &timestamp); */
GetOpts(argc, argv); GetOpts(argc, argv);
Py_NoUserSiteDirectory++; Py_NoUserSiteDirectory++;
Py_NoSiteFlag++; Py_NoSiteFlag++;

View file

@ -145,6 +145,8 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *name,
size_t lfilehdrsize, uncompsize, compsize, commentsize; size_t lfilehdrsize, uncompsize, compsize, commentsize;
uint16_t method, gflags, mtime, mdate, iattrs, dosmode; uint16_t method, gflags, mtime, mdate, iattrs, dosmode;
CHECK_NE(0, mtim.tv_sec);
gflags = 0; gflags = 0;
iattrs = 0; iattrs = 0;
compsize = size; compsize = size;

View file

@ -26,11 +26,13 @@
#include "libc/runtime/gc.internal.h" #include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h" #include "libc/stdio/stdio.h"
#include "libc/sysv/consts/clock.h"
#include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h" #include "libc/sysv/consts/exit.h"
#include "libc/sysv/consts/map.h" #include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h" #include "libc/sysv/consts/prot.h"
#include "libc/time/time.h"
#include "libc/x/x.h" #include "libc/x/x.h"
#include "third_party/getopt/getopt.h" #include "third_party/getopt/getopt.h"
#include "tool/build/lib/elfwriter.h" #include "tool/build/lib/elfwriter.h"
@ -166,6 +168,8 @@ void zipobj(int argc, char **argv) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
timestamp.tv_sec = 1647414000; /* determinism */
/* clock_gettime(CLOCK_REALTIME, &timestamp); */
zipobj(argc, argv); zipobj(argc, argv);
return 0; return 0;
} }