| ... | @@ -229,6 +229,8 @@ comdat_groups_table: std.AutoHashMapUnmanaged(u32, ComdatGroupOwner.Index) = .{} | ... | @@ -229,6 +229,8 @@ comdat_groups_table: std.AutoHashMapUnmanaged(u32, ComdatGroupOwner.Index) = .{} |
| 229 | /// such as `resolver` and `comdat_groups_table`. | 229 | /// such as `resolver` and `comdat_groups_table`. |
| 230 | strings: StringTable = .{}, | 230 | strings: StringTable = .{}, |
| 231 | | 231 | |
| | 232 | first_eflags: ?elf.Elf64_Word = null, |
| | 233 | |
| 232 | /// When allocating, the ideal_capacity is calculated by | 234 | /// When allocating, the ideal_capacity is calculated by |
| 233 | /// actual_capacity + (actual_capacity / ideal_factor) | 235 | /// actual_capacity + (actual_capacity / ideal_factor) |
| 234 | const ideal_factor = 3; | 236 | const ideal_factor = 3; |
| ... | @@ -553,7 +555,7 @@ pub fn lowerAnonDecl( | ... | @@ -553,7 +555,7 @@ pub fn lowerAnonDecl( |
| 553 | pt: Zcu.PerThread, | 555 | pt: Zcu.PerThread, |
| 554 | decl_val: InternPool.Index, | 556 | decl_val: InternPool.Index, |
| 555 | explicit_alignment: InternPool.Alignment, | 557 | explicit_alignment: InternPool.Alignment, |
| 556 | src_loc: Module.LazySrcLoc, | 558 | src_loc: Zcu.LazySrcLoc, |
| 557 | ) !codegen.Result { | 559 | ) !codegen.Result { |
| 558 | return self.zigObjectPtr().?.lowerAnonDecl(self, pt, decl_val, explicit_alignment, src_loc); | 560 | return self.zigObjectPtr().?.lowerAnonDecl(self, pt, decl_val, explicit_alignment, src_loc); |
| 559 | } | 561 | } |
| ... | @@ -1161,7 +1163,11 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod | ... | @@ -1161,7 +1163,11 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod |
| 1161 | | 1163 | |
| 1162 | for (positionals.items) |obj| { | 1164 | for (positionals.items) |obj| { |
| 1163 | self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { | 1165 | self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { |
| 1164 | error.MalformedObject, error.MalformedArchive, error.InvalidCpuArch => continue, // already reported | 1166 | error.MalformedObject, |
| | 1167 | error.MalformedArchive, |
| | 1168 | error.MismatchedEflags, |
| | 1169 | error.InvalidCpuArch, |
| | 1170 | => continue, // already reported |
| 1165 | else => |e| try self.reportParseError( | 1171 | else => |e| try self.reportParseError( |
| 1166 | obj.path, | 1172 | obj.path, |
| 1167 | "unexpected error: parsing input file failed with error {s}", | 1173 | "unexpected error: parsing input file failed with error {s}", |
| ... | @@ -1270,7 +1276,11 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod | ... | @@ -1270,7 +1276,11 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod |
| 1270 | | 1276 | |
| 1271 | for (positionals.items) |obj| { | 1277 | for (positionals.items) |obj| { |
| 1272 | self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { | 1278 | self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { |
| 1273 | error.MalformedObject, error.MalformedArchive, error.InvalidCpuArch => continue, // already reported | 1279 | error.MalformedObject, |
| | 1280 | error.MalformedArchive, |
| | 1281 | error.MismatchedEflags, |
| | 1282 | error.InvalidCpuArch, |
| | 1283 | => continue, // already reported |
| 1274 | else => |e| try self.reportParseError( | 1284 | else => |e| try self.reportParseError( |
| 1275 | obj.path, | 1285 | obj.path, |
| 1276 | "unexpected error: parsing input file failed with error {s}", | 1286 | "unexpected error: parsing input file failed with error {s}", |
| ... | @@ -1700,6 +1710,7 @@ pub const ParseError = error{ | ... | @@ -1700,6 +1710,7 @@ pub const ParseError = error{ |
| 1700 | MalformedObject, | 1710 | MalformedObject, |
| 1701 | MalformedArchive, | 1711 | MalformedArchive, |
| 1702 | InvalidCpuArch, | 1712 | InvalidCpuArch, |
| | 1713 | MismatchedEflags, |
| 1703 | OutOfMemory, | 1714 | OutOfMemory, |
| 1704 | Overflow, | 1715 | Overflow, |
| 1705 | InputOutput, | 1716 | InputOutput, |
| ... | @@ -1879,6 +1890,48 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void { | ... | @@ -1879,6 +1890,48 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void { |
| 1879 | } | 1890 | } |
| 1880 | } | 1891 | } |
| 1881 | | 1892 | |
| | 1893 | pub fn validateEFlags(self: *Elf, file_index: File.Index, e_flags: elf.Elf64_Word) !void { |
| | 1894 | const target = self.base.comp.root_mod.resolved_target.result; |
| | 1895 | |
| | 1896 | if (self.first_eflags == null) { |
| | 1897 | self.first_eflags = e_flags; |
| | 1898 | return; // there isn't anything to conflict with yet |
| | 1899 | } |
| | 1900 | const self_eflags: *elf.Elf64_Word = &self.first_eflags.?; |
| | 1901 | |
| | 1902 | switch (target.cpu.arch) { |
| | 1903 | .riscv64 => { |
| | 1904 | if (e_flags != self_eflags.*) { |
| | 1905 | const riscv_eflags: riscv.RiscvEflags = @bitCast(e_flags); |
| | 1906 | const self_riscv_eflags: *riscv.RiscvEflags = @ptrCast(self_eflags); |
| | 1907 | |
| | 1908 | self_riscv_eflags.rvc = self_riscv_eflags.rvc or riscv_eflags.rvc; |
| | 1909 | self_riscv_eflags.tso = self_riscv_eflags.tso or riscv_eflags.tso; |
| | 1910 | |
| | 1911 | var is_error: bool = false; |
| | 1912 | if (self_riscv_eflags.fabi != riscv_eflags.fabi) { |
| | 1913 | is_error = true; |
| | 1914 | _ = try self.reportParseError2( |
| | 1915 | file_index, |
| | 1916 | "cannot link object files with different float-point ABIs", |
| | 1917 | .{}, |
| | 1918 | ); |
| | 1919 | } |
| | 1920 | if (self_riscv_eflags.rve != riscv_eflags.rve) { |
| | 1921 | is_error = true; |
| | 1922 | _ = try self.reportParseError2( |
| | 1923 | file_index, |
| | 1924 | "cannot link object files with different RVEs", |
| | 1925 | .{}, |
| | 1926 | ); |
| | 1927 | } |
| | 1928 | if (is_error) return error.MismatchedEflags; |
| | 1929 | } |
| | 1930 | }, |
| | 1931 | else => {}, |
| | 1932 | } |
| | 1933 | } |
| | 1934 | |
| 1882 | fn accessLibPath( | 1935 | fn accessLibPath( |
| 1883 | self: *Elf, | 1936 | self: *Elf, |
| 1884 | arena: Allocator, | 1937 | arena: Allocator, |
| ... | @@ -3025,7 +3078,7 @@ pub fn lowerUnnamedConst(self: *Elf, pt: Zcu.PerThread, val: Value, decl_index: | ... | @@ -3025,7 +3078,7 @@ pub fn lowerUnnamedConst(self: *Elf, pt: Zcu.PerThread, val: Value, decl_index: |
| 3025 | pub fn updateExports( | 3078 | pub fn updateExports( |
| 3026 | self: *Elf, | 3079 | self: *Elf, |
| 3027 | pt: Zcu.PerThread, | 3080 | pt: Zcu.PerThread, |
| 3028 | exported: Module.Exported, | 3081 | exported: Zcu.Exported, |
| 3029 | export_indices: []const u32, | 3082 | export_indices: []const u32, |
| 3030 | ) link.File.UpdateExportsError!void { | 3083 | ) link.File.UpdateExportsError!void { |
| 3031 | if (build_options.skip_non_native and builtin.object_format != .elf) { | 3084 | if (build_options.skip_non_native and builtin.object_format != .elf) { |
| ... | @@ -6432,8 +6485,6 @@ const LlvmObject = @import("../codegen/llvm.zig").Object; | ... | @@ -6432,8 +6485,6 @@ const LlvmObject = @import("../codegen/llvm.zig").Object; |
| 6432 | const MergeSection = merge_section.MergeSection; | 6485 | const MergeSection = merge_section.MergeSection; |
| 6433 | const MergeSubsection = merge_section.MergeSubsection; | 6486 | const MergeSubsection = merge_section.MergeSubsection; |
| 6434 | const Zcu = @import("../Zcu.zig"); | 6487 | const Zcu = @import("../Zcu.zig"); |
| 6435 | /// Deprecated. | | |
| 6436 | const Module = Zcu; | | |
| 6437 | const Object = @import("Elf/Object.zig"); | 6488 | const Object = @import("Elf/Object.zig"); |
| 6438 | const InternPool = @import("../InternPool.zig"); | 6489 | const InternPool = @import("../InternPool.zig"); |
| 6439 | const PltSection = synthetic_sections.PltSection; | 6490 | const PltSection = synthetic_sections.PltSection; |
| ... | @@ -6446,3 +6497,4 @@ const Value = @import("../Value.zig"); | ... | @@ -6446,3 +6497,4 @@ const Value = @import("../Value.zig"); |
| 6446 | const VerneedSection = synthetic_sections.VerneedSection; | 6497 | const VerneedSection = synthetic_sections.VerneedSection; |
| 6447 | const ZigGotSection = synthetic_sections.ZigGotSection; | 6498 | const ZigGotSection = synthetic_sections.ZigGotSection; |
| 6448 | const ZigObject = @import("Elf/ZigObject.zig"); | 6499 | const ZigObject = @import("Elf/ZigObject.zig"); |
| | 6500 | const riscv = @import("riscv.zig"); |