diff --git a/asm/preproc.c b/asm/preproc.c index 0ff2b518..7724b12a 100644 --- a/asm/preproc.c +++ b/asm/preproc.c @@ -162,7 +162,38 @@ static bool is_smac_param(enum token_type toktype) * is incorrect, as some token types strip parts of the string, * e.g. indirect tokens. */ +#if 0 #define INLINE_TEXT (7*sizeof(char *)-sizeof(enum token_type)-sizeof(unsigned int)-1) +#define TOKENPACKED +#elif 0 +/* + * The minimum size is enough to hold "%00" and ".nolist", + * as these are compared directly to the Token.text.a field. + * Further, to have Token.text.p.pad be at least one byte, + * INLINE_TEXT must be at least sizeof(char *) long which is + * equal to 8 for long mode. + */ +#define INLINE_TEXT 8 +/* + * If the structures aren't specified as packed the compiler + * will expand struct Token to 32 bytes regardless it appears. + * So to minimise memory usage, pack the structures. + */ +#define TOKENPACKED __attribute__((packed)) +#else +/* + * Setting the token structure size to 32 bytes appears to be + * sufficient to build the lDebug application, hg 7016dd710698, + * with the options -D_SYMBOLIC -D_DUALCODE -D_SYMBOLASMDUALCODE + * as well as -D_DEBUG -D_PM (lDDebugX build, with symbolic + * option and dual code segments). + * + * 64 bytes, the prior default for building the assembler for + * long mode, resulted in the assembler being OOM killed. + */ +#define INLINE_TEXT (32-sizeof(char *)-sizeof(enum token_type)-sizeof(unsigned int)-1) +#define TOKENPACKED +#endif #define MAX_TEXT (INT_MAX-2) struct Token { @@ -171,12 +202,12 @@ struct Token { unsigned int len; union { char a[INLINE_TEXT+1]; - struct { + struct TOKENPACKED { char pad[INLINE_TEXT+1 - sizeof(char *)]; char *ptr; } p; } text; -}; +} TOKENPACKED; /* * Note on the storage of both SMacro and MMacros: the hash table @@ -1766,7 +1797,7 @@ static void delete_Blocks(void) static inline Token *alloc_Token(void) { Token *t; - nasm_new(*t); + nasm_new(t); return t; } @@ -1841,7 +1872,7 @@ static Token *new_Token_free(Token * next, enum token_type type, if (txtlen <= INLINE_TEXT) { memcpy(t->text.a, text, txtlen); - free(text); + nasm_free(text); } else { t->text.p.ptr = text; } @@ -7285,9 +7316,11 @@ static Token *pp_tokline(void) if (mmac) { const Token *t; list_for_each(t, tline) { - if (t->type == TOKEN_PREPROC_ID && + if (t->type == TOKEN_MMACRO_PARAM && !memcmp(t->text.a, "%00", 4)) mmac->capture_label = true; + if (0) printf("t->type=%u t->text.a=%s TOKEN_PREPROC_ID=%u\n", + t->type, t->text.a, TOKEN_PREPROC_ID); } } } else if (istk->conds && !emitting(istk->conds->state)) {