Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loongarch64 support. #5

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions consolidate.zig
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const zig_targets = [_]ZigTarget{
.{ .arch = .x86_64 , .abi = .gnux32 },
.{ .arch = .riscv64 , .abi = .gnu },
.{ .arch = .sparc64 , .abi = .gnu },
.{ .arch = .loongarch64, .abi = .gnu },

.{ .arch = .s390x , .abi = .gnu },
// zig fmt: on
Expand Down Expand Up @@ -233,6 +234,12 @@ const abi_lists = [_]AbiList{
},
.path = "riscv/rv64",
},
AbiList{
.targets = &[_]ZigTarget{
ZigTarget{ .arch = .loongarch64, .abi = .gnu },
},
.path = "loongarch/lp64",
},
};

/// After glibc 2.33, mips64 put some files inside n64 and n32 directories.
Expand Down Expand Up @@ -267,6 +274,12 @@ const ver23 = Version{
.minor = 23,
};

/// This is the first version that has loongarch64 support.
const ver36 = Version{
.major = 2,
.minor = 36,
};

const Symbol = struct {
type: [lib_names.len][zig_targets.len][versions.len]Type = empty_type,
is_fn: bool = undefined,
Expand Down Expand Up @@ -372,16 +385,21 @@ pub fn main() !void {
if (abi_list.targets[0].arch == .riscv32 and fs_ver.order(ver33) == .lt) {
continue;
}
if (abi_list.targets[0].arch == .loongarch64 and fs_ver.order(ver36) == .lt) {
continue;
}

for (lib_names, 0..) |lib_name, lib_i| {
const lib_prefix = if (std.mem.eql(u8, lib_name, "ld")) "" else "lib";
const basename = try fmt.allocPrint(arena, "{s}{s}.abilist", .{ lib_prefix, lib_name });
const abi_list_filename = blk: {
const is_c = std.mem.eql(u8, lib_name, "c");
const is_dl = std.mem.eql(u8, lib_name, "dl");
const is_m = std.mem.eql(u8, lib_name, "m");
const is_ld = std.mem.eql(u8, lib_name, "ld");
const is_rt = std.mem.eql(u8, lib_name, "rt");
const is_resolv = std.mem.eql(u8, lib_name, "resolv");
const is_util = std.mem.eql(u8, lib_name, "util");

if ((abi_list.targets[0].arch == .mips64 or
abi_list.targets[0].arch == .mips64el) and
Expand Down Expand Up @@ -451,6 +469,13 @@ pub fn main() !void {
break :blk try fmt.allocPrint(arena, "{s}/{s}/{s}{s}{s}.abilist", .{
prefix, abi_list.path, lib_prefix, lib_name, endian_suffix,
});
} else if ((abi_list.targets[0].arch == .loongarch64)) {
if (is_dl) {
continue;
}
if (is_util) {
continue;
}
}

break :blk try fs.path.join(arena, &.{ prefix, abi_list.path, basename });
Expand Down Expand Up @@ -838,7 +863,8 @@ pub fn main() !void {

{
// Function Inclusions
try w.writeIntLittle(u16, @intCast(fn_inclusions.items.len));
var len: u16 = @intCast(fn_inclusions.items.len);
try w.writeIntLittle(u16, len);
var i: usize = 0;
while (i < fn_inclusions.items.len) {
const name = fn_inclusions.items[i].name;
Expand Down Expand Up @@ -874,7 +900,8 @@ pub fn main() !void {

{
// Object Inclusions
try w.writeIntLittle(u16, @intCast(obj_inclusions.items.len));
var len: u16 = @intCast(obj_inclusions.items.len);
try w.writeIntLittle(u16, len);
var i: usize = 0;
while (i < obj_inclusions.items.len) {
const name = obj_inclusions.items[i].name;
Expand Down