Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Disabling intel assembly causes undefined symbols #301

Closed
benbierens opened this issue Nov 21, 2023 · 1 comment · Fixed by #309
Closed

Bug: Disabling intel assembly causes undefined symbols #301

benbierens opened this issue Nov 21, 2023 · 1 comment · Fixed by #309

Comments

@benbierens
Copy link
Contributor

Seen in project codex-storage/nim-codex.
We set use_asm_syntax_intel=false for compatibility with secp256k1. This causes undefined symbols 'u' and 'x'. We are working around it by disabling assembly entirely.
image

mratsim added a commit that referenced this issue Nov 25, 2023
@mratsim
Copy link
Owner

mratsim commented Nov 25, 2023

I can't reproduce in branch gcc-asm which default for testing to LTO = false and AT&T assembly:

proc releaseBuildOptions(useLTO = false): string =
let compiler = if existsEnv"CC": " --cc:" & getEnv"CC"
else: ""
let (useAsmIfAble, force32) = getEnvVars()
let envASM = if not useAsmIfAble: " -d:CTT_ASM=false "
else: ""
let env32 = if force32: " -d:CTT_32 "
else: ""
let lto = if useLTO: " --passC:-flto=auto --passL:-flto=auto "
else: ""
let lto_syntax = if useLTO: " -d:UseAsmSyntaxIntel=true "
else: " -d:UseAsmSyntaxIntel=false "

CI job: https://github.com/mratsim/constantine/actions/runs/6990069731/job/19019218914

Furthermore your screenshot mentions line 303 of limbs_asm_modular_x86 but that file only has 282 lines:

func negmod_asm*(r: var Limbs, a, M: Limbs) =
## Constant-time modular negation
negmod_gen(r, a, M)

Even going back to when this file was created in April 2022, line 303 was behind when isMainModule and so wouldn't create an error:

func negmod_asm*(r: var Limbs, a, m: Limbs) =
## Constant-time modular negation
negmod_gen(r, a, m)
# Sanity checks
# ----------------------------------------------------------
when isMainModule:
import ../../config/type_bigint, algorithm, strutils
proc mainAdd() =
var a = [SecretWord 0xE3DF60E8F6D0AF9A'u64, SecretWord 0x7B2665C2258A7625'u64, SecretWord 0x68FC9A1D0977C8E0'u64, SecretWord 0xF3DC61ED7DE76883'u64]
var b = [SecretWord 0x78E9C2EF58BB6B78'u64, SecretWord 0x547F65BD19014254'u64, SecretWord 0x556A115819EAD4B5'u64, SecretWord 0x8CA844A546935DC3'u64]
var m = [SecretWord 0xFFFFFFFF00000001'u64, SecretWord 0x0000000000000000'u64, SecretWord 0x00000000FFFFFFFF'u64, SecretWord 0xFFFFFFFFFFFFFFFF'u64]
var s = "0x5cc923d94f8c1b11cfa5cb7f3e8bb879be66ab7423629d968084a692c47ac647"
a.reverse()
b.reverse()
m.reverse()

mratsim added a commit that referenced this issue Dec 2, 2023
@mratsim mratsim linked a pull request Dec 2, 2023 that will close this issue
mratsim added a commit that referenced this issue Dec 2, 2023
* use local ASM to avoid incompat with other lib https://github.com/codex-storage/nim-codex/pull/625\#discussion_r1397594279
Implement workaround for Nim v2

* rework LTO usage in .nimble

* allow investigating #301

* disable library LTO as well for reproducing #301

* reactivate upstream LLVM instead of Apple in MacOS CI to solve missing symbol _hasAdxImpl__OOZconstantineZplatformsZisaZcpuinfo95x5654_70

* LTO & ASM: local intel syntax doesn't work + disable LTO for static libraries

* LTO & ASM: improve comments

* LTO & ASM: -flto=thin with LLVM15 does not find enough register in MacOS CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants