authorgravatar for motiejus@jakstys.ltMotiejus Jakštys <motiejus@jakstys.lt> 2023-03-28 20:33:39+03:00
committergravatar for motiejus@jakstys.ltMotiejus Jakštys <motiejus@jakstys.lt> 2023-03-28 22:29:20+03:00
log652e8cf8645c46ec5b5b4e6540f71b9b7e518711
tree5ea13b4734ea6c014eeddd42bd1be5858aea58ed
parent7e6aeead85c0831b054f095f35677abb49e9b984

glibc compat: add a test and README


4 files changed, 67 insertions(+), 0 deletions(-)

lib/libc/glibc/README.md created+8
...@@ -0,0 +1,8 @@
1glibc headers are slightly patched for backwards compatibility. This is not
2good, because it requires to maintain our patchset whlist upgrading glibc.
3
4Until universal headers are real and this file can be removed, these commits
5need to be cherry-picked in the future glibc header upgrades:
6
7- 39083c31a550ed80f369f60d35791e98904b8096
8- a89813ef282c092a9caf699731c7faaf485acabe
test/link.zig+4
...@@ -20,6 +20,10 @@ pub const cases = [_]Case{...@@ -20,6 +20,10 @@ pub const cases = [_]Case{
20 .build_root = "test/link/interdependent_static_c_libs",20 .build_root = "test/link/interdependent_static_c_libs",
21 .import = @import("link/interdependent_static_c_libs/build.zig"),21 .import = @import("link/interdependent_static_c_libs/build.zig"),
22 },22 },
23 .{
24 .build_root = "test/link/glibc_compat",
25 .import = @import("link/glibc_compat/build.zig"),
26 },
2327
24 // WASM Cases28 // WASM Cases
25 .{29 .{
test/link/glibc_compat/build.zig created+18
...@@ -0,0 +1,18 @@
1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 const test_step = b.step("test", "Test");
5 b.default_step = test_step;
6
7 inline for (.{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| {
8 const exe = b.addExecutable(.{
9 .name = t,
10 .root_source_file = .{ .path = "main.c" },
11 .target = std.zig.CrossTarget.parse(
12 .{ .arch_os_abi = t },
13 ) catch unreachable,
14 });
15 exe.linkLibC();
16 test_step.dependOn(&exe.step);
17 }
18}
test/link/glibc_compat/main.c created+37
...@@ -0,0 +1,37 @@
1#define _FILE_OFFSET_BITS 64
2#include <unistd.h>
3#include <fcntl.h>
4#include <stdio.h>
5#include <resolv.h>
6
7int main() {
8 /* in glibc 2.28+ and _FILE_OFFSET_BITS=64 fcntl is #define'd to fcntl64
9 * Thus headers say `fcntl64` exists, but libc.so.6 (the old one)
10 * disagrees, resulting in a linking error unless headers are made
11 * backwards-compatible.
12 *
13 * Glibc 2.28+:
14 * FUNC GLOBAL DEFAULT UND fcntl64@GLIBC_2.28 (3):
15 *
16 * Glibc 2.27 or older:
17 * FUNC GLOBAL DEFAULT UND fcntl@GLIBC_2.2.5
18 */
19 printf("address to fcntl: %p\n", fcntl);
20
21 /* The following functions became symbols of their own right with glibc
22 * 2.34+. Before 2.34 resolv.h would #define res_search __res_search; and
23 * __res_search is a valid symbol since the beginning of time.
24 *
25 * On glibc 2.34+ these symbols are linked this way:
26 * FUNC GLOBAL DEFAULT UND res_search@GLIBC_2.34 (2)
27 *
28 * Pre-glibc 2.34:
29 * FUNC GLOBAL DEFAULT UND __res_search@GLIBC_2.2.5 (4)
30 */
31 printf("address to res_search: %p\n", res_search);
32 printf("address to res_nsearch: %p\n", res_nsearch);
33 printf("address to res_query: %p\n", res_query);
34 printf("address to res_nquery: %p\n", res_nquery);
35 printf("address to res_querydomain: %p\n", res_querydomain);
36 printf("address to res_nquerydomain: %p\n", res_nquerydomain);
37}