1

res_search: fix for aarch64

On linux_aarch64 `res_search` is `__res_search@GLIBC_2.17`, which is
different from the x86_64 counterpart `__res_search@GLIBC_2.2.5`.

Also fix tests.
This commit is contained in:
Motiejus Jakštys 2023-01-18 22:39:35 +02:00
parent a47c7abc96
commit 8d1e1c9fa6
6 changed files with 44 additions and 12 deletions

View File

@ -6,7 +6,6 @@ go_library(
name = "cgo_lib",
srcs = ["cgo.go"],
cgo = True,
clinkopts = ["-lresolv"],
importpath = "git.sr.ht/~motiejus/bazel-zig-cc/test/cgo",
visibility = ["//visibility:private"],
)

View File

@ -1,13 +1,8 @@
package main
// #define _FILE_OFFSET_BITS 64
// #include <unistd.h>
// #include <fcntl.h>
// #include <stdio.h>
// #include <resolv.h>
// char* hello() { return "hello, world"; }
// void phello() { printf("%s, your lucky numbers are %p and %p\n", hello(), fcntl, res_search); }
// #cgo LDFLAGS: -lresolv
// void phello() { printf("%s\n", hello()); }
import "C"
func main() {

22
test/glibc_hacks/BUILD Normal file
View File

@ -0,0 +1,22 @@
load("@bazel-zig-cc//rules:platform.bzl", "platform_binary")
cc_binary(
name = "main",
srcs = ["main.c"],
)
[
(
platform_binary(
name = "main_{}".format(name),
src = "main",
platform = platform,
),
)
for name, platform in [
("linux_amd64_musl", "//libc_aware/platform:linux_amd64_musl"),
("linux_amd64_gnu.2.19", "//libc_aware/platform:linux_amd64_gnu.2.19"),
("linux_amd64_gnu.2.28", "//libc_aware/platform:linux_amd64_gnu.2.28"),
("linux_arm64_musl", "//libc_aware/platform:linux_arm64_musl"),
]
]

13
test/glibc_hacks/main.c Normal file
View File

@ -0,0 +1,13 @@
// This file tests that problematic functions (glibc-hacks) work.
// Also see https://github.com/ziglang/zig/issues/9485
#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <fcntl.h>
#include <resolv.h>
#include <stdio.h>
int main() {
printf("Your lucky numbers are %p and %p\n", fcntl, res_search);
return 0;
}

View File

@ -208,9 +208,12 @@ def _zig_repository_impl(repository_ctx):
fcntl_hack = _glibc_hack("fcntl64", "fcntl@GLIBC_2.2.5")
repository_ctx.file("glibc-hacks/fcntl.map", content = fcntl_hack.mapfile)
repository_ctx.file("glibc-hacks/fcntl.h", content = fcntl_hack.header)
res_search_hack = _glibc_hack("res_search", "__res_search@GLIBC_2.2.5")
repository_ctx.file("glibc-hacks/res_search.map", content = res_search_hack.mapfile)
repository_ctx.file("glibc-hacks/res_search.h", content = res_search_hack.header)
res_search_amd64 = _glibc_hack("res_search", "__res_search@GLIBC_2.2.5")
repository_ctx.file("glibc-hacks/res_search-amd64.map", content = res_search_amd64.mapfile)
repository_ctx.file("glibc-hacks/res_search-amd64.h", content = res_search_amd64.header)
res_search_arm64 = _glibc_hack("res_search", "__res_search@GLIBC_2.17")
repository_ctx.file("glibc-hacks/res_search-arm64.map", content = res_search_arm64.mapfile)
repository_ctx.file("glibc-hacks/res_search-arm64.h", content = res_search_arm64.header)
zig_repository = repository_rule(
attrs = {

View File

@ -128,8 +128,8 @@ def _target_linux_gnu(gocpu, zigcpu, glibc_version):
compiler_extra_includes.append("glibc-hacks/fcntl.h")
linker_version_scripts.append("glibc-hacks/fcntl.map")
if glibc_version < "2.34":
compiler_extra_includes.append("glibc-hacks/res_search.h")
linker_version_scripts.append("glibc-hacks/res_search.map")
compiler_extra_includes.append("glibc-hacks/res_search-{}.h".format(gocpu))
linker_version_scripts.append("glibc-hacks/res_search-{}.map".format(gocpu))
return struct(
gotarget = "linux_{}_{}".format(gocpu, glibc_suffix),