This commit is contained in:
Alejandro Cabeza Romero 2026-05-18 19:58:49 +02:00
parent 5a8dd7a83d
commit be17d66f76
No known key found for this signature in database
GPG Key ID: DA3D14AE478030FD
3 changed files with 14 additions and 3 deletions

View File

@ -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

View File

@ -655,7 +655,6 @@ jobs:
install: >-
base-devel
mingw-w64-x86_64-toolchain
mingw-w64-x86_64-llvm
make
git

View File

@ -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