Long story short
When ( cross compiling zig code to kobo ereader and if I use .link_libc = true or exe.linkLibC();, then when I run it (the program) I get a Segmentation fault error message.
Short story long
I was trying to write a program in zig for Kobo Ereader.
When cross compiled and dependent only on zig’'s std library everything worked fine, but each time I tried to include a lib written in c called FBInk, and run the successfully compiled program I got an Segmentation fault message.
Because I don’t have access to gdb or ldd on the target platform I tried cutting down this program to the point where I know that even if I were to not call any external c function (i.e. using printf from stdio lib), but I were to use exe.linkLibC(); I would get an Segmentation fault error while running.
I had tried multiple thing eg. dynamic vs static including that library mentioned before but nothing had worked.
I was even able by using the same target to cross compile a simple c program and run it without any issue.
Platform Info
Surprisingly Kobo Ereaders are using Linux under the hood, which is quite open for any hacking opportunities - not like Kindle.
$ uname -a
Linux kobo 4.9.77 #1 SMP PREEMPT d226bc7bf-20250103T160218-B0103160930 armv7l GNU/Linux
$ ls /lib/libc-*.so
/lib/libc-2.11.1.so
Source Code
build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.resolveTargetQuery(.{
.os_tag = .linux,
.cpu_arch = .arm,
.cpu_model = .{
.explicit = &std.Target.arm.cpu.cortex_a55,
},
.abi = .gnueabihf,
.glibc_version = .{
//.major = 2,
//.minor = 11,
//.patch = 1,
.major = 2,
.minor = 16,
.patch = 0
}
});
const optimize = b.standardOptimizeOption(.{});
const rebend = b.addExecutable(.{
.name = "rebend",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
rebend.linkLibC(); // Results in Segfault
b.installArtifact(rebend);
const rebend_c = b.addExecutable(.{
.name = "rebend-c",
.target = target,
.optimize = optimize,
});
rebend_c.addCSourceFiles(.{
.root = b.path("src"),
.files = &.{
"main.c"
},
});
rebend_c.linkLibC();
b.installArtifact(rebend_c);
}
src/main.zig
const std = @import("std");
pub fn main() !void {
std.debug.print("Help World\n", .{});
}
src/main.c
#include <stdio.h>
int main() {
printf("Hello World\n");
return 0;
}
Run
[root@kobo reband]# ./rebend
Segmentation fault
[root@kobo reband]# ./rebend-c
Hello World