Skip to content

Commit 6fc5608

Browse files
authored
Merge branch 'master' into opt-index-of-diff
2 parents 024a316 + e96d860 commit 6fc5608

File tree

10 files changed

+322
-189
lines changed

10 files changed

+322
-189
lines changed

lib/std/zig/AstGen.zig

Lines changed: 119 additions & 84 deletions
Large diffs are not rendered by default.

src/Package.zig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ pub const Hash = struct {
6666

6767
pub fn toSlice(ph: *const Hash) []const u8 {
6868
var end: usize = ph.bytes.len;
69-
while (true) {
69+
while (end > 0) {
7070
end -= 1;
7171
if (ph.bytes[end] != 0) return ph.bytes[0 .. end + 1];
7272
}
73+
return ph.bytes[0..0];
7374
}
7475

7576
pub fn eql(a: *const Hash, b: *const Hash) bool {
@@ -195,6 +196,11 @@ test Hash {
195196
try std.testing.expectEqualStrings("nasm-2.16.1-3-vrr-ygAAoADH9XG3tOdvPNuHen_d-XeHndOG-nNXmved", result.toSlice());
196197
}
197198

199+
test "empty hash" {
200+
const hash = Hash.fromSlice("");
201+
try std.testing.expectEqualStrings("", hash.toSlice());
202+
}
203+
198204
test {
199205
_ = Fetch;
200206
}

src/Package/Fetch.zig

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,14 +568,14 @@ fn runResource(
568568
const actual_hex = Package.multiHashHexDigest(f.computed_hash.digest);
569569
if (!std.mem.eql(u8, declared_hash.toSlice(), &actual_hex)) {
570570
return f.fail(hash_tok, try eb.printString(
571-
"hash mismatch: manifest declares {s} but the fetched package has {s}",
571+
"hash mismatch: manifest declares '{s}' but the fetched package has '{s}'",
572572
.{ declared_hash.toSlice(), actual_hex },
573573
));
574574
}
575575
} else {
576576
if (!computed_package_hash.eql(&declared_hash)) {
577577
return f.fail(hash_tok, try eb.printString(
578-
"hash mismatch: manifest declares {s} but the fetched package has {s}",
578+
"hash mismatch: manifest declares '{s}' but the fetched package has '{s}'",
579579
.{ declared_hash.toSlice(), computed_package_hash.toSlice() },
580580
));
581581
}
@@ -726,6 +726,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
726726
.hash = h: {
727727
const h = dep.hash orelse break :h null;
728728
const pkg_hash: Package.Hash = .fromSlice(h);
729+
if (h.len == 0) break :h pkg_hash;
729730
const gop = f.job_queue.table.getOrPutAssumeCapacity(pkg_hash);
730731
if (gop.found_existing) {
731732
if (!dep.lazy) {
@@ -908,6 +909,7 @@ const FileType = enum {
908909
if (ascii.endsWithIgnoreCase(file_path, ".tzst")) return .@"tar.zst";
909910
if (ascii.endsWithIgnoreCase(file_path, ".tar.zst")) return .@"tar.zst";
910911
if (ascii.endsWithIgnoreCase(file_path, ".zip")) return .zip;
912+
if (ascii.endsWithIgnoreCase(file_path, ".jar")) return .zip;
911913
return null;
912914
}
913915

@@ -1130,6 +1132,9 @@ fn unpackResource(
11301132
if (ascii.eqlIgnoreCase(mime_type, "application/zip"))
11311133
break :ft .zip;
11321134

1135+
if (ascii.eqlIgnoreCase(mime_type, "application/java-archive"))
1136+
break :ft .zip;
1137+
11331138
if (!ascii.eqlIgnoreCase(mime_type, "application/octet-stream") and
11341139
!ascii.eqlIgnoreCase(mime_type, "application/x-compressed"))
11351140
{

src/link.zig

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,35 +2294,35 @@ fn resolvePathInputLib(
22942294
const test_path: Path = pq.path;
22952295
// In the case of shared libraries, they might actually be "linker scripts"
22962296
// that contain references to other libraries.
2297-
if (pq.query.allow_so_scripts and target.ofmt == .elf and
2298-
Compilation.classifyFileExt(test_path.sub_path) == .shared_library)
2299-
{
2297+
if (pq.query.allow_so_scripts and target.ofmt == .elf and switch (Compilation.classifyFileExt(test_path.sub_path)) {
2298+
.static_library, .shared_library => true,
2299+
else => false,
2300+
}) {
23002301
var file = test_path.root_dir.handle.openFile(test_path.sub_path, .{}) catch |err| switch (err) {
23012302
error.FileNotFound => return .no_match,
23022303
else => |e| fatal("unable to search for {s} library '{'}': {s}", .{
23032304
@tagName(link_mode), test_path, @errorName(e),
23042305
}),
23052306
};
23062307
errdefer file.close();
2307-
try ld_script_bytes.resize(gpa, @sizeOf(std.elf.Elf64_Ehdr));
2308+
try ld_script_bytes.resize(gpa, @max(std.elf.MAGIC.len, std.elf.ARMAG.len));
23082309
const n = file.preadAll(ld_script_bytes.items, 0) catch |err| fatal("failed to read '{'}': {s}", .{
23092310
test_path, @errorName(err),
23102311
});
2311-
elf_file: {
2312-
if (n != ld_script_bytes.items.len) break :elf_file;
2313-
if (!mem.eql(u8, ld_script_bytes.items[0..4], "\x7fELF")) break :elf_file;
2314-
// Appears to be an ELF file.
2312+
const buf = ld_script_bytes.items[0..n];
2313+
if (mem.startsWith(u8, buf, std.elf.MAGIC) or mem.startsWith(u8, buf, std.elf.ARMAG)) {
2314+
// Appears to be an ELF or archive file.
23152315
return finishResolveLibInput(resolved_inputs, test_path, file, link_mode, pq.query);
23162316
}
23172317
const stat = file.stat() catch |err|
23182318
fatal("failed to stat {}: {s}", .{ test_path, @errorName(err) });
23192319
const size = std.math.cast(u32, stat.size) orelse
23202320
fatal("{}: linker script too big", .{test_path});
23212321
try ld_script_bytes.resize(gpa, size);
2322-
const buf = ld_script_bytes.items[n..];
2323-
const n2 = file.preadAll(buf, n) catch |err|
2322+
const buf2 = ld_script_bytes.items[n..];
2323+
const n2 = file.preadAll(buf2, n) catch |err|
23242324
fatal("failed to read {}: {s}", .{ test_path, @errorName(err) });
2325-
if (n2 != buf.len) fatal("failed to read {}: unexpected end of file", .{test_path});
2325+
if (n2 != buf2.len) fatal("failed to read {}: unexpected end of file", .{test_path});
23262326
var diags = Diags.init(gpa);
23272327
defer diags.deinit();
23282328
const ld_script_result = LdScript.parse(gpa, &diags, test_path, ld_script_bytes.items);

src/link/Elf.zig

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ copy_rel: CopyRelSection = .{},
9999
rela_plt: std.ArrayListUnmanaged(elf.Elf64_Rela) = .empty,
100100
/// SHT_GROUP sections
101101
/// Applies only to a relocatable.
102-
comdat_group_sections: std.ArrayListUnmanaged(ComdatGroupSection) = .empty,
102+
group_sections: std.ArrayListUnmanaged(GroupSection) = .empty,
103103

104104
resolver: SymbolResolver = .{},
105105

@@ -510,7 +510,7 @@ pub fn deinit(self: *Elf) void {
510510
self.copy_rel.deinit(gpa);
511511
self.rela_dyn.deinit(gpa);
512512
self.rela_plt.deinit(gpa);
513-
self.comdat_group_sections.deinit(gpa);
513+
self.group_sections.deinit(gpa);
514514
self.dump_argv_list.deinit(gpa);
515515
}
516516

@@ -919,7 +919,7 @@ fn flushModuleInner(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id) !void {
919919
&self.sections,
920920
self.shstrtab.items,
921921
self.merge_sections.items,
922-
self.comdat_group_sections.items,
922+
self.group_sections.items,
923923
self.zigObjectPtr(),
924924
self.files,
925925
);
@@ -1315,16 +1315,16 @@ pub fn resolveSymbols(self: *Elf) !void {
13151315
}
13161316

13171317
{
1318-
// Dedup comdat groups.
1318+
// Dedup groups.
13191319
var table = std.StringHashMap(Ref).init(self.base.comp.gpa);
13201320
defer table.deinit();
13211321

13221322
for (self.objects.items) |index| {
1323-
try self.file(index).?.object.resolveComdatGroups(self, &table);
1323+
try self.file(index).?.object.resolveGroups(self, &table);
13241324
}
13251325

13261326
for (self.objects.items) |index| {
1327-
self.file(index).?.object.markComdatGroupsDead(self);
1327+
self.file(index).?.object.markGroupsDead(self);
13281328
}
13291329
}
13301330

@@ -3125,7 +3125,7 @@ pub fn sortShdrs(
31253125
sections: *std.MultiArrayList(Section),
31263126
shstrtab: []const u8,
31273127
merge_sections: []Merge.Section,
3128-
comdat_group_sections: []ComdatGroupSection,
3128+
comdat_group_sections: []GroupSection,
31293129
zig_object_ptr: ?*ZigObject,
31303130
files: std.MultiArrayList(File.Entry),
31313131
) !void {
@@ -4446,8 +4446,8 @@ pub fn atom(self: *Elf, ref: Ref) ?*Atom {
44464446
return file_ptr.atom(ref.index);
44474447
}
44484448

4449-
pub fn comdatGroup(self: *Elf, ref: Ref) *ComdatGroup {
4450-
return self.file(ref.file).?.comdatGroup(ref.index);
4449+
pub fn group(self: *Elf, ref: Ref) *Group {
4450+
return self.file(ref.file).?.group(ref.index);
44514451
}
44524452

44534453
pub fn symbol(self: *Elf, ref: Ref) ?*Symbol {
@@ -4814,7 +4814,7 @@ fn fmtDumpState(
48144814
object.fmtCies(self),
48154815
object.fmtFdes(self),
48164816
object.fmtSymtab(self),
4817-
object.fmtComdatGroups(self),
4817+
object.fmtGroups(self),
48184818
});
48194819
}
48204820

@@ -4852,9 +4852,9 @@ fn fmtDumpState(
48524852
try writer.print("{}\n", .{self.got.fmt(self)});
48534853
try writer.print("{}\n", .{self.plt.fmt(self)});
48544854

4855-
try writer.writeAll("Output COMDAT groups\n");
4856-
for (self.comdat_group_sections.items) |cg| {
4857-
try writer.print(" shdr({d}) : COMDAT({})\n", .{ cg.shndx, cg.cg_ref });
4855+
try writer.writeAll("Output groups\n");
4856+
for (self.group_sections.items) |cg| {
4857+
try writer.print(" shdr({d}) : GROUP({})\n", .{ cg.shndx, cg.cg_ref });
48584858
}
48594859

48604860
try writer.writeAll("\nOutput merge sections\n");
@@ -4934,25 +4934,26 @@ const default_entry_addr = 0x8000000;
49344934

49354935
pub const base_tag: link.File.Tag = .elf;
49364936

4937-
pub const ComdatGroup = struct {
4937+
pub const Group = struct {
49384938
signature_off: u32,
49394939
file_index: File.Index,
49404940
shndx: u32,
49414941
members_start: u32,
49424942
members_len: u32,
4943+
is_comdat: bool,
49434944
alive: bool = true,
49444945

4945-
pub fn file(cg: ComdatGroup, elf_file: *Elf) File {
4946+
pub fn file(cg: Group, elf_file: *Elf) File {
49464947
return elf_file.file(cg.file_index).?;
49474948
}
49484949

4949-
pub fn signature(cg: ComdatGroup, elf_file: *Elf) [:0]const u8 {
4950+
pub fn signature(cg: Group, elf_file: *Elf) [:0]const u8 {
49504951
return cg.file(elf_file).object.getString(cg.signature_off);
49514952
}
49524953

4953-
pub fn comdatGroupMembers(cg: ComdatGroup, elf_file: *Elf) []const u32 {
4954+
pub fn members(cg: Group, elf_file: *Elf) []const u32 {
49544955
const object = cg.file(elf_file).object;
4955-
return object.comdat_group_data.items[cg.members_start..][0..cg.members_len];
4956+
return object.group_data.items[cg.members_start..][0..cg.members_len];
49564957
}
49574958

49584959
pub const Index = u32;
@@ -5310,7 +5311,7 @@ const Air = @import("../Air.zig");
53105311
const Archive = @import("Elf/Archive.zig");
53115312
const AtomList = @import("Elf/AtomList.zig");
53125313
const Compilation = @import("../Compilation.zig");
5313-
const ComdatGroupSection = synthetic_sections.ComdatGroupSection;
5314+
const GroupSection = synthetic_sections.GroupSection;
53145315
const CopyRelSection = synthetic_sections.CopyRelSection;
53155316
const Diags = @import("../link.zig").Diags;
53165317
const DynamicSection = synthetic_sections.DynamicSection;

0 commit comments

Comments
 (0)