libc
v1.82.14
Documentation
pkg.go.dev ↗Package libc is a partial reimplementation of C libc in pure Go.
READ THIS BEFORE UPGRADING
This package is to ccgo what the runtime package is to Go. It is not a library you happen to link against, it is the other half of the compiler. Code that ccgo produced and the libc it was produced for are one artifact split across two modules, and they are only ever tested as a pair.
That is why the version numbers here do not mean what semver says they mean. A release that bumps only the patch or the minor number can still change the contract between generated code and this package, which by semver's own rules it must not. Read every libc version as though it were a major one.
None of this is new. It has been documented for as long as this package has carried ccgo's runtime, and it holds for every release. What is new is how it fails.
Upgrading libc alone used to change behaviour quietly. It can now stop the build. The setjmp/longjmp support changed shape: LongjmpRetval went from an integer to a struct naming the jump buffer a longjmp targeted, because a region recovering that panic has no other way to tell whether the longjmp was meant for it or for a setjmp further out, and recovering one meant for another region resumes the program at the wrong place. Code generated by an older ccgo does not compile against it, failing on the conversion between LongjmpRetval and int32. That is the intended outcome rather than an oversight: a refusal to build, in place of a program that would have built and then jumped to the wrong setjmp.
This is a correctness fix and there is no backward compatible way to make it. Deciding which region a longjmp belongs to needs information the old panic value did not carry, so any fix has to change what that value is. Keeping the old shape working alongside the new one would leave every consumer silently on the broken path, which is the bug.
The remedy is what it has always been, and it is not to pin an old libc and hope: recompile your C to Go with a ccgo new enough to depend on the libc you want, then use that pair together. If you consume translated code produced by someone else, modernc.org/sqlite for instance, take the libc version from that package's go.mod and do not bump it on your own just because a newer libc is tagged.
Package libc provides run time support for programs generated by the ccgo C to Go transpiler, version 4 or later.
Concurrency
Many C libc functions are not thread safe. Such functions are not safe for concurrent use by multiple goroutines in the Go translation as well.
Thread Local Storage
C threads are modeled as Go goroutines. Every such C thread, ie. a Go goroutine, must use its own Thread Local Storage instance implemented by the TLS type.
Signals
A handler that C code installs with signal or sigaction gets the signal through os/signal. It runs on the C thread that installed it, at that thread's next check point: when a function that took stack memory from its TLS returns, and in some native routines such as fabs. Unlike in C, a handler does not interrupt the code running at the time, so a loop that reaches no check point, an interpreter running an empty endless loop for example, never runs it. A Go program that must handle such a signal promptly can catch it with os/signal itself.
Environmental variables
This package synchronizes its environ with the current Go environ lazily and only once.
libc API documentation copyright
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Since the Linux kernel and libraries are constantly changing, this manual page may be incorrect or out-of-date. The author(s) assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. The author(s) may not have taken the same level of care in the production of this manual, which is licensed free of charge, as they might when working professionally. Formatted or processed versions of this manual, if unaccompanied by the source, must acknowledge the copyright and authors of this work.
Constants
ABDAY_1
const ABDAY_1 = 131072
ABDAY_2
const ABDAY_2 = 131073
ABDAY_3
const ABDAY_3 = 131074
ABDAY_4
const ABDAY_4 = 131075
ABDAY_5
const ABDAY_5 = 131076
ABDAY_6
const ABDAY_6 = 131077
ABDAY_7
const ABDAY_7 = 131078
ABMON_1
const ABMON_1 = 131086
ABMON_10
const ABMON_10 = 131095
ABMON_11
const ABMON_11 = 131096
ABMON_12
const ABMON_12 = 131097
ABMON_2
const ABMON_2 = 131087
ABMON_3
const ABMON_3 = 131088
ABMON_4
const ABMON_4 = 131089
ABMON_5
const ABMON_5 = 131090
ABMON_6
const ABMON_6 = 131091
ABMON_7
const ABMON_7 = 131092
ABMON_8
const ABMON_8 = 131093
ABMON_9
const ABMON_9 = 131094
ABUF_SIZE
const ABUF_SIZE = 4800
ACCOUNTING
const ACCOUNTING = 9
ADD
const ADD = 1
ADDR_COMPAT_LAYOUT
const ADDR_COMPAT_LAYOUT = 2097152
ADDR_LIMIT_32BIT
const ADDR_LIMIT_32BIT = 8388608
ADDR_LIMIT_3GB
const ADDR_LIMIT_3GB = 134217728
ADDR_NO_RANDOMIZE
const ADDR_NO_RANDOMIZE = 262144
ADJ_ESTERROR
const ADJ_ESTERROR = 8
ADJ_FREQUENCY
const ADJ_FREQUENCY = 2
ADJ_MAXERROR
const ADJ_MAXERROR = 4
ADJ_MICRO
const ADJ_MICRO = 4096
ADJ_NANO
const ADJ_NANO = 8192
ADJ_OFFSET
const ADJ_OFFSET = 1
ADJ_OFFSET_SINGLESHOT
const ADJ_OFFSET_SINGLESHOT = 32769
ADJ_OFFSET_SS_READ
const ADJ_OFFSET_SS_READ = 40961
ADJ_SETOFFSET
const ADJ_SETOFFSET = 256
ADJ_STATUS
const ADJ_STATUS = 16
ADJ_TAI
const ADJ_TAI = 128
ADJ_TICK
const ADJ_TICK = 16384
ADJ_TIMECONST
const ADJ_TIMECONST = 32
AF_ALG
const AF_ALG = 38