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

gettid() is undeclared (Linux) #23351

Closed
davidebeatrici opened this issue Jan 3, 2025 · 5 comments · Fixed by #23364
Closed

gettid() is undeclared (Linux) #23351

davidebeatrici opened this issue Jan 3, 2025 · 5 comments · Fixed by #23364
Labels
Bug This tag is applied to issues which reports bugs. Build V build error on any OS/CPU architecture.

Comments

@davidebeatrici
Copy link
Contributor

davidebeatrici commented Jan 3, 2025

Describe the bug

A test fails to compile due to the gettid() function being undeclared.

Reproduction Steps

v vlib/v/tests/trace_calls_test.v

Expected Behavior

The test to succeed.

Current Behavior

The test fails to compile:

 FAIL  [2077/2214] C:   447.2 ms, R:   750.467 ms vlib/v/tests/trace_calls_test.v
> trace_fns_only_println compilation output:
================== C compilation error (from cc): ==============
cc: /tmp/v_1001/tsession_7f5da030e740_01JGMW261EACT7W3A17Q67E947/single_println.01JGMW7YBVE9N13HGQ7BHP4SR6.tmp.c:14022:10: error: call to undeclared function 'gettid'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
cc:  14022 |                         tid = gettid();
cc:        |                               ^
cc: 1 error generated.
================================================================

Possible Solution

https://stackoverflow.com/questions/61979901/gcc-warns-about-gettid-syscall-wrapper-with-glibc-2-30-8

Additional Information/Context

No response

V version

0.4.9

Environment details (OS name and version, etc.)

V full version: V 0.4.9 3953445
OS: linux, "OpenMandriva Lx 24.90" (VM)
Processor: 8 cpus, 64bit, little endian, AMD Ryzen 9 5900X 12-Core Processor

getwd: /tmp/v-0.4.9
vexe: /tmp/v-0.4.9/v
vexe mtime: 2025-01-03 01:18:56

vroot: OK, value: /tmp/v-0.4.9
VMODULES: OK, value: /home/user/.vmodules
VTMP: OK, value: /tmp/v_1001

Git version: git version 2.47.1
Git vroot status: 08d5c282-dirty
.git/config present: false

CC version: OpenMandriva 19.1.6-1 clang version 19.1.6 (/builddir/build/BUILD/llvm-19.1.6-build/llvm-project-llvmorg-19.1.6/clang 1cc1c8b2641ccba94c7b90b5e4c4e500729f7556)
emcc version: N/A
thirdparty/tcc: N/A

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Huly®: V_0.6-21782

@davidebeatrici davidebeatrici added the Bug This tag is applied to issues which reports bugs. label Jan 3, 2025
@JalonSolov
Copy link
Contributor

Appears to be just your version of Linux.

On Manjaro, I get this:

$ v vlib/v/tests/trace_calls_test.v
> `-trace-calls -trace-fns PATTERNS` works
------------------------------
> 64bit trace output of vlib/v/tests/testdata/trace_calls/single_println.vv matches line pattern: *hi*
> skipping -m32 compilation since either 32bit headers are not installed, or you do not have gcc installed
------------------------------
> 64bit trace output of vlib/v/tests/testdata/trace_calls/simple.vv matches line pattern: *> trace * C.main*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/simple.vv matches line pattern: *> trace * _vinit*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/simple.vv matches line pattern: *> trace * main main.main/0*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/simple.vv matches line pattern: *> trace * main main.foo/0*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/simple.vv matches line pattern: *> trace * main main.bar/0*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/simple.vv matches line pattern: *> trace * main main.baz/0*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/simple.vv matches line pattern: *> trace * main main.Boo.call_1/1*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/simple.vv matches line pattern: *> trace * builtin eprintln/1*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/simple.vv matches line pattern: *> trace * _vcleanup*
> skipping -m32 compilation since either 32bit headers are not installed, or you do not have gcc installed
------------------------------
> 64bit trace output of vlib/v/tests/testdata/trace_calls/with_modules.vv matches line pattern: *> trace * C.main*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/with_modules.vv matches line pattern: *> trace * _vinit*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/with_modules.vv matches line pattern: *> trace * builtin arguments/0*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/with_modules.vv matches line pattern: *> trace * main main.main/0*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/with_modules.vv matches line pattern: *> trace * main main.f1/0*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/with_modules.vv matches line pattern: *> trace * main main.f2/0*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/with_modules.vv matches line pattern: *> trace * main main.f3/0*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/with_modules.vv matches line pattern: *> trace * os os.join_path/2*
> 64bit trace output of vlib/v/tests/testdata/trace_calls/with_modules.vv matches line pattern: *> trace *_vcleanup*
> skipping -m32 compilation since either 32bit headers are not installed, or you do not have gcc installed
------------------------------
$

@davidebeatrici
Copy link
Contributor Author

Are you using glibc or musl?

@JalonSolov
Copy link
Contributor

glibc

@felipensp
Copy link
Member

felipensp commented Jan 3, 2025

Currently we already do:

#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#include <sys/syscall.h>
#define gettid() syscall(SYS_gettid)
#endif

This was added to fix such error on Debian 10.

@felipensp felipensp added the Build V build error on any OS/CPU architecture. label Jan 3, 2025
@davidebeatrici
Copy link
Contributor Author

davidebeatrici commented Jan 3, 2025

For reference, OpenMandriva currently has glibc 2.40.

v/vlib/v/gen/c/cgen.v

Lines 952 to 957 in c50d4ee

if g.pref.os == .linux {
g.cheaders.writeln('#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30')
g.cheaders.writeln('#include <sys/syscall.h>')
g.cheaders.writeln('#define gettid() syscall(SYS_gettid)')
g.cheaders.writeln('#endif')
}

@felipensp I believe we should either:

  1. Do that for all glibc versions.
  2. Do this for glibc >= 2.30:
#define _GNU_SOURCE
#include <unistd.h>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Build V build error on any OS/CPU architecture.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants