Merge pull request #8737 from ifreund/link-system-libc

stage2: use system libc when targeting the native OS/ABI
This commit is contained in:
Andrew Kelley 2021-05-11 20:28:14 -04:00 committed by GitHub
commit e3dd4dc91d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 19 deletions

View File

@ -55,11 +55,11 @@ cmake .. \
-DZIG_TARGET_MCPU="$HOST_MCPU" \
-DZIG_STATIC=ON
make $JOBS install
unset CC
unset CXX
make $JOBS install
# Build zig compiler cross-compiled for arm64
cd $ZIGDIR
@ -79,11 +79,11 @@ cmake .. \
-DZIG_EXECUTABLE="$ZIG" \
-DZIG_STATIC=ON
make $JOBS install
unset CC
unset CXX
make $JOBS install
if [ "${BUILD_REASON}" != "PullRequest" ]; then
mv ../LICENSE release/

View File

@ -848,7 +848,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
arena,
options.zig_lib_directory.path.?,
options.target,
options.is_native_os,
options.is_native_abi,
link_libc,
options.libc_installation,
);
@ -2885,7 +2885,7 @@ fn detectLibCIncludeDirs(
arena: *Allocator,
zig_lib_dir: []const u8,
target: Target,
is_native_os: bool,
is_native_abi: bool,
link_libc: bool,
libc_installation: ?*const LibCInstallation,
) !LibCDirs {
@ -2900,6 +2900,12 @@ fn detectLibCIncludeDirs(
return detectLibCFromLibCInstallation(arena, target, lci);
}
if (is_native_abi) {
const libc = try arena.create(LibCInstallation);
libc.* = try LibCInstallation.findNative(.{ .allocator = arena });
return detectLibCFromLibCInstallation(arena, target, libc);
}
if (target_util.canBuildLibC(target)) {
const generic_name = target_util.libCGenericName(target);
// Some architectures are handled by the same set of headers.
@ -2950,12 +2956,6 @@ fn detectLibCIncludeDirs(
};
}
if (is_native_os) {
const libc = try arena.create(LibCInstallation);
libc.* = try LibCInstallation.findNative(.{ .allocator = arena });
return detectLibCFromLibCInstallation(arena, target, libc);
}
return LibCDirs{
.libc_include_dir_list = &[0][]u8{},
.libc_installation = null,

View File

@ -764,16 +764,17 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
.lt => continue,
.gt => {
// TODO Expose via compile error mechanism instead of log.
std.log.warn("invalid target glibc version: {}", .{target_version});
std.log.err("invalid target glibc version: {}", .{target_version});
return error.InvalidTargetGLibCVersion;
},
}
} else blk: {
} else {
const latest_index = metadata.all_versions.len - 1;
std.log.warn("zig cannot build new glibc version {}; providing instead {}", .{
// TODO Expose via compile error mechanism instead of log.
std.log.err("zig does not yet provide glibc version {}, the max provided version is {}", .{
target_version, metadata.all_versions[latest_index],
});
break :blk latest_index;
return error.InvalidTargetGLibCVersion;
};
{
var map_contents = std.ArrayList(u8).init(arena);

View File

@ -1650,9 +1650,15 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
if (self.base.options.libc_installation != null) {
const needs_grouping = self.base.options.link_mode == .Static;
if (needs_grouping) try argv.append("--start-group");
try argv.append("-lm");
try argv.append("-lpthread");
try argv.append("-lc");
// This matches the order of glibc.libs
try argv.appendSlice(&[_][]const u8{
"-lm",
"-lpthread",
"-lc",
"-ldl",
"-lrt",
"-lutil",
});
if (needs_grouping) try argv.append("--end-group");
} else if (target.isGnuLibC()) {
try argv.append(comp.libunwind_static_lib.?.full_object_path);