Skip to content

Conversation

@kriskowal
Copy link
Collaborator

No description provided.

Comment on lines +65 to +77
## present in 3.9.2 xst.mk
## C_OPTIONS += -fsanitize=address -fno-omit-frame-pointer
## LINK_OPTIONS += -fsanitize=address -fno-omit-frame-pointer
# present in 5.5.0 xst.mk
# ifeq ($(SANITIZER), undefined)
# C_OPTIONS += -fsanitize=bool,builtin,enum,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr -fno-sanitize-recover=bool,builtin,enum,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr,array-bounds,function
# LINK_OPTIONS += -fsanitize=bool,builtin,enum,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr -fno-sanitize-recover=bool,builtin,enum,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr,array-bounds,function
# else
# C_OPTIONS += -fsanitize=address -fsanitize-blacklist=xst_no_asan.txt
# LINK_OPTIONS += -fsanitize=address
# endif
# C_OPTIONS += -DmxASANStackMargin=131072 -fno-omit-frame-pointer
# LINK_OPTIONS += -fno-omit-frame-pointer
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please confirm I can safely delete this commented section that I found in xst.mk on Moddable 5.5.0.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That all appears to be related to fuzzer configurations. You should be able to report that.

FWIW – it might be interesting to run xsnap with sanitizers enabled in a debug / development environment. It certainly uses XS in ways that are different from the fuzzers and would also check your name code. That should be an option since the performance impact of the sanitizers is considerable.

Comment on lines +126 to +152
$(TMP_DIR)/e_acos.o \
$(TMP_DIR)/e_acosh.o \
$(TMP_DIR)/e_asin.o \
$(TMP_DIR)/e_atan2.o \
$(TMP_DIR)/e_atanh.o \
$(TMP_DIR)/e_cosh.o \
$(TMP_DIR)/e_exp.o \
$(TMP_DIR)/e_hypot.o \
$(TMP_DIR)/e_log.o \
$(TMP_DIR)/e_log10.o \
$(TMP_DIR)/e_pow.o \
$(TMP_DIR)/e_rem_pio2.o \
$(TMP_DIR)/e_sinh.o \
$(TMP_DIR)/k_cos.o \
$(TMP_DIR)/k_exp.o \
$(TMP_DIR)/k_rem_pio2.o \
$(TMP_DIR)/k_sin.o \
$(TMP_DIR)/k_tan.o \
$(TMP_DIR)/s_asinh.o \
$(TMP_DIR)/s_atan.o \
$(TMP_DIR)/s_cos.o \
$(TMP_DIR)/s_expm1.o \
$(TMP_DIR)/s_log1p.o \
$(TMP_DIR)/s_scalbn.o \
$(TMP_DIR)/s_sin.o \
$(TMP_DIR)/s_tan.o \
$(TMP_DIR)/s_tanh.o \
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not present in lin/xsnap-worker.mk. Should we sync these from Mac to Linux?

$(TMP_DIR)/xsnap-worker.o

VPATH += $(SRC_DIR) $(TLS_DIR)
VPATH += $(SRC_DIR) $(TLS_DIR) $(XS_TLS_DIR)/fdlibm
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only slightly different than what I found in xst.mk. The difference accounts for xsnap tools being a different than xs tools.

Comment on lines +631 to +644
// TODO reason through this follow-up from moddable's fork between 3.9.2 and 5.5.0
//path = nsbuf + 1;
//snapshot.stream = fopen(path, "rb");
//if (snapshot.stream) {
// fxUseSnapshot(machine, &snapshot);
// fclose(snapshot.stream);
//}
//else
// snapshot.error = errno;
//if (snapshot.error) {
// fprintf(stderr, "cannot restore snapshot %s: %s\n",
// path, strerror(snapshot.error));
// c_exit(E_IO_ERROR);
//}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is present in the Moddable fork of xsnap-worker.c. It looks like it’s verifying that the snapshot can round-trip back. I found that some unit tests in agoric-sdk/packages/xsnap failed with this code in place. This may simply have been because the path was a file descriptor reference. If it’s useful, I could make this contingent on whether path starts with @.

attn @mhofman

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah this was added by Moddable to reset the machine from snapshot to avoid performance degradation due to memory fragmentation. We do not need this as we do this upstream, and it is actually harmful to have that behavior hardcoded as we need the ability to test without reloading to detect load from snapshot divergence bugs.

Please take a look at discarded changes from #44 compared to what was merged in #46

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also see #48 for a proposal to make this use snapshot explicit.

We never landed it because we instead found it more efficient to start another worker and stream the snapshot to it (the agoric process is teeing the snapshot stream into both the swing-store and to the new worker).

Comment on lines 289 to 319
// TODO reconcile with xnsap-worker.c, which has a try/catch
// {
// xsVars(3);
// xsTry {
// if (command == '?') {
// #if XSNAP_TEST_RECORD
// fxTestRecord(mxTestRecordJSON | mxTestRecordParam, nsbuf + 1, nslen - 1);
// #endif
// // TODO: can we avoid a copy?
// xsVar(0) = xsArrayBuffer(nsbuf + 1, nslen - 1);
// xsVar(1) = xsCall1(xsGlobal, xsID("handleCommand"), xsVar(0));
// } else {
// #if XSNAP_TEST_RECORD
// fxTestRecord(mxTestRecordJS | mxTestRecordParam, nsbuf + 1, nslen - 1);
// #endif
// // TODO reconcile with xsnap.c -e
// // xsResult = xsString(argv[argi]);
// // xsCall1(xsGlobal, xsID("eval"), xsResult);
// xsVar(0) = xsStringBuffer(nsbuf + 1, nslen - 1);
// xsVar(1) = xsCall1(xsGlobal, xsID("eval"), xsVar(0));
// }
// }
// xsCatch {
// if (xsTypeOf(xsException) != xsUndefinedType) {
// // fprintf(stderr, "%c: %s\n", command, xsToString(xsException));
// error = E_UNHANDLED_EXCEPTION;
// xsVar(1) = xsException;
// xsException = xsUndefined;
// }
// }
// }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intend to delete this note. I made some early attempt to reconcile xsnap.c and xsnap-worker.c, and this was a note to that effect.

Comment on lines 58 to 59
// XXX present in xst.h but absent on my machine. system dependency? need linkage in Makefile?
//#include <fdlibm.h>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is safe to delete.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's in the makefile, right?

@kriskowal kriskowal requested a review from phoddie April 17, 2025 23:41
Copy link
Contributor

@mhofman mhofman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My biggest concerns are around the scope of the change for timers which seem to involves a bunch of mutex logic, and the apparent addition of some I/O in module loading.

