Undefined symbol: __libc_csu_* on RHEL8

Let me preface by knowing, there is a possibility that it’s a botched install (it’s a RHEL8 install deployed by my company), but I thought I’d shoot the shot here to see if anyone has any ideas.

First, making a simple file of:

#include <stdio.h>
int main() { printf("TEST\n"); return 0; }

does compile with gcc example.c -o example. Setting verbosity to high, it outputs that the GCC version is `GCC version 8.5.0 (Red Hat 8.5.0-29). Since this is a C program, I presume it copmiles against glibc.

Now, pivoting to zig. I attempt to link against libC with zig, only to run into the errors of:

error: undefined symbol: __libc_csu_fini
    note: referenced by /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o:.text
error: undefined symbol: __libc_csu_init
    note: referenced by /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o:.text

Now, from what I understand, the expectation of those symbols makes sense. As the default installation on RHEL8 is GCC 8 toolchain, then under /usr/lib64/crt1.o it would still have a runtime start up file that expects those symbols in the corresponding glibc.

Now, it is stated that those symbols only disappear starting with glibc==2.34 according to Google. Performing ldd -v I get ldd (GNU libc) 2.28, which would have those symbols. I.e., both my default GCC toolchain and my default Glibc align (which, to me examples why a normal gcc a.c -o a.out works without issue.

But then, I don’t know why the build is not working over zig. From what I understood, zig does support a wide range of glibc versions, including this old. Does anyone have any insight as to what steps I could perform next to debug? E.g. is there some way to know what glibc zig is referencing? (mind you, adding -target x86_64-linux-gnu.2.28 did not seem to help, but grasping at straws).

(tagged with build-system, but unsure if it falls more so under ‘C’)

are you trying to build the C file whose source is here in your post with zig? if so, how: what commands are you running? your post seems to me like it has a lot of extraneous information that AI Google gave you and not a lot of the information that would help us help you

The purpose of my post was to show due diligence in attempting to solve the issue myself. I did use Google, stackoverflow, and Gitlab PR comments to get a rough understanding of what causes the error under normal circumstances. Namely botched installations of glibc or a mismatch between a GCC toolchain version and expected glibc version.
Thus, I then proceeded to do some tests to show my issue isn’t the obvious ones. That’s why I:

  1. showed that a basic GCC compilation works.
  2. That my system glibc version would have the missing symbols. (2.28 < 2.34)

In this way, the hope was to avoid wasting others’ time by covering the easy potential causes myself.

As for a minimum viable example, with zig 0.17.0:

mkdir c-example
cd c-example
zig init

proceed to populate src/main.zig with:

const std = @import("std");

pub fn main(init: std.process.Init) !void {
    _ = init;
    const allocator = std.heap.c_allocator;
    _ = allocator;
}

and execute zig run src/main.zig -lc

This results in the aforementioned

error: undefined symbol: __libc_csu_fini
    note: referenced by /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o:.text
error: undefined symbol: __libc_csu_init
    note: referenced by /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o:.text

Anyways, to answer my own question, using --shown-builtin revealed that the default was using glibc 2.31, somehow. Specifying -target in that situation did work, as did -Dtarget= in my other situation. The latter of which, the issue was my unfamiliarity with how to pass target.

Still somewhat curious as to why, on RHEL8 who’s default is 2.28 zig was picking 2.31 as a default, but I have my workaround so I’ll mark this solved.

Maybe #25415/#31919.

#31919 seems to match pretty well.