nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.54k stars 1.47k forks source link

Seg Fault on cross compiled binary for ARM #23816

Open vortex73 opened 3 months ago

vortex73 commented 3 months ago

Description

Segmentation fault encountered when cross compiling for arm(cortex-a53).

Nim Version

Nim Compiler Version 2.1.1 [Linux: amd64] Compiled at 2024-07-07 Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 1dcc364cd2e284f831735e0fe9b988b08c82ac4f active boot switches: -d:release

Current Output

Traceback (most recent call last)
pasture.nim              pasture
asyncdispatch.nim        waitFor
asyncdispatch.nim        poll
asyncdispatch.nim        runOnce
asyncdispatch.nim        processPendingCallbacks
asyncmacro.nim           processRequest (Async)
asyncmacro.nim           reqHandler (Async)
system.nim               echoBinSafe
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault

Compiler warning:
/usr/bin/arm-linux-gnueabihf-ld: /home/vorrtt3x/.cache/nim/pasture_r/@m..@s..@s..@s.choosenim@stoolchains@snim-@hdevel@slib@spure@snativesockets.nim.c.o: in function `getAddrInfo__pureZnativesockets_u249':
@m..@s..@s..@s.choosenim@stoolchains@snim-@hdevel@slib@spure@snativesockets.nim.c:(.text+0x1284): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

Expected Output

write/read from file system

Possible Solution

No response

Additional Information

I'm trying to r/w requests via asynchttpserver. I've tried compiling with zig cc, gcc toolchains for arm, clang. Even tried using musl-libc. The following is the config I defined as per my knowledge:

switch("gcc.exe", "zig cc")
switch("define", "release")
switch("cpu", "arm")
switch("os", "linux")
switch("passL", "-static")
switch("d", "debug")
switch("stacktrace", "on")

image

Araq commented 3 months ago

And what we're supposed to do with this? You don't provide any source code and "zig cc" is not a GCC anyway.

Maybe your stdout was not opened.

vortex73 commented 3 months ago

You can view the source here.

alex65536 commented 3 months ago

Have you tried to create a minimal reproducer for the issue (i.e. by removing your custom logic, HTTP server and async and checking what exactly is relevant to your bug and what is not)?

Also, note that -static linking with glibc doesn't work well in complex cases (like networking). See this warning:

Compiler warning:
/usr/bin/arm-linux-gnueabihf-ld: /home/vorrtt3x/.cache/nim/pasture_r/@m..@s..@s..@s.choosenim@stoolchains@snim-@hdevel@slib@spure@snativesockets.nim.c.o: in function `getAddrInfo__pureZnativesockets_u249':
@m..@s..@s..@s.choosenim@stoolchains@snim-@hdevel@slib@spure@snativesockets.nim.c:(.text+0x1284): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

Though, I'm unsure whether this is relevant, simple standard IO may work well with statically linked glibc.