Skip to content

Commit f7fccd9

Browse files
willieyzmkannwischer
authored andcommitted
autogen/simpasm: Add support for Intel syntax
- This commit is ported from mlkem-native PR 1275 - This commit extends scripts/simpasm to support the emission of x86_64 assembly in Intel syntax via `--x86-64-syntax intel`, also the CI is extended to exercise this on an x86_64 runner and run the full tests afterwards. Signed-off-by: willieyz <[email protected]>
1 parent 6a4e9c3 commit f7fccd9

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

.github/workflows/base.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,20 @@ jobs:
241241
./scripts/autogen ${{ matrix.simplify.arg }}
242242
make clean
243243
OPT=1 make quickcheck
244+
x86_64_intel_syntax:
245+
name: x86_64 Intel syntax
246+
runs-on: ubuntu-latest
247+
steps:
248+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
249+
- name: Generate with Intel syntax and test
250+
uses: ./.github/actions/setup-shell
251+
with:
252+
nix-shell: 'ci'
253+
gh_token: ${{ secrets.GITHUB_TOKEN }}
254+
script: |
255+
./scripts/autogen --x86-64-syntax intel
256+
make clean
257+
./scripts/tests all
244258
scan-build:
245259
strategy:
246260
fail-fast: false

scripts/autogen

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ def update_via_simpasm(
13771377
preserve_header=True,
13781378
dry_run=False,
13791379
force_cross=False,
1380+
x86_64_syntax="att",
13801381
):
13811382
status_update("simpasm", infile_full)
13821383

@@ -1432,6 +1433,9 @@ def update_via_simpasm(
14321433
cmd += [f'--cflags="{cflags}"']
14331434
if preserve_header is True:
14341435
cmd += ["-p"]
1436+
# Add syntax option for x86_64
1437+
if arch == "x86_64" and x86_64_syntax != "att":
1438+
cmd += ["--syntax", x86_64_syntax]
14351439
r = subprocess.run(
14361440
cmd,
14371441
stdout=subprocess.DEVNULL,
@@ -1542,7 +1546,13 @@ def synchronize_backend(
15421546

15431547

15441548
def synchronize_backends(
1545-
*, dry_run=False, force_cross=False, clean=False, delete=False, no_simplify=False
1549+
*,
1550+
dry_run=False,
1551+
force_cross=False,
1552+
clean=False,
1553+
delete=False,
1554+
no_simplify=False,
1555+
x86_64_syntax="att",
15461556
):
15471557
if clean is False:
15481558
ty = "opt"
@@ -1603,6 +1613,7 @@ def synchronize_backends(
16031613
delete=delete,
16041614
force_cross=force_cross,
16051615
no_simplify=no_simplify,
1616+
x86_64_syntax=x86_64_syntax,
16061617
# Turn off control-flow protection (CET) explicitly. Newer versions of
16071618
# clang turn it on by default and insert endbr64 instructions at every
16081619
# global symbol.
@@ -2226,7 +2237,13 @@ def _main():
22262237
parser.add_argument("--aarch64-clean", default=True, action="store_true")
22272238
parser.add_argument("--no-simplify", default=False, action="store_true")
22282239
parser.add_argument("--force-cross", default=False, action="store_true")
2229-
2240+
parser.add_argument(
2241+
"--x86-64-syntax",
2242+
type=str,
2243+
choices=["att", "intel"],
2244+
default="att",
2245+
help="Assembly syntax for x86_64 disassembly output (att or intel)",
2246+
)
22302247
args = parser.parse_args()
22312248

22322249
os.chdir(os.path.join(os.path.dirname(__file__), ".."))
@@ -2248,6 +2265,7 @@ def _main():
22482265
clean=args.aarch64_clean,
22492266
no_simplify=args.no_simplify,
22502267
force_cross=args.force_cross,
2268+
x86_64_syntax=args.x86_64_syntax,
22512269
)
22522270
high_level_status("Synchronized backends")
22532271

@@ -2264,6 +2282,7 @@ def _main():
22642282
delete=True,
22652283
force_cross=args.force_cross,
22662284
no_simplify=args.no_simplify,
2285+
x86_64_syntax=args.x86_64_syntax,
22672286
)
22682287
high_level_status("Completed final backend synchronization")
22692288
gen_test_configs(args.dry_run)

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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ def simplify(logger, args, asm_input, asm_output=None):
250250
if platform.system() == "Darwin":
251251
cmd += ["--triple=aarch64"]
252252

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

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

275+
# Add syntax specifier for Intel syntax
276+
if args.syntax and args.syntax.lower() == "intel":
277+
autogen_header.append(".intel_syntax noprefix")
278+
271279
if args.preserve_preprocessor_directives is False:
272280
if platform.system() == "Darwin" and sym[0] == "_":
273281
sym = sym[1:]
@@ -414,6 +422,14 @@ def _main():
414422
help="Target architecture for CFI directives",
415423
)
416424

425+
parser.add_argument(
426+
"--syntax",
427+
type=str,
428+
choices=["att", "intel"],
429+
default="att",
430+
help="Assembly syntax for disassembly output (att or intel)",
431+
)
432+
417433
args = parser.parse_args()
418434

419435
os.chdir(os.path.join(os.path.dirname(__file__), ".."))

0 commit comments

Comments
 (0)