Posts
-march=, -mcpu=, and -mtune=
Updated in 2025-05.
In GCC and Clang, there are three major options specifying the architecture and microarchitecture the generated code can run on. The general semantics are described below, but each target machine may assign different semantics.
-march=X: (execution domain) Generate code that can use instructions available in the architecture X-mtune=X: (optimization domain) Optimize for the microarchitecture X, but does not change the ABI or make assumptions about available instructions-mcpu=X: Specify both-march=and-mtune=but can be overridden by the two options. The supported values are generally the same as-mtune=. The architecture name is inferred fromX
glibc and DT_GNU_HASH
Updated in 2026-02.
tl;dr "Easy Anti-Cheat"'s incompatibility with glibc 2.36 provides shared objects (libc.so.6, ld-linux-x86_64.so.2) is an instance of Hyrum's law.
- On 2022-08-02 glibc 2.36 was released.
- On the same day the x86-64 package was moved to
[core]on Arch Linux. - On 2022-08-03 Jelgnum reported that with the new glibc, "Easy Anti-Cheat" cannot load the anti-cheat module (GLIBC update broke EAC for most games that use it).
- Multiple Arch Linux game users confirmed the problem.
- Frogging101 bisected the problem to the glibc commit Do not use --hash-style=both for building glibc shared objects.
- The problem led to heated discussions, some clickbait news, and claims such as "glibc breaks ABI" and "glibc does not prioritize compatibility with pre-existing applications".
I feel compelled to demystify the accident and wish that people can stop defamation to glibc.
…DWARF in reproducible builds
Deterministic builds with clang and lld describes several degrees of build determinism. Here is the description of local determinism:
…Like incremental basic determinism, but builds are also independent of the name of the build directory. Builds of the same source code on the same machine produce exactly the same output every time, independent of the location of the source checkout directory or the build directory.
RISC-V linker relaxation in lld
On 2022-07-07, I added a RISC-V linker relaxation framework in ld.lld and implemented R_RISCV_ALIGN/R_RISCV_CALL/R_RISCV_CALL_PLT relaxation.
The changes will be included in the next llvm-project release 15.0.0.
This post describes the implementation.
See The dark side of RISC-V linker relaxation for more information about RISC-V linker relaxation.
…Everything I know about glibc
Updated in 2025-06.
- Repository: https://sourceware.org/git/gitweb.cgi?p=glibc.git
- Wiki: https://sourceware.org/glibc/wiki/
- Bugzilla: https://sourceware.org/bugzilla/
- Mailing lists:
{libc-announce,libc-alpha,libc-locale,libc-stable,libc-help}@sourceware.org - Patchwork: https://patchwork.sourceware.org/project/glibc/list/ Patch Review Workflow
- Contribution Checklist: https://sourceware.org/glibc/wiki/Contribution%20checklist
- Build bots: https://builder.sourceware.org/buildbot/#/builders, search "glibc"
- public inbox: https://inbox.sourceware.org/libc-alpha/
glibc is an implementation of the user-space side of standard C/POSIX functions with Linux extensions.
…C standard library headers in C++
Updated in 2024-01.
In ISO C++ standards, [support.c.headers.general] says:
Source files that are not intended to also be valid ISO C should not use any of the C headers.
Then, [depr.c.headers] describes how a C header name.h is transformed to the corresponding C++ cname header. There is a helpful example:
[ Example: The header
assuredly provides its declarations and definitions within the namespace std. It may also provide these names within the global namespace. The header <stdlib.h> assuredly provides the same declarations and definitions within the global namespace, much as in the C Standard. It may also provide these names within the namespace std. — end example ]
"may also" in the wording allows implementations to provide mix-and-match, e.g. #include <stdlib.h> may provide std::exit and #include <cstdlib> may provide ::exit.
libstdc++ chooses to enable global namespace declarations with C++ cname header.
For example, #include <cstdlib> also includes the corresponding C header stdlib.h and we get declarations in both the global namespace and the namespace std.
. /usr/include/c++/12/cstdlib
.. /usr/include/stdlib.h
The preprocessed output looks like:
extern void exit (int __status) noexcept (true) __attribute__ ((__noreturn__));
extern "C++"
{
namespace std __attribute__ ((__visibility__ ("default")))
{
using ::exit;
}
}
The compiler knows that the declarations in the namespace std are identical to the ones in the global namespace.
The compiler recognizes some library functions and can optimize them. By using the compiler can optimize some C library functions in the namespace std (e.g. many std::mem* and std::str* functions).
For some C standard library headers, libstdc++ provides wrappers (libstdc++-v3/include/c_compatibility/) which take precedence over the glibc headers.
The configuration of libstdc++ uses --enable-cheaders=c_global by default.
if GLIBCXX_C_HEADERS_C_GLOBAL in libstdc++-v3/include/Makefile.am describes that the 6 wrappers (complex.h, fenv.h, tgmath.h, math.h, stdatomic.h, stdlib.h) shadow the C library headers of the same name.
For example, #include <stdlib.h> includes the wrapper stdlib.h which includes cstdlib, therefore bringing exit into the namespace std.
. /usr/include/c++/12/stdlib.h
.. /usr/include/c++/12/cstdlib
... /usr/include/stdlib.h…
Analysis and introspection options in linkers
Updated in 2026-01.
Reproduce tarball
LLD offers a convenient feature to bundle all input files into a tarball, making it easier to experiment with different linker options. Use either of these commands:
clang -fuse-ld=lld -Wl,--reproduce=/tmp/rep.tar a.o b.o
LLD_REPRODUCE=/tmp/rep.tar clang -fuse-ld=lld a.o b.o
Then unpack the tarball, navigate to the directory, and invoke LLD with the response file:
cd /tmp; tar xf rep.tar; cd rep
ld.lld @response.txt # append options like -y foo
The response file includes the --chroot option, which GNU ld does not support.
In most cases, you can simply remove this option to examine GNU ld's behavior.
ld.bfd @response.txtSymbol related
--trace-symbol=<sym>
Alias: -y sym
lld 14 ELF changes
llvm-project 14 will be released soon. I added some lld/ELF notes to https://github.com/llvm/llvm-project/blob/release/14.x/lld/docs/ReleaseNotes.rst. Here I will elaborate on some changes.
…