$(OBJECTS): $(XS_TLS_DIR)/fdlibm/math_private.h
$(OBJECTS): $(SRC_DIR)/xsSnapshot.h
$(OBJECTS): $(INC_DIR)/xs.h
$(OBJECTS): $(EXTRA_DEPS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an agoric-sdk build mechanism to force rebuild on config changes, please do not remove.

Comment on lines +631 to +644
// TODO reason through this follow-up from moddable's fork between 3.9.2 and 5.5.0
//path = nsbuf + 1;
//snapshot.stream = fopen(path, "rb");
//if (snapshot.stream) {
// fxUseSnapshot(machine, &snapshot);
// fclose(snapshot.stream);
//}
//else
// snapshot.error = errno;
//if (snapshot.error) {
// fprintf(stderr, "cannot restore snapshot %s: %s\n",
// path, strerror(snapshot.error));
// c_exit(E_IO_ERROR);
//}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah this was added by Moddable to reset the machine from snapshot to avoid performance degradation due to memory fragmentation. We do not need this as we do this upstream, and it is actually harmful to have that behavior hardcoded as we need the ability to test without reloading to detect load from snapshot divergence bugs.

Please take a look at discarded changes from #44 compared to what was merged in #46

-DmxMetering=1 \
-DmxDebug=1 \
-UmxInstrument \
-DmxInstrument=1 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this used to cause issues, or at least I wasn't confident in its behavior. See #34

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a rule mxInstrument and mxDebug are checked to see if they defined. The value shouldn't matter. That said, I prefer setting it to 1. But, whatever you do, don't set it 0 which suggests the feature is disabled when it isn't.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mxInstrument is indeed still problematic and I’ve restored the -U flag just to be sure.

$(OBJECTS): $(SRC_DIR)/xsScript.h
$(OBJECTS): $(SRC_DIR)/xsSnapshot.h
$(OBJECTS): $(INC_DIR)/xs.h
$(OBJECTS): $(EXTRA_DEPS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an agoric-sdk build mechanism to force rebuild on config changes, please do not remove.

char prefix[8 + sizeof fmt + 8 * sizeof numeral64 + sizeof timestampBuffer];
// Prepend the meter usage to the reply.
snprintf(prefix, sizeof(prefix), fmt,
snprintf(prefix, sizeof(prefix) - 1, fmt,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to make prefix 1 bigger instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s reasonable. I believe sprintfn assumes a space for the null terminator beyond the length.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The snprintf() and vsnprintf() functions will write at most size-1 of the characters
printed into the output string (the size'th character then gets the terminating ‘\0’); if
the return value is greater than or equal to the size argument, the string was too short
and some of the printed characters were discarded.  The output is always null-terminated,
unless size is 0.

Comment on lines +574 to +587
#if mxWindows
DWORD attributes;
attributes = GetFileAttributes(path);
if (attributes != 0xFFFFFFFF) {
if (attributes & FILE_ATTRIBUTE_DIRECTORY)
return;
}
#else
struct stat a_stat;
if (stat(path, &a_stat) == 0) {
if (S_ISDIR(a_stat.st_mode))
return;
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we had nerfed file system access. Slightly concerned we'd be doing I/O possibly before the nerfing point.

FILE* file;
};

typedef void (*txDumpChunk)(txDumper* dumper, txByte* data, txSize size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay for abstractions

Comment on lines 58 to 59
// XXX present in xst.h but absent on my machine. system dependency? need linkage in Makefile?
//#include <fdlibm.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's in the makefile, right?

Comment on lines +75 to +77
#if GNUC > 11
#define mxUseFloat16 1
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to require a minimum version of the compiler to make sure we don't end up with different representations floating around. I believe we already have some checks like that for hasBuiltin

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It the compiler supports float16 it is IEEE numerics by definition, so there shouldn't be variation in the representations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is if we allowed a mix of compiler that either had this enabled or not. I think we should just fail to compile if we can't enable this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could. But, it is unnecessary. XS contains the necessary fallback code for when the compiler does not support float16 natively. That has been verified with test262.

Comment on lines 96 to 97
// XXX xst.h also has:
// void* script; // txScript*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this has something to do with runScript ?

@mhofman
Copy link
Contributor

mhofman commented Apr 18, 2025

Oh and as discussed offline, making sure we use fdlibm on linux. Definitely want to take advantage there.

@kriskowal
Copy link
Collaborator Author

I’ve, among other things,

  • ported the fdlibm changes to the linux makefile
  • sorted out the timers. we’re not going to support shared timers, but the hooks have to be present in the platform, so i’ve left noop for the ones that can’t be avoided and panic from the ones that shouldn’t be called.
  • gotten this to pass all xsap tests in agoric-sdk locally, so far

@kriskowal kriskowal marked this pull request as ready for review September 8, 2025 21:36
@kriskowal
Copy link
Collaborator Author

This work is not a current priority for Agoric, but if we can review and merge this in the occasional spare cycle, I think we’ll be better off overall than letting these bits rot. Please consider a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants