Skip to content

Commit ae9335a

Browse files
author
H. Peter Anvin (Intel)
committed
labels: make the prefix/suffix options and pragmas consistent
Make the spellings for the label-mangling options and pragmas consistent, and implement the directive forms which were documented but never implemented. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
1 parent c08b4ed commit ae9335a

File tree

11 files changed

+115
-49
lines changed

11 files changed

+115
-49
lines changed

Mkfiles/msvc.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ NDISASM = disasm\ndisasm.obj
8686
PROGOBJ = $(NASM) $(NDISASM)
8787
PROGS = nasm$(X) ndisasm$(X)
8888

89-
# Files dependent on extracted warnings
89+
# Files dependent on warnings.dat
9090
WARNOBJ = asm\warnings.obj
9191
WARNFILES = asm\warnings_c.h include\warnings.h doc\warnings.src
9292

Mkfiles/openwcom.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ NDISASM = disasm\ndisasm.obj
7171
PROGOBJ = $(NASM) $(NDISASM)
7272
PROGS = nasm$(X) ndisasm$(X)
7373

74-
# Files dependent on extracted warnings
74+
# Files dependent on warnings.dat
7575
WARNOBJ = asm\warnings.obj
7676
WARNFILES = asm\warnings_c.h include\warnings.h doc\warnings.src
7777

asm/directiv.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,18 @@ bool process_directives(char *directive)
603603
case D_PRAGMA:
604604
process_pragma(value);
605605
break;
606+
607+
case D_PREFIX:
608+
case D_GPREFIX:
609+
case D_SUFFIX:
610+
case D_GSUFFIX:
611+
case D_POSTFIX:
612+
case D_GPOSTFIX:
613+
case D_LPREFIX:
614+
case D_LSUFFIX:
615+
case D_LPOSTFIX:
616+
set_label_mangle(d, value);
617+
break;
606618
}
607619

608620

asm/directiv.dat

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,23 @@ uppercase ; outieee, outobj
8787
#special pragma_tokens
8888

8989
; --- Assembler pragmas
90+
limit
91+
92+
; --- Listing pragmas
93+
options
94+
95+
; --- Common output pragmas
9096
prefix
9197
suffix
98+
postfix
9299
gprefix
93100
gsuffix
101+
gpostfix
94102
lprefix
95103
lsuffix
96-
limit
97-
98-
; --- Listing pragmas
99-
options
104+
lpostfix
100105

101-
; --- Backend pragmas
106+
; --- Backend-specific pragmas
102107
subsections_via_symbols ; macho
103108
no_dead_strip ; macho
104109
maxdump ; dbg

asm/labels.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,45 @@ static inline bool is_global(enum label_type type)
262262
return type == LBL_GLOBAL || type == LBL_COMMON;
263263
}
264264

265+
enum mangle_index {
266+
LM_LPREFIX, /* Local variable prefix */
267+
LM_LSUFFIX, /* Local variable suffix */
268+
LM_GPREFIX, /* Global variable prefix */
269+
LM_GSUFFIX /* GLobal variable suffix */
270+
};
271+
265272
static const char *mangle_strings[] = {"", "", "", ""};
266273
static bool mangle_string_set[ARRAY_SIZE(mangle_strings)];
267274

268275
/*
269276
* Set a prefix or suffix
270277
*/
271-
void set_label_mangle(enum mangle_index which, const char *what)
278+
void set_label_mangle(enum directive how, const char *what)
272279
{
280+
enum mangle_index which;
281+
282+
switch (how) {
283+
case D_PREFIX:
284+
case D_GPREFIX:
285+
which = LM_GPREFIX;
286+
break;
287+
case D_SUFFIX:
288+
case D_GSUFFIX:
289+
case D_POSTFIX:
290+
case D_GPOSTFIX:
291+
which = LM_GSUFFIX;
292+
break;
293+
case D_LPREFIX:
294+
which = LM_LPREFIX;
295+
break;
296+
case D_LSUFFIX:
297+
case D_LPOSTFIX:
298+
which = LM_LSUFFIX;
299+
break;
300+
default:
301+
return;
302+
}
303+
273304
if (mangle_string_set[which])
274305
return; /* Once set, do not change */
275306

asm/nasm.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -932,15 +932,15 @@ static const struct textargs textopts[] = {
932932
{"version", OPT_VERSION, ARG_NO, 0},
933933
{"help", OPT_HELP, ARG_MAYBE, 0},
934934
{"abort-on-panic", OPT_ABORT_ON_PANIC, ARG_NO, 0},
935-
{"prefix", OPT_MANGLE, ARG_YES, LM_GPREFIX},
936-
{"postfix", OPT_MANGLE, ARG_YES, LM_GSUFFIX},
937-
{"suffix", OPT_MANGLE, ARG_YES, LM_GSUFFIX},
938-
{"gprefix", OPT_MANGLE, ARG_YES, LM_GPREFIX},
939-
{"gpostfix", OPT_MANGLE, ARG_YES, LM_GSUFFIX},
940-
{"gsuffix", OPT_MANGLE, ARG_YES, LM_GSUFFIX},
941-
{"lprefix", OPT_MANGLE, ARG_YES, LM_LPREFIX},
942-
{"lpostfix", OPT_MANGLE, ARG_YES, LM_LSUFFIX},
943-
{"lsuffix", OPT_MANGLE, ARG_YES, LM_LSUFFIX},
935+
{"prefix", OPT_MANGLE, ARG_YES, D_PREFIX},
936+
{"postfix", OPT_MANGLE, ARG_YES, D_POSTFIX},
937+
{"suffix", OPT_MANGLE, ARG_YES, D_SUFFIX},
938+
{"gprefix", OPT_MANGLE, ARG_YES, D_GPREFIX},
939+
{"gpostfix", OPT_MANGLE, ARG_YES, D_GPOSTFIX},
940+
{"gsuffix", OPT_MANGLE, ARG_YES, D_GSUFFIX},
941+
{"lprefix", OPT_MANGLE, ARG_YES, D_LPREFIX},
942+
{"lpostfix", OPT_MANGLE, ARG_YES, D_LPOSTFIX},
943+
{"lsuffix", OPT_MANGLE, ARG_YES, D_LSUFFIX},
944944
{"include", OPT_INCLUDE, ARG_YES, 0},
945945
{"pragma", OPT_PRAGMA, ARG_YES, 0},
946946
{"before", OPT_BEFORE, ARG_YES, 0},

asm/pragma.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,14 @@ static enum directive_result output_pragma_common(const struct pragma *pragma)
287287
switch (pragma->opcode) {
288288
case D_PREFIX:
289289
case D_GPREFIX:
290-
set_label_mangle(LM_GPREFIX, pragma->tail);
291-
return DIRR_OK;
292290
case D_SUFFIX:
293291
case D_GSUFFIX:
294-
set_label_mangle(LM_GSUFFIX, pragma->tail);
295-
return DIRR_OK;
292+
case D_POSTFIX:
293+
case D_GPOSTFIX:
296294
case D_LPREFIX:
297-
set_label_mangle(LM_LPREFIX, pragma->tail);
298-
return DIRR_OK;
299295
case D_LSUFFIX:
300-
set_label_mangle(LM_LSUFFIX, pragma->tail);
296+
case D_LPOSTFIX:
297+
set_label_mangle(pragma->opcode, pragma->tail);
301298
return DIRR_OK;
302299
default:
303300
return DIRR_UNKNOWN;

doc/changes.src

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ It is the production version of NASM since 2025.
3636
\b A new \c{--bits} option as convenience shorthand for \c{--before
3737
"BITS ..."}. See \k{opt-bits}.
3838

39-
\b Add aliases \c{--suffix}, \c{--gsuffix} and \c{--lsuffix} for the
40-
corresponding \c{postfix} options. See \k{opt-pfix}.
39+
\b The options and pragmas for configuring external label mangling
40+
were inconsistent, the former using the spelling \c{postfix} and
41+
the latter \c{suffix}. Furthermore, these were also documented as
42+
\e{directives} in addition to pragmas. Implement the already
43+
documented directives (bracketed forms only) and allow both
44+
\c{postfix} and \c{suffix} in all cases.
45+
46+
See \k{opt-pfix} and \k{mangling}.
4147

4248
\b Define additional permissive patterns and fix some opcode bugs.
4349

doc/directiv.src

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -402,26 +402,38 @@ global variables).
402402
Unlike \c{GLOBAL}, \c{STATIC} does not allow object formats to accept
403403
private extensions mentioned in \k{global}.
404404

405-
\H{mangling} \i\c{(G|L)PREFIX}, \i\c{(G|L)POSTFIX}: Mangling Symbols
406-
407-
\c{PREFIX}, \c{GPREFIX}, \c{LPREFIX}, \c{POSTFIX}, \c{GPOSTFIX}, and
408-
\c{LPOSTFIX} directives can prepend or append a string to a certain
405+
\IR{PREFIX} \c{[PREFIX]}
406+
\IC{PREFIX}{GPREFIX} \c{[GPREFIX]}
407+
\IC{PREFIX}{LPREFIX} \c{[LPREFIX]}
408+
\IC{PREFIX}{SUFFIX} \c{[SUFFIX]}
409+
\IC{PREFIX}{GSUFFIX} \c{[GSUFFIX]}
410+
\IC{PREFIX}{LSUFFIX} \c{[LSUFFIX]}
411+
\IC{PREFIX}{POSTFIX} \c{[POSTFIX]}
412+
\IC{PREFIX}{GPOSTFIX} \c{[GPOSTFIX]}
413+
\IC{PREFIX}{LPOSTFIX} \c{[LPOSTFIX]}
414+
415+
\H{mangling} \I{PREFIX}\c{[GL]PREFIX}, \c{[GL]SUFFIX}: Mangling Symbols
416+
417+
\c{[PREFIX}, \c{[GPREFIX}, \c{[LPREFIX}, \c{[SUFFIX}, \c{[GSUFFIX}, and
418+
\c{[LSUFFIX} directives can prepend or append a string to a certain
409419
type of symbols, normally to fit specific ABI conventions
410420

411-
\b\c{PREFIX}|\c{GPREFIX}: Prepend the argument to all \c{EXTERN},
421+
\b\c{[PREFIX}, \c{[GPREFIX}: Prepend the argument to all \c{EXTERN},
412422
\c{COMMON}, \c{STATIC}, and \c{GLOBAL} symbols.
413423

414-
\b\c{LPREFIX}: Prepend the argument to all other symbols
424+
\b\c{[LPREFIX}: Prepend the argument to all other symbols
415425
such as local labels and backend defined symbols.
416426

417-
\b\c{POSTFIX}|\c{GPOSTFIX}: Append the argument to all \c{EXTERN},
418-
\c{COMMON}, \c{STATIC}, and \c{GLOBAL} symbols.
427+
\b\c{[SUFFIX]}, \c{[GSUFFIX]}, \c{[POSTFIX]}, \c{[GPOSTFIX]}: Append
428+
the argument to all \c{EXTERN}, \c{COMMON}, \c{STATIC}, and
429+
\c{GLOBAL} symbols.
419430

420-
\b\c{LPOSTFIX}: Append the argument to all other symbols
431+
\b\c{[LSUFFIX]}, \c{[LPOSTFIX]}: Append the argument to all other symbols
421432
such as local labels and backend defined symbols.
422433

423-
These are macros implemented as pragmas, and using \c{%pragma} syntax
424-
can be restricted to specific backends (see \k{pragma}):
434+
These directives are also implemented as pragmas, and using
435+
\c{%pragma} syntax can be restricted to specific backends (see
436+
\k{pragma}):
425437

426438
\c %pragma macho lprefix L_
427439

@@ -443,13 +455,19 @@ naming scheme to chunk up sections into smaller subsections, each of
443455
which may be eliminated. When the \c{subsections_via_symbols}
444456
directive (\k{macho-ssvs}) is declared, each symbol is the start of a
445457
separate block. The subsection is, then, defined to include sections
446-
before the one that starts with a 'L'. \c{LPREFIX} is useful here to
458+
before the one that starts with a 'L'. \c{[LPREFIX]} is useful here to
447459
mark all local symbols with the 'L' prefix to be excluded to the meta
448460
section. It converts local symbols compatible with the particular
449461
toolchain. Note that local symbols declared with \c{STATIC}
450462
(\k{static}) are excluded from the symbol mangling and also not marked
451463
as global.
452464

465+
Earlier versions of NASM called the pragmas \i\c{suffix} and the
466+
options \i\c{--postfix}, and did not implement directives at all
467+
despite being so documented. Since NASM 3.01, the directive forms are
468+
implemented, and directives, pragmas and options all support all
469+
spellings.
470+
453471

454472
\H{CPU} \i\c{CPU}: Defining CPU Dependencies
455473

doc/running.src

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,13 @@ system calling conventions.
557557

558558
\c{--prefix} is an alias for \c{--gprefix}.
559559

560-
Starting with NASM 3.01, \c{--suffix}, \c{--gsuffix}, and
561-
\c{--lsuffix} are accepted as aliases for the corresponding
562-
\c{postfix} options.
560+
See \k{mangling} for the equivalent directives and pragmas.
561+
562+
Earlier versions of NASM called the pragmas \i\c{suffix} and the
563+
options \i\c{--postfix}, and did not implement directives at all
564+
despite being so documented. Since NASM 3.01, the directive forms are
565+
implemented, and directives, pragmas and options all support all
566+
spellings.
563567

564568

565569
\IR{--pragma} \c{--pragma} option

0 commit comments

Comments
 (0)