From be17d66f76464be9dff0b67d2e924e090661d3e8 Mon Sep 17 00:00:00 2001 From: Alejandro Cabeza Romero Date: Mon, 18 May 2026 19:58:49 +0200 Subject: [PATCH] wip4 --- .github/resources/witness-generator/Makefile | 10 ++++++++-- .github/workflows/ci.yml | 1 - CONTRIBUTING.md | 6 ++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/resources/witness-generator/Makefile b/.github/resources/witness-generator/Makefile index a2a4a59..227f451 100644 --- a/.github/resources/witness-generator/Makefile +++ b/.github/resources/witness-generator/Makefile @@ -54,8 +54,14 @@ windows-lib: $(LIB) # Localizes all circuit-specific code to prevent conflicts when multiple circuit # libraries are linked into the same binary. See CONTRIBUTING.md § "Symbol Isolation". +# On Linux/ELF: llvm-objcopy is required — it clears GRP_COMDAT when localizing +# COMDAT signature symbols, preventing "relocation refers to symbol in discarded +# section" errors that GNU objcopy causes. On Windows/COFF: GNU objcopy suffices +# because COFF COMDAT is per-section (not group-based) and is already deduplicated +# automatically by the linker — the ELF GRP_COMDAT problem does not apply. PUBLIC_SYMS := $(PROJECT)_generate_witness $(PROJECT)_generate_witness_from_files LOCAL_OBJ := $(PROJECT)_local.o +OBJCOPY := $(if $(filter windows,$(OS)),objcopy,llvm-objcopy) UNAME := $(shell uname -s) @@ -65,10 +71,10 @@ $(BIN): $(COMMON_OBJS) $(LIB): $(LIB_OBJS) ifeq ($(UNAME),Darwin) - ar rcs $@ $^ # On macOS two-level namespace, conflicts don't arise + ar rcs $@ $^ # macOS: two-level namespace, conflicts don't arise else ld -r -o $(LOCAL_OBJ) $(filter-out fr.o,$^) - llvm-objcopy $(foreach s,$(PUBLIC_SYMS),--keep-global-symbol=$(s)) $(LOCAL_OBJ) + $(OBJCOPY) $(foreach s,$(PUBLIC_SYMS),--keep-global-symbol=$(s)) $(LOCAL_OBJ) ar rcs $@ fr.o $(LOCAL_OBJ) rm $(LOCAL_OBJ) endif diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33aca01..eb99f99 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -655,7 +655,6 @@ jobs: install: >- base-devel mingw-w64-x86_64-toolchain - mingw-w64-x86_64-llvm make git diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 24f4140..09765e0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -81,6 +81,12 @@ It is safe to deduplicate across circuits — the linker picks one copy, which i On macOS, localization is skipped. macOS uses a two-level namespace by default, meaning symbols are qualified by which library they come from, so the conflict does not arise. +On Windows, GNU `objcopy` (from MinGW binutils) is used instead of `llvm-objcopy`. `llvm-objcopy --keep-global-symbol` +is not supported for COFF objects, but GNU `objcopy --keep-global-symbol` works correctly on COFF — it maps the local +binding to COFF storage class `C_STAT`. The ELF `GRP_COMDAT` problem that required `llvm-objcopy` on Linux does not +apply on Windows: COFF COMDAT is per-section rather than group-based, and the linker already deduplicates it +automatically. + ### Maintenance `PUBLIC_SYMS` is hardcoded to `$(PROJECT)_generate_witness` and `$(PROJECT)_generate_witness_from_files` in the