Open etan-status opened 3 years ago
Is version 1.6 also affected?
This issue still exists on version-1-2
as of Nim v1.2.16, but it doesn't seem that version-1-6
is affected.
The oldest version-1-6
commit that compiles the test code is ee876aee28a93d45f95ae605199b19274eee92c2
(6 Dec 2021), earlier than that would require updates to the sample code.
I'm not sure which Nim commit fixed the issue, or if the problem is just hidden on version-1-6
as a side effect of something else.
I did not manage to produce a minimized example of this issue, but the instruction to reproduce the problem on the bigger example on version-1-2
follow below.
To repro, checkout status-im/nimbus-eth2
commit aa1b8e4a17683d35ded3c3e603c7e9ded5e0eda9
, then:
ulimit -n 1024 && rm -rf ~/.cache ~/.nimble build nimcache vendor .git/modules && git submodule sync --recursive
docker run --rm -v ~/Documents/Repos:/Repos -it i386/ubuntu:20.04
export ARCH=32 PLATFORM=x86 CFLAGS='-m32 -mno-adx' && apt update && apt full-upgrade -y && apt install -y build-essential curl git && cd /Repos/nimbus-eth2 && make -j16 deps ARCH_OVERRIDE=$PLATFORM LOG_LEVEL=TRACE V=1 && source env.sh
hash_tree_root_multi
to hash_tree_root
across entire codebase, including submodulesThen, for each compiler version:
commit={{ NIM_COMPILER_VERSION }}
make -j16 deps NIM_COMMIT=$commit ARCH_OVERRIDE=$PLATFORM LOG_LEVEL=TRACE V=1
nim c -p:vendor/nim-unittest2 -p:vendor/nim-presto -p:vendor/nim-libp2p -p:vendor/nim-nat-traversal -p:vendor/nim-normalize/src -p:vendor/nim-unicodedb/src -p:vendor/nim-toml-serialization -p:vendor/nim-confutils -p:vendor/nim-secp256k1 -p:vendor/nim-zlib -p:vendor/nim-websock -p:vendor/nim-http-utils -p:vendor/nim-json-rpc -p:vendor/nim-metrics -p:vendor/nim-sqlite3-abi -p:vendor/nim-eth -p:vendor/nim-snappy -p:vendor/nim-testutils -p:vendor/nim-bearssl -p:vendor/nim-taskpools -p:vendor/nim-blscurve -p:vendor/nim-web3 -p:vendor/nimcrypto -p:vendor/nim-stint -p:vendor/nim-ssz-serialization -p:vendor/nim-chronos -p:vendor/nim-serialization -p:vendor/nim-json-serialization -p:vendor/nim-faststreams -p:vendor/nim-stew -p:vendor/nim-chronicles -d:disable_libbacktrace -d:PREFER_BLST_SHA256=false --passC:"-m32 -mno-adx" -r tests/consensus_spec/altair/test_fixture_sync_protocol
When passing a
static openArray[uint64]
to another function, in some cases the Nim compiler generates incorrect code if the caller has the same function name. Instead of passing theuint64
array as is, the compiler generates a copy of the array with all data members converted to pointers instead ofNU64
, and passes that copy instead. The callee still interprets the array asNU64[]
. On 32-bit platforms this leads to incorrect followup computations and out-of-bounds memory access (as the 32-bit pointer array is smaller than the 64-bituint64
array).Creating a minimal reproducible example showcasing this bug proved difficult.
Example
Logging an
uint64
openArray at call site and at callee site, with$
:Caller:
Current Output
Callee:
Notes:
Sometimes, 2 is paired with uninitialized memory (and the 0-values can be uninitialized as well).
Expected Output
Possible Solution
Renaming the called function works around the problem.
Additional Information
Generated C code attached (only Nim code difference is the function re-name).
#line 1211
Bugged:
Fixed (renamed function):