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

Abierto
#6,297 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
c, go, wasm
Área
compilers

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
17.8k
Forks
1.1k
Merge medio
1 d 4 h
PR fusionados (30 d)
380

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tinygo-org/tinygo

Todos los issues de tinygo-org/tinygo

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.