cgo: `__attribute__((used))` in a cgo preamble does not link on wasm targets

Aperta
#6,297 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à
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
c, go, wasm
Ambito
compilers

Direzione di ricerca

Start with the cgo preamble reproducer and the llvm.used global that TinyGo builds with llvmutil.AppendToGlobal, which sets no section. Find where the builder links the header snippet bitcode into the package module on wasm targets. Done when the reproducer links for wasip1 and the llvm.used global is given a section compatible with the linked module.

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

Descrizione

A cgo preamble that uses __attribute__((used)) does not link on the wasm, wasip1 and wasip2 targets. The same program links and runs on the host and on cortex-m-qemu.

Reproducer

main.go:

package main

// __attribute__((used)) static int keep = 1;
// int one(void) { return 1; }
import "C"

func main() {
	println(C.one())
}
$ tinygo build -target=wasip1 -o main.wasm .
error: Appending variables with different section name need to be linked!
failed to link module: Linking failed

tinygo version 0.45.0-dev-7a6b6401 linux/amd64 (using go version go1.27.4 and LLVM version 22.1.4)

tinygo version 0.45.0-dev-7a6b6401 darwin/arm64 (using go version go1.27.4 and LLVM version 23.1.5)

Expected

tinygo build -target=wasip1 -o main.wasm . links the program.

Notes

Clang puts llvm.used in the llvm.metadata section:

@llvm.used = appending global [1 x ptr] [ptr @keep], section "llvm.metadata"

TinyGo makes its llvm.used global with llvmutil.AppendToGlobal, which does not set a section. On wasm targets the package module has an llvm.used global before the builder links the bitcode of the header snippet. llvm.LinkModules does not link two appending globals with different sections.

Lingua principale
Go
Stelle
17.8k
Fork
1.1k
Merge medio
1g 4h
PR unite (30g)
380

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 tinygo-org/tinygo

Tutte le issue di tinygo-org/tinygo

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.