@@ -229,6 +229,8 @@ comdat_groups_table: std.AutoHashMapUnmanaged(u32, ComdatGroupOwner.Index) = .{}
229229/// such as `resolver` and `comdat_groups_table`.
230230strings : StringTable = .{},
231231
232+ first_eflags : ? elf.Elf64_Word = null ,
233+
232234/// When allocating, the ideal_capacity is calculated by
233235/// actual_capacity + (actual_capacity / ideal_factor)
234236const ideal_factor = 3 ;
@@ -553,7 +555,7 @@ pub fn lowerAnonDecl(
553555 pt : Zcu.PerThread ,
554556 decl_val : InternPool.Index ,
555557 explicit_alignment : InternPool.Alignment ,
556- src_loc : Module .LazySrcLoc ,
558+ src_loc : Zcu .LazySrcLoc ,
557559) ! codegen.Result {
558560 return self .zigObjectPtr ().? .lowerAnonDecl (self , pt , decl_val , explicit_alignment , src_loc );
559561}
@@ -1161,7 +1163,11 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod
11611163
11621164 for (positionals .items ) | obj | {
11631165 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
11651171 else = > | e | try self .reportParseError (
11661172 obj .path ,
11671173 "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
12701276
12711277 for (positionals .items ) | obj | {
12721278 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
12741284 else = > | e | try self .reportParseError (
12751285 obj .path ,
12761286 "unexpected error: parsing input file failed with error {s}" ,
@@ -1700,6 +1710,7 @@ pub const ParseError = error{
17001710 MalformedObject ,
17011711 MalformedArchive ,
17021712 InvalidCpuArch ,
1713+ MismatchedEflags ,
17031714 OutOfMemory ,
17041715 Overflow ,
17051716 InputOutput ,
@@ -1879,6 +1890,48 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void {
18791890 }
18801891}
18811892
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+
18821935fn accessLibPath (
18831936 self : * Elf ,
18841937 arena : Allocator ,
@@ -3025,7 +3078,7 @@ pub fn lowerUnnamedConst(self: *Elf, pt: Zcu.PerThread, val: Value, decl_index:
30253078pub fn updateExports (
30263079 self : * Elf ,
30273080 pt : Zcu.PerThread ,
3028- exported : Module .Exported ,
3081+ exported : Zcu .Exported ,
30293082 export_indices : []const u32 ,
30303083) link.File.UpdateExportsError ! void {
30313084 if (build_options .skip_non_native and builtin .object_format != .elf ) {
@@ -6432,8 +6485,6 @@ const LlvmObject = @import("../codegen/llvm.zig").Object;
64326485const MergeSection = merge_section .MergeSection ;
64336486const MergeSubsection = merge_section .MergeSubsection ;
64346487const Zcu = @import ("../Zcu.zig" );
6435- /// Deprecated.
6436- const Module = Zcu ;
64376488const Object = @import ("Elf/Object.zig" );
64386489const InternPool = @import ("../InternPool.zig" );
64396490const PltSection = synthetic_sections .PltSection ;
@@ -6446,3 +6497,4 @@ const Value = @import("../Value.zig");
64466497const VerneedSection = synthetic_sections .VerneedSection ;
64476498const ZigGotSection = synthetic_sections .ZigGotSection ;
64486499const ZigObject = @import ("Elf/ZigObject.zig" );
6500+ const riscv = @import ("riscv.zig" );
0 commit comments