Skip to content

Commit

Permalink
CogVM sources as per VMMaker.oscog-eem.2803
Browse files Browse the repository at this point in the history
StackInterpreter: Fix a regression on Cygwin. Cygwin's setjmp.h defines
_setjmp.  Undefine to get to our own definition.
Ensure various definitions for error agree to the letter.
b3dMain.c should not need to define warning.
  • Loading branch information
eliotmiranda committed Sep 7, 2020
1 parent d04e683 commit 1b896e9
Show file tree
Hide file tree
Showing 63 changed files with 573 additions and 402 deletions.
2 changes: 1 addition & 1 deletion nsspur64src/vm/cogit.h
@@ -1,5 +1,5 @@
/* Automatically generated by
CCodeGenerator VMMaker.oscog-eem.2802 uuid: 599172af-2cce-44a4-9004-23bd36c89807
CCodeGenerator VMMaker.oscog-eem.2803 uuid: 6584359e-d7b8-46dd-bb76-b631d9977a57
*/


Expand Down
49 changes: 27 additions & 22 deletions nsspur64src/vm/cointerp.c
@@ -1,9 +1,9 @@
/* Automatically generated by
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.2802 uuid: 599172af-2cce-44a4-9004-23bd36c89807
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.2803 uuid: 6584359e-d7b8-46dd-bb76-b631d9977a57
from
CoInterpreter VMMaker.oscog-eem.2802 uuid: 599172af-2cce-44a4-9004-23bd36c89807
CoInterpreter VMMaker.oscog-eem.2803 uuid: 6584359e-d7b8-46dd-bb76-b631d9977a57
*/
static char __buildInfo[] = "CoInterpreter VMMaker.oscog-eem.2802 uuid: 599172af-2cce-44a4-9004-23bd36c89807 " __DATE__ ;
static char __buildInfo[] = "CoInterpreter VMMaker.oscog-eem.2803 uuid: 6584359e-d7b8-46dd-bb76-b631d9977a57 " __DATE__ ;
char *__interpBuildInfo = __buildInfo;


Expand Down Expand Up @@ -55,6 +55,11 @@ warningat(const char *s, int l) { /* ditto with line number. */
}
#pragma auto_inline(on)

/* Some setjmp.h's, e.g. cygwin's define _setjmp. Undefine to get to our own. */
#if defined(_setjmp)
# undef _setjmp
#endif

This comment has been minimized.

Copy link
@nicolas-cellier-aka-nice

nicolas-cellier-aka-nice Sep 8, 2020

Contributor

Hi Eliot,
unfortunately, it does not seem to work for mingw target (which is what we use, cygwin is just the compiling host, not the target).

../../spur64src/vm/gcc3x-cointerp.c:13681:41: error: too few arguments to function call, expected 2, have 1
if ((_setjmp(GIV(jmpBuf)[GIV(jmpDepth)])) == 0) {
~~~~~~~ ^
/usr/x86_64-w64-mingw32/sys-root/mingw/include/setjmp.h:242:3: note: '_setjmp' declared here
int __cdecl attribute ((nothrow,returns_twice)) _setjmp(jmp_buf _Buf, void *_Ctx);
^

Shouldn't we use a conflict-less osvm_setjmp and osvm_longjmp (or use sq prefix if you prefer) - and either define them as setjmp longjmp where it fits, or use our own implementation when it does not fit ?

This comment has been minimized.

Copy link
@eliotmiranda

eliotmiranda Sep 8, 2020

Author Contributor

I has hoping I could fix this in platforms/Cross/vm/sqSetjmpShim.h but so far I have not been able to.

The issue is that mingw defines _setjmp, here's the definition that is used when clang is the compiler:

# 242 "/usr/x86_64-w64-mingw32/sys-root/mingw/include/setjmp.h" 3
  int __attribute__((__cdecl__)) __attribute__ ((__nothrow__,__returns_twice__))  _setjmp(jmp_buf _Buf, void *_Ctx);

So I tried a sqSetjmpShim.h like this:

#if !defined(_WIN32)
# undef setjmp
# undef longjmp
# define setjmp _setjmp
# define longjmp _longjmp
#endif
/* mingw redeclares _setjmp so we have to provide an alternative */
#if __MINGW32__ || __MINGW64__ /* clang on cygwin/mingw */
int __attribute__((__nowthrow__,__returns_twice__)) _setjmp0(jmp_buf);
# undef _setjmp
# define _setjmp _setjmp0
#endif

I know the code is being selected because if I preprocess via -E I see the declaration for _setjmp0. But the define of _setjmp is not seen and so invocations of _setjmp are not changed by the preprocessor into invocations of _setjmp0. Sigh... (& I've tried both #define _setjmp _setjmp0 and #define _setjmp(b) _setjmp0(b)).

A reason to prefer redefine _setjmp itself rather than adding our own non-conflicting version is that if any library code included in a plugin uses setjmp/longjmp then the longjmp will likely fail unless it uses our code.

The alternatives seem to be
a) try and figure out why sqSetjmpShim.h is unable to map _setjmp to _setjmp0 and fix this
b) if it cant be fixed, have Slang emit osvm_setjmp and osvm_longjmp, and have sqSetjmpShim.h map osvm_setjmp and osvm_longjmp to _setjmp/_longjmp, and have _setjmp-x64.asm et al override all symbols for _setjmp/_longjmp, e.g.

        .text
        .globl setjmp
        .globl sigsetjmp
        .globl _setjmp
        .globl _setjmp0
        .p2align        4, 0x90
setjmp:
sigsetjmp:
_setjmp:
_setjmp0:
        ....

This comment has been minimized.

Copy link
@nicolas-cellier-aka-nice

nicolas-cellier-aka-nice Sep 9, 2020

Contributor

Ah OK, what we can do is define our own osvm_setjmp in the .asm, then #define setjmp osvm_setjmp when #ifdef WIN64, and use setjmp instead of _setjmp in VMMaker... Can it work?

I don't think that using _setjmp directly in VMMaker is a good idea because too much implementation specific anyway.

The cygwin/mingw makefiles must also be fixed for using the .asm, currently they do not.


/* end StackInterpreter class>>preambleCCode */


Expand Down Expand Up @@ -1256,7 +1261,7 @@ extern sqInt nonIndexablePointerFormat(void);
static sqInt noUnscannedEphemerons(void);
static sqInt NoDbgRegParms numBytesOfBytes(sqInt objOop);
extern sqInt numBytesOf(sqInt objOop);
extern usqInt numPointerSlotsOf(sqInt objOop);
extern sqInt numPointerSlotsOf(sqInt objOop);
static usqInt NoDbgRegParms numSlotsOfAny(sqInt objOop);
extern usqInt numSlotsOf(sqInt objOop);
static sqInt NoDbgRegParms numStrongSlotsOfInephemeral(sqInt objOop);
Expand Down Expand Up @@ -2616,7 +2621,7 @@ sqInt debugCallbackInvokes;
sqInt debugCallbackReturns;
sqInt ffiExceptionResponse;
sqInt checkedPluginName;
const char *interpreterVersion = "Newspeak Virtual Machine [ Open Smalltalk, Spur] CoInterpreterPrimitives_VMMaker.oscog-eem.2802";
const char *interpreterVersion = "Newspeak Virtual Machine [ Open Smalltalk, Spur] CoInterpreterPrimitives_VMMaker.oscog-eem.2803";
sqInt minBackwardJumpCountForCompile = MinBackwardJumpCountForCompile /* 40 */;
int displayWidth;
int displayDepth;
Expand Down Expand Up @@ -41391,7 +41396,7 @@ followForwardedObjectFieldstoDepth(sqInt objOop, sqInt depth)
sqInt header1;
sqInt i;
sqInt numLiterals;
usqInt numSlots;
sqInt numSlots;
usqInt numSlots1;
sqInt oop;
sqInt referent;
Expand Down Expand Up @@ -49120,7 +49125,7 @@ copyObjtoAddrstopAtsavedFirstFieldsindex(sqInt objOop, sqInt segAddr, sqInt endS
sqInt iLimiT;
sqInt methodHeader;
sqInt numLiterals;
usqInt numMediatedSlots;
sqInt numMediatedSlots;
usqInt numSlots;
usqInt numSlots1;
sqInt oop;
Expand Down Expand Up @@ -55655,7 +55660,7 @@ numBytesOf(sqInt objOop)
Works with CompiledMethods, as well as ordinary objects. */

/* SpurMemoryManager>>#numPointerSlotsOf: */
usqInt
sqInt
numPointerSlotsOf(sqInt objOop)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
sqInt contextSize;
Expand Down Expand Up @@ -58891,7 +58896,7 @@ printReferencesTo(sqInt anOop)
assert((ReceiverIndex + ((sp >> 3))) < (lengthOf(objOop1)));
contextSize = (sp >> 3);
l12: /* end fetchStackPointerOf: */;
i = ((usqInt) (CtxtTempFrameStart + contextSize));
i = CtxtTempFrameStart + contextSize;
goto l13;
}
/* begin numSlotsOf: */
Expand Down Expand Up @@ -58924,7 +58929,7 @@ printReferencesTo(sqInt anOop)
/* begin literalCountOfMethodHeader: */
assert((((header) & 7) == 1));
numLiterals = ((header >> 3)) & AlternateHeaderNumLiteralsMask;
i = ((usqInt) (numLiterals + LiteralStart));
i = numLiterals + LiteralStart;
l13: /* end numPointerSlotsOf: */;
while (((i -= 1)) >= 0) {
if (anOop == (longAt((objOop1 + BaseHeaderSize) + (((sqInt)((usqInt)(i) << (shiftForWord()))))))) {
Expand Down Expand Up @@ -58979,7 +58984,7 @@ printReferencesTo(sqInt anOop)
assert((ReceiverIndex + ((sp >> 3))) < (lengthOf(objOop1)));
contextSize = (sp >> 3);
l14: /* end fetchStackPointerOf: */;
i = ((usqInt) (CtxtTempFrameStart + contextSize));
i = CtxtTempFrameStart + contextSize;
goto l15;
}
/* begin numSlotsOf: */
Expand Down Expand Up @@ -59012,7 +59017,7 @@ printReferencesTo(sqInt anOop)
/* begin literalCountOfMethodHeader: */
assert((((header) & 7) == 1));
numLiterals = ((header >> 3)) & AlternateHeaderNumLiteralsMask;
i = ((usqInt) (numLiterals + LiteralStart));
i = numLiterals + LiteralStart;
l15: /* end numPointerSlotsOf: */;
while (((i -= 1)) >= 0) {
if (anOop == (longAt((objOop1 + BaseHeaderSize) + (((sqInt)((usqInt)(i) << (shiftForWord()))))))) {
Expand Down Expand Up @@ -59068,7 +59073,7 @@ printReferencesTo(sqInt anOop)
assert((ReceiverIndex + ((sp >> 3))) < (lengthOf(objOop11)));
contextSize = (sp >> 3);
l16: /* end fetchStackPointerOf: */;
i = ((usqInt) (CtxtTempFrameStart + contextSize));
i = CtxtTempFrameStart + contextSize;
goto l17;
}
/* begin numSlotsOf: */
Expand Down Expand Up @@ -59101,7 +59106,7 @@ printReferencesTo(sqInt anOop)
/* begin literalCountOfMethodHeader: */
assert((((header) & 7) == 1));
numLiterals = ((header >> 3)) & AlternateHeaderNumLiteralsMask;
i = ((usqInt) (numLiterals + LiteralStart));
i = numLiterals + LiteralStart;
l17: /* end numPointerSlotsOf: */;
while (((i -= 1)) >= 0) {
if (anOop == (longAt((objOop11 + BaseHeaderSize) + (((sqInt)((usqInt)(i) << (shiftForWord()))))))) {
Expand Down Expand Up @@ -62234,10 +62239,10 @@ updatePointers(void)
sqInt numLiterals1;
sqInt numLiterals2;
sqInt numLiterals3;
usqInt numPointerSlots;
usqInt numPointerSlots1;
usqInt numPointerSlots2;
usqInt numPointerSlots3;
sqInt numPointerSlots;
sqInt numPointerSlots1;
sqInt numPointerSlots2;
sqInt numPointerSlots3;
usqInt numSlots;
usqInt numSlots1;
usqInt numSlots11;
Expand Down Expand Up @@ -62812,7 +62817,7 @@ updatePointersInsavedFirstFieldPointer(sqInt obj, sqInt firstFieldPtr)
assert((ReceiverIndex + ((sp >> 3))) < (lengthOf(obj)));
contextSize = (sp >> 3);
l6: /* end fetchStackPointerOf: */;
numPointerSlots = ((usqInt) (CtxtTempFrameStart + contextSize));
numPointerSlots = CtxtTempFrameStart + contextSize;
goto l10;
}
/* begin numSlotsOf: */
Expand Down Expand Up @@ -62842,7 +62847,7 @@ updatePointersInsavedFirstFieldPointer(sqInt obj, sqInt firstFieldPtr)
/* begin literalCountOfMethodHeader: */
assert((((header) & 7) == 1));
numLiterals = ((header >> 3)) & AlternateHeaderNumLiteralsMask;
numPointerSlots = ((usqInt) (numLiterals + LiteralStart));
numPointerSlots = numLiterals + LiteralStart;
l10: /* end numPointerSlotsWhileCompactingOf:withFormat:savedFirstFieldPointer: */;
if ((fmt <= 5 /* lastPointerFormat */)
&& (numPointerSlots > 0)) {
Expand Down Expand Up @@ -67420,8 +67425,8 @@ static sqInt
getErrorObjectFromPrimFailCode(void)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
sqInt classIndex;
usqInt clone;
usqInt errObj;
sqInt clone;
sqInt errObj;
sqInt fieldIndex;
sqInt i;
usqInt newObj;
Expand Down
4 changes: 2 additions & 2 deletions nsspur64src/vm/cointerp.h
@@ -1,5 +1,5 @@
/* Automatically generated by
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.2802 uuid: 599172af-2cce-44a4-9004-23bd36c89807
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.2803 uuid: 6584359e-d7b8-46dd-bb76-b631d9977a57
*/


Expand Down Expand Up @@ -254,7 +254,7 @@ extern sqInt minSlotsForShortening(void);
extern sqInt nilObject(void);
extern sqInt nonIndexablePointerFormat(void);
extern sqInt numBytesOf(sqInt objOop);
extern usqInt numPointerSlotsOf(sqInt objOop);
extern sqInt numPointerSlotsOf(sqInt objOop);
extern usqInt numSlotsOf(sqInt objOop);
extern sqInt numStrongSlotsOfWeakling(sqInt objOop);
extern sqInt objectAfter(sqInt objOop);
Expand Down
49 changes: 27 additions & 22 deletions nsspur64src/vm/gcc3x-cointerp.c
Expand Up @@ -2,11 +2,11 @@


/* Automatically generated by
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.2802 uuid: 599172af-2cce-44a4-9004-23bd36c89807
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.2803 uuid: 6584359e-d7b8-46dd-bb76-b631d9977a57
from
CoInterpreter VMMaker.oscog-eem.2802 uuid: 599172af-2cce-44a4-9004-23bd36c89807
CoInterpreter VMMaker.oscog-eem.2803 uuid: 6584359e-d7b8-46dd-bb76-b631d9977a57
*/
static char __buildInfo[] = "CoInterpreter VMMaker.oscog-eem.2802 uuid: 599172af-2cce-44a4-9004-23bd36c89807 " __DATE__ ;
static char __buildInfo[] = "CoInterpreter VMMaker.oscog-eem.2803 uuid: 6584359e-d7b8-46dd-bb76-b631d9977a57 " __DATE__ ;
char *__interpBuildInfo = __buildInfo;


Expand Down Expand Up @@ -58,6 +58,11 @@ warningat(const char *s, int l) { /* ditto with line number. */
}
#pragma auto_inline(on)

/* Some setjmp.h's, e.g. cygwin's define _setjmp. Undefine to get to our own. */
#if defined(_setjmp)
# undef _setjmp
#endif

/* end StackInterpreter class>>preambleCCode */


Expand Down Expand Up @@ -1259,7 +1264,7 @@ extern sqInt nonIndexablePointerFormat(void);
static sqInt noUnscannedEphemerons(void);
static sqInt NoDbgRegParms numBytesOfBytes(sqInt objOop);
extern sqInt numBytesOf(sqInt objOop);
extern usqInt numPointerSlotsOf(sqInt objOop);
extern sqInt numPointerSlotsOf(sqInt objOop);
static usqInt NoDbgRegParms numSlotsOfAny(sqInt objOop);
extern usqInt numSlotsOf(sqInt objOop);
static sqInt NoDbgRegParms numStrongSlotsOfInephemeral(sqInt objOop);
Expand Down Expand Up @@ -2619,7 +2624,7 @@ sqInt debugCallbackInvokes;
sqInt debugCallbackReturns;
sqInt ffiExceptionResponse;
sqInt checkedPluginName;
const char *interpreterVersion = "Newspeak Virtual Machine [ Open Smalltalk, Spur] CoInterpreterPrimitives_VMMaker.oscog-eem.2802";
const char *interpreterVersion = "Newspeak Virtual Machine [ Open Smalltalk, Spur] CoInterpreterPrimitives_VMMaker.oscog-eem.2803";
sqInt minBackwardJumpCountForCompile = MinBackwardJumpCountForCompile /* 40 */;
int displayWidth;
int displayDepth;
Expand Down Expand Up @@ -41400,7 +41405,7 @@ followForwardedObjectFieldstoDepth(sqInt objOop, sqInt depth)
sqInt header1;
sqInt i;
sqInt numLiterals;
usqInt numSlots;
sqInt numSlots;
usqInt numSlots1;
sqInt oop;
sqInt referent;
Expand Down Expand Up @@ -49129,7 +49134,7 @@ copyObjtoAddrstopAtsavedFirstFieldsindex(sqInt objOop, sqInt segAddr, sqInt endS
sqInt iLimiT;
sqInt methodHeader;
sqInt numLiterals;
usqInt numMediatedSlots;
sqInt numMediatedSlots;
usqInt numSlots;
usqInt numSlots1;
sqInt oop;
Expand Down Expand Up @@ -55664,7 +55669,7 @@ numBytesOf(sqInt objOop)
Works with CompiledMethods, as well as ordinary objects. */

/* SpurMemoryManager>>#numPointerSlotsOf: */
usqInt
sqInt
numPointerSlotsOf(sqInt objOop)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
sqInt contextSize;
Expand Down Expand Up @@ -58900,7 +58905,7 @@ printReferencesTo(sqInt anOop)
assert((ReceiverIndex + ((sp >> 3))) < (lengthOf(objOop1)));
contextSize = (sp >> 3);
l12: /* end fetchStackPointerOf: */;
i = ((usqInt) (CtxtTempFrameStart + contextSize));
i = CtxtTempFrameStart + contextSize;
goto l13;
}
/* begin numSlotsOf: */
Expand Down Expand Up @@ -58933,7 +58938,7 @@ printReferencesTo(sqInt anOop)
/* begin literalCountOfMethodHeader: */
assert((((header) & 7) == 1));
numLiterals = ((header >> 3)) & AlternateHeaderNumLiteralsMask;
i = ((usqInt) (numLiterals + LiteralStart));
i = numLiterals + LiteralStart;
l13: /* end numPointerSlotsOf: */;
while (((i -= 1)) >= 0) {
if (anOop == (longAt((objOop1 + BaseHeaderSize) + (((sqInt)((usqInt)(i) << (shiftForWord()))))))) {
Expand Down Expand Up @@ -58988,7 +58993,7 @@ printReferencesTo(sqInt anOop)
assert((ReceiverIndex + ((sp >> 3))) < (lengthOf(objOop1)));
contextSize = (sp >> 3);
l14: /* end fetchStackPointerOf: */;
i = ((usqInt) (CtxtTempFrameStart + contextSize));
i = CtxtTempFrameStart + contextSize;
goto l15;
}
/* begin numSlotsOf: */
Expand Down Expand Up @@ -59021,7 +59026,7 @@ printReferencesTo(sqInt anOop)
/* begin literalCountOfMethodHeader: */
assert((((header) & 7) == 1));
numLiterals = ((header >> 3)) & AlternateHeaderNumLiteralsMask;
i = ((usqInt) (numLiterals + LiteralStart));
i = numLiterals + LiteralStart;
l15: /* end numPointerSlotsOf: */;
while (((i -= 1)) >= 0) {
if (anOop == (longAt((objOop1 + BaseHeaderSize) + (((sqInt)((usqInt)(i) << (shiftForWord()))))))) {
Expand Down Expand Up @@ -59077,7 +59082,7 @@ printReferencesTo(sqInt anOop)
assert((ReceiverIndex + ((sp >> 3))) < (lengthOf(objOop11)));
contextSize = (sp >> 3);
l16: /* end fetchStackPointerOf: */;
i = ((usqInt) (CtxtTempFrameStart + contextSize));
i = CtxtTempFrameStart + contextSize;
goto l17;
}
/* begin numSlotsOf: */
Expand Down Expand Up @@ -59110,7 +59115,7 @@ printReferencesTo(sqInt anOop)
/* begin literalCountOfMethodHeader: */
assert((((header) & 7) == 1));
numLiterals = ((header >> 3)) & AlternateHeaderNumLiteralsMask;
i = ((usqInt) (numLiterals + LiteralStart));
i = numLiterals + LiteralStart;
l17: /* end numPointerSlotsOf: */;
while (((i -= 1)) >= 0) {
if (anOop == (longAt((objOop11 + BaseHeaderSize) + (((sqInt)((usqInt)(i) << (shiftForWord()))))))) {
Expand Down Expand Up @@ -62243,10 +62248,10 @@ updatePointers(void)
sqInt numLiterals1;
sqInt numLiterals2;
sqInt numLiterals3;
usqInt numPointerSlots;
usqInt numPointerSlots1;
usqInt numPointerSlots2;
usqInt numPointerSlots3;
sqInt numPointerSlots;
sqInt numPointerSlots1;
sqInt numPointerSlots2;
sqInt numPointerSlots3;
usqInt numSlots;
usqInt numSlots1;
usqInt numSlots11;
Expand Down Expand Up @@ -62821,7 +62826,7 @@ updatePointersInsavedFirstFieldPointer(sqInt obj, sqInt firstFieldPtr)
assert((ReceiverIndex + ((sp >> 3))) < (lengthOf(obj)));
contextSize = (sp >> 3);
l6: /* end fetchStackPointerOf: */;
numPointerSlots = ((usqInt) (CtxtTempFrameStart + contextSize));
numPointerSlots = CtxtTempFrameStart + contextSize;
goto l10;
}
/* begin numSlotsOf: */
Expand Down Expand Up @@ -62851,7 +62856,7 @@ updatePointersInsavedFirstFieldPointer(sqInt obj, sqInt firstFieldPtr)
/* begin literalCountOfMethodHeader: */
assert((((header) & 7) == 1));
numLiterals = ((header >> 3)) & AlternateHeaderNumLiteralsMask;
numPointerSlots = ((usqInt) (numLiterals + LiteralStart));
numPointerSlots = numLiterals + LiteralStart;
l10: /* end numPointerSlotsWhileCompactingOf:withFormat:savedFirstFieldPointer: */;
if ((fmt <= 5 /* lastPointerFormat */)
&& (numPointerSlots > 0)) {
Expand Down Expand Up @@ -67429,8 +67434,8 @@ static sqInt
getErrorObjectFromPrimFailCode(void)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
sqInt classIndex;
usqInt clone;
usqInt errObj;
sqInt clone;
sqInt errObj;
sqInt fieldIndex;
sqInt i;
usqInt newObj;
Expand Down
2 changes: 1 addition & 1 deletion nsspursrc/vm/cogit.h
@@ -1,5 +1,5 @@
/* Automatically generated by
CCodeGenerator VMMaker.oscog-eem.2802 uuid: 599172af-2cce-44a4-9004-23bd36c89807
CCodeGenerator VMMaker.oscog-eem.2803 uuid: 6584359e-d7b8-46dd-bb76-b631d9977a57
*/


Expand Down

0 comments on commit 1b896e9

Please sign in to comment.