bug: --target windows: stack-map rewriter refuses COFF alias symbol records (`.def`/`.scl`/`.endef`) after .llvm_stackmaps for $pshape method aliases

Aperta Adatta ai principianti
#14,982 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust, typescript
Ambito
backend, compilers

Direzione di ricerca

Inizia da crates/perry-codegen/src/gc_map.rs e leggi is_zero_width_directive, che l’issue indica come il punto in cui gestire i record dei simboli COFF. Controlla la gestione attuale delle direttive e i test del riscrittore delle stack map, quindi riproduci il problema con l’esempio TypeScript fornito e il comando di compilazione per Windows. Il lavoro è concluso quando le direttive COFF elencate non provocano più l’errore di analisi e la riscrittura delle stack map continua a preservare le radici GC.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area:compiler effort:S impact:med platform:windows type:bug

Summary

On --target windows (COFF), a class whose method's $pshape clone has the same body as the ordinary method fails to compile. The error is "unrecognised directive .def inside the stack-map block".

What happens: inprocess/equivalent_shape_bodies.rs replaces the $pshape clone with an external LLVM alias of the method. On COFF, LLVM prints the alias's symbol record after .llvm_stackmaps:

.globl  <sym>
.def    <sym>;
.scl    2;
.type   32;
.endef
<sym> = <method>

The compact stack-map rewriter in crates/perry-codegen/src/gc_map.rs accepts .type and sym = expr, but not .def / .scl / .endef, so it refuses the module. This is the COFF counterpart of the Mach-O .alt_entry alias case (#12736).

Reproduction

coff_pshape_alias.ts:

// A method whose `$pshape` capability body equals the ordinary body becomes
// an LLVM alias after optimization. On COFF its symbol record
// (`.def`/`.scl`/`.type`/`.endef`) prints after the stack map; the
// Windows-target compile regression assembles this module.
export class Img {
  private template = false;
  setTemplateImage(option: boolean): void {
    this.template = option;
  }
  isTemplateImage(): boolean {
    return this.template;
  }
}
const image = new Img();
image.setTemplateImage(true);
console.log(image.isTemplateImage());
perry compile coff_pshape_alias.ts --target windows --no-link -o c.o
perry: this module emits an LLVM stack map that the compact-map rewriter could not parse, so its GC roots would be invisible to the collector (the runtime reads only the compact section). Refusing to emit a binary that would lose roots silently.
reason: line 5440: unrecognised directive `.def` inside the stack-map block (`.def	perry_method_coff_pshape_alias_ts__Img__setTemplateImage$pshape;`). [...] Add it to `directive_width` (with its width) or to `is_zero_width_directive`.

No special settings are needed. It fails the same way with the default settings, with PERRY_LL_OPT_LEVEL=0, with PERRY_LLVM_INPROCESS=1, and with both.

Suggested fix

Treat .def, .scl, .endef (and .safeseh) as zero-width in is_zero_width_directive. They only build COFF symbol-table records and emit no section bytes, so they can be carried through verbatim, as .type already is.

Environment

  • PerryTS/perry main 86988bec62 (pristine, current head). Linux host build (cargo build --release -p perry --no-default-features --features dev-cli plus the runtime/stdlib static archives), cross-compiling with --target windows.
  • Linux x86_64, Ubuntu 24.04.
Lingua principale
Rust
Stelle
4.9k
Fork
166
Merge medio
4h 54m
PR unite (30g)
909

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PerryTS/perry

Tutte le issue di PerryTS/perry

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.