Skip to content

Commit dfa73e7

Browse files
hanno-beckermkannwischer
authored andcommitted
autogen/simpasm: Add support for Intel syntax
This commit extends scripts/simpasm to support the emission of x86_64 assembly in Intel syntax via --x86-64-syntax intel. The CI is extended to exercise this on an x86_64 runner and run the full tests afterwards. This can be useful for consuming libraries wishing to use a different syntax than what mlkem-native uses. A similar approach may be usable in the future to add assembly suitable for the Windows assembler. Signed-off-by: Hanno Becker <[email protected]>
1 parent f778c9d commit dfa73e7

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

.github/workflows/base.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,20 @@ jobs:
279279
./scripts/autogen ${{ matrix.backend.arg }} ${{ matrix.simplify.arg }}
280280
make clean
281281
OPT=1 make quickcheck
282+
x86_64_intel_syntax:
283+
name: x86_64 Intel syntax
284+
runs-on: ubuntu-latest
285+
steps:
286+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
287+
- name: Generate with Intel syntax and test
288+
uses: ./.github/actions/setup-shell
289+
with:
290+
nix-shell: 'ci'
291+
gh_token: ${{ secrets.GITHUB_TOKEN }}
292+
script: |
293+
./scripts/autogen --x86-64-syntax intel
294+
make clean
295+
./scripts/tests all
282296
scan-build:
283297
strategy:
284298
fail-fast: false

scripts/autogen

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,7 @@ def update_via_simpasm(
19161916
preserve_header=True,
19171917
dry_run=False,
19181918
force_cross=False,
1919+
x86_64_syntax="att",
19191920
):
19201921
status_update("simpasm", infile_full)
19211922

@@ -1971,6 +1972,9 @@ def update_via_simpasm(
19711972
cmd += [f'--cflags="{cflags}"']
19721973
if preserve_header is True:
19731974
cmd += ["-p"]
1975+
# Add syntax option for x86_64
1976+
if arch == "x86_64" and x86_64_syntax != "att":
1977+
cmd += ["--syntax", x86_64_syntax]
19741978
r = subprocess.run(
19751979
cmd,
19761980
stdout=subprocess.DEVNULL,
@@ -2194,7 +2198,13 @@ def synchronize_backend(
21942198

21952199

21962200
def synchronize_backends(
2197-
*, dry_run=False, force_cross=False, clean=False, delete=False, no_simplify=False
2201+
*,
2202+
dry_run=False,
2203+
force_cross=False,
2204+
clean=False,
2205+
delete=False,
2206+
no_simplify=False,
2207+
x86_64_syntax="att",
21982208
):
21992209
if clean is False:
22002210
ty = "opt"
@@ -2255,6 +2265,7 @@ def synchronize_backends(
22552265
delete=delete,
22562266
force_cross=force_cross,
22572267
no_simplify=no_simplify,
2268+
x86_64_syntax=x86_64_syntax,
22582269
# Turn off control-flow protection (CET) explicitly. Newer versions of
22592270
# clang turn it on by default and insert endbr64 instructions at every
22602271
# global symbol.
@@ -3068,6 +3079,13 @@ def _main():
30683079
parser.add_argument("--aarch64-clean", default=False, action="store_true")
30693080
parser.add_argument("--no-simplify", default=False, action="store_true")
30703081
parser.add_argument("--force-cross", default=False, action="store_true")
3082+
parser.add_argument(
3083+
"--x86-64-syntax",
3084+
type=str,
3085+
choices=["att", "intel"],
3086+
default="att",
3087+
help="Assembly syntax for x86_64 disassembly output (att or intel)",
3088+
)
30713089

30723090
args = parser.parse_args()
30733091

@@ -3110,6 +3128,7 @@ def _main():
31103128
clean=args.aarch64_clean,
31113129
no_simplify=args.no_simplify,
31123130
force_cross=args.force_cross,
3131+
x86_64_syntax=args.x86_64_syntax,
31133132
)
31143133
high_level_status("Synchronized backends")
31153134

@@ -3129,6 +3148,7 @@ def _main():
31293148
delete=True,
31303149
force_cross=args.force_cross,
31313150
no_simplify=args.no_simplify,
3151+
x86_64_syntax=args.x86_64_syntax,
31323152
)
31333153
high_level_status("Completed final backend synchronization")
31343154

scripts/cfify

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ def add_cfi_directives(text, arch):
217217
i += 1
218218
continue
219219

220-
# x86_64: retq -> .cfi_endproc after retq
221-
match = re.match(r"(\s*)retq\s*$", line, re.IGNORECASE)
220+
# x86_64: ret/retq -> .cfi_endproc after ret
221+
match = re.match(r"(\s*)retq?\s*$", line, re.IGNORECASE)
222222
if match:
223223
indent = match.group(1)
224224
result.append(line)

scripts/simpasm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ def simplify(logger, args, asm_input, asm_output=None):
249249
if platform.system() == "Darwin":
250250
cmd += ["--triple=aarch64"]
251251

252+
# Add syntax option if specified
253+
if args.syntax and args.syntax.lower() != "att":
254+
cmd += [f"--x86-asm-syntax={args.syntax}"]
255+
252256
logger.debug(f"Disassembling temporary object file {tmp_objfile0} ...")
253257
disasm = run_cmd(cmd).stdout
254258

@@ -267,6 +271,10 @@ def simplify(logger, args, asm_input, asm_output=None):
267271
".balign 4",
268272
]
269273

274+
# Add syntax specifier for Intel syntax
275+
if args.syntax and args.syntax.lower() == "intel":
276+
autogen_header.append(".intel_syntax noprefix")
277+
270278
if args.preserve_preprocessor_directives is False:
271279
if platform.system() == "Darwin" and sym[0] == "_":
272280
sym = sym[1:]
@@ -412,6 +420,13 @@ def _main():
412420
default="aarch64",
413421
help="Target architecture for CFI directives",
414422
)
423+
parser.add_argument(
424+
"--syntax",
425+
type=str,
426+
choices=["att", "intel"],
427+
default="att",
428+
help="Assembly syntax for disassembly output (att or intel)",
429+
)
415430

416431
args = parser.parse_args()
417432

0 commit comments

Comments
 (0)