forked from ziglang/zig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
glibc: add backwards compatibility for some symbols
- `fcntl` was renamed to `fcntl64` in glibc 2.28 (see ziglang#9485) - `res_{,n}{search,query,querydomain}` became "their own" symbols since glibc 2.34: they were prefixed with `__` before. This PR makes it possible to use `fcntl` with glibc 2.27 or older and the `res_*` functions with glibc 2.33 or older. These patches will become redundant with universal-headers and can be dropped. But we have to do with what we have now. Closes ziglang#9485 Related: 39083c3
- Loading branch information
Showing
6 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) void { | ||
const test_step = b.step("test", "Test"); | ||
b.default_step = test_step; | ||
|
||
const targets: []const []const u8 = &.{ | ||
"aarch64-linux-gnu.2.27", | ||
"aarch64-linux-gnu.2.28", | ||
"aarch64-linux-gnu.2.33", | ||
"aarch64-linux-gnu.2.34", | ||
}; | ||
|
||
for (targets) |target| { | ||
const exe = b.addExecutable(.{ | ||
.name = target, | ||
.root_source_file = .{ .path = "main.c" }, | ||
.target = std.zig.CrossTarget.parse( | ||
.{ .arch_os_abi = target }, | ||
) catch unreachable, | ||
}); | ||
exe.linkLibC(); | ||
test_step.dependOn(&exe.step); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#define _FILE_OFFSET_BITS 64 | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <resolv.h> | ||
|
||
int main() { | ||
/* in glibc 2.28+ and _FILE_OFFSET_BITS=64 fcntl is #define'd to fcntl64 | ||
* Thus headers say `fcntl64` exists, but libc.so.6 (the old one) | ||
* disagrees, resulting in a linking error unless headers are made | ||
* backwards-compatible. | ||
* | ||
* Glibc 2.28+: | ||
* FUNC GLOBAL DEFAULT UND fcntl64@GLIBC_2.28 (3): | ||
* | ||
* Glibc 2.27 or older: | ||
* FUNC GLOBAL DEFAULT UND fcntl@GLIBC_2.2.5 | ||
*/ | ||
printf("address to fcntl: %p\n", fcntl); | ||
|
||
/* The following functions became symbols of their own right with glibc | ||
* 2.34+. Before 2.34 resolv.h would #define res_search __res_search; and | ||
* __res_search is a valid symbol since the beginning of time. | ||
* | ||
* On glibc 2.34+ these symbols are linked this way: | ||
* FUNC GLOBAL DEFAULT UND res_search@GLIBC_2.34 (2) | ||
* | ||
* Pre-glibc 2.34: | ||
* FUNC GLOBAL DEFAULT UND __res_search@GLIBC_2.2.5 (4) | ||
*/ | ||
printf("address to res_search: %p\n", res_search); | ||
printf("address to res_nsearch: %p\n", res_nsearch); | ||
printf("address to res_query: %p\n", res_query); | ||
printf("address to res_nquery: %p\n", res_nquery); | ||
printf("address to res_querydomain: %p\n", res_querydomain); | ||
printf("address to res_nquerydomain: %p\n", res_nquerydomain); | ||
} |