| ... | @@ -158,6 +158,7 @@ pub const File = struct { | ... | @@ -158,6 +158,7 @@ pub const File = struct { |
| 158 | } | 158 | } |
| 159 | } | 159 | } |
| 160 | | 160 | |
| | 161 | /// Commit pending changes and write headers. |
| 161 | pub fn flush(base: *File) !void { | 162 | pub fn flush(base: *File) !void { |
| 162 | const tracy = trace(@src()); | 163 | const tracy = trace(@src()); |
| 163 | defer tracy.end(); | 164 | defer tracy.end(); |
| ... | @@ -1022,7 +1023,6 @@ pub const File = struct { | ... | @@ -1022,7 +1023,6 @@ pub const File = struct { |
| 1022 | pub const abbrev_pad1 = 5; | 1023 | pub const abbrev_pad1 = 5; |
| 1023 | pub const abbrev_parameter = 6; | 1024 | pub const abbrev_parameter = 6; |
| 1024 | | 1025 | |
| 1025 | /// Commit pending changes and write headers. | | |
| 1026 | pub fn flush(self: *Elf) !void { | 1026 | pub fn flush(self: *Elf) !void { |
| 1027 | const target_endian = self.base.options.target.cpu.arch.endian(); | 1027 | const target_endian = self.base.options.target.cpu.arch.endian(); |
| 1028 | const foreign_endian = target_endian != std.Target.current.cpu.arch.endian(); | 1028 | const foreign_endian = target_endian != std.Target.current.cpu.arch.endian(); |
| ... | @@ -2330,7 +2330,6 @@ pub const File = struct { | ... | @@ -2330,7 +2330,6 @@ pub const File = struct { |
| 2330 | try self.pwriteDbgInfoNops(prev_padding_size, dbg_info_buf, next_padding_size, trailing_zero, file_pos); | 2330 | try self.pwriteDbgInfoNops(prev_padding_size, dbg_info_buf, next_padding_size, trailing_zero, file_pos); |
| 2331 | } | 2331 | } |
| 2332 | | 2332 | |
| 2333 | /// Must be called only after a successful call to `updateDecl`. | | |
| 2334 | pub fn updateDeclExports( | 2333 | pub fn updateDeclExports( |
| 2335 | self: *Elf, | 2334 | self: *Elf, |
| 2336 | module: *Module, | 2335 | module: *Module, |
| ... | @@ -2832,99 +2831,7 @@ pub const File = struct { | ... | @@ -2832,99 +2831,7 @@ pub const File = struct { |
| 2832 | | 2831 | |
| 2833 | }; | 2832 | }; |
| 2834 | | 2833 | |
| 2835 | pub const MachO = struct { | 2834 | pub const MachO = @import("link/MachO.zig"); |
| 2836 | pub const base_tag: Tag = .macho; | | |
| 2837 | | | |
| 2838 | base: File, | | |
| 2839 | | | |
| 2840 | ptr_width: enum { p32, p64 }, | | |
| 2841 | | | |
| 2842 | error_flags: ErrorFlags = ErrorFlags{}, | | |
| 2843 | | | |
| 2844 | pub const TextBlock = struct { | | |
| 2845 | pub const empty = TextBlock{}; | | |
| 2846 | }; | | |
| 2847 | | | |
| 2848 | pub const SrcFn = struct { | | |
| 2849 | pub const empty = SrcFn{}; | | |
| 2850 | }; | | |
| 2851 | | | |
| 2852 | pub fn openPath(allocator: *Allocator, dir: fs.Dir, sub_path: []const u8, options: Options) !*File { | | |
| 2853 | assert(options.object_format == .macho); | | |
| 2854 | | | |
| 2855 | const file = try dir.createFile(sub_path, .{ .truncate = false, .read = true, .mode = determineMode(options) }); | | |
| 2856 | errdefer file.close(); | | |
| 2857 | | | |
| 2858 | var macho_file = try allocator.create(MachO); | | |
| 2859 | errdefer allocator.destroy(macho_file); | | |
| 2860 | | | |
| 2861 | macho_file.* = openFile(allocator, file, options) catch |err| switch (err) { | | |
| 2862 | error.IncrFailed => try createFile(allocator, file, options), | | |
| 2863 | else => |e| return e, | | |
| 2864 | }; | | |
| 2865 | | | |
| 2866 | return &macho_file.base; | | |
| 2867 | } | | |
| 2868 | | | |
| 2869 | /// Returns error.IncrFailed if incremental update could not be performed. | | |
| 2870 | fn openFile(allocator: *Allocator, file: fs.File, options: Options) !MachO { | | |
| 2871 | switch (options.output_mode) { | | |
| 2872 | .Exe => {}, | | |
| 2873 | .Obj => {}, | | |
| 2874 | .Lib => return error.IncrFailed, | | |
| 2875 | } | | |
| 2876 | var self: MachO = .{ | | |
| 2877 | .base = .{ | | |
| 2878 | .file = file, | | |
| 2879 | .tag = .macho, | | |
| 2880 | .options = options, | | |
| 2881 | .allocator = allocator, | | |
| 2882 | }, | | |
| 2883 | .ptr_width = switch (options.target.cpu.arch.ptrBitWidth()) { | | |
| 2884 | 32 => .p32, | | |
| 2885 | 64 => .p64, | | |
| 2886 | else => return error.UnsupportedELFArchitecture, | | |
| 2887 | }, | | |
| 2888 | }; | | |
| 2889 | errdefer self.deinit(); | | |
| 2890 | | | |
| 2891 | // TODO implement reading the macho file | | |
| 2892 | return error.IncrFailed; | | |
| 2893 | //try self.populateMissingMetadata(); | | |
| 2894 | //return self; | | |
| 2895 | } | | |
| 2896 | | | |
| 2897 | /// Truncates the existing file contents and overwrites the contents. | | |
| 2898 | /// Returns an error if `file` is not already open with +read +write +seek abilities. | | |
| 2899 | fn createFile(allocator: *Allocator, file: fs.File, options: Options) !MachO { | | |
| 2900 | switch (options.output_mode) { | | |
| 2901 | .Exe => return error.TODOImplementWritingMachOExeFiles, | | |
| 2902 | .Obj => return error.TODOImplementWritingMachOObjFiles, | | |
| 2903 | .Lib => return error.TODOImplementWritingLibFiles, | | |
| 2904 | } | | |
| 2905 | } | | |
| 2906 | | | |
| 2907 | /// Commit pending changes and write headers. | | |
| 2908 | pub fn flush(self: *MachO) !void {} | | |
| 2909 | | | |
| 2910 | pub fn deinit(self: *MachO) void {} | | |
| 2911 | | | |
| 2912 | pub fn allocateDeclIndexes(self: *MachO, decl: *Module.Decl) !void {} | | |
| 2913 | | | |
| 2914 | pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {} | | |
| 2915 | | | |
| 2916 | pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl: *const Module.Decl) !void {} | | |
| 2917 | | | |
| 2918 | /// Must be called only after a successful call to `updateDecl`. | | |
| 2919 | pub fn updateDeclExports( | | |
| 2920 | self: *MachO, | | |
| 2921 | module: *Module, | | |
| 2922 | decl: *const Module.Decl, | | |
| 2923 | exports: []const *Module.Export, | | |
| 2924 | ) !void {} | | |
| 2925 | | | |
| 2926 | pub fn freeDecl(self: *MachO, decl: *Module.Decl) void {} | | |
| 2927 | }; | | |
| 2928 | }; | 2835 | }; |
| 2929 | | 2836 | |
| 2930 | /// Saturating multiplication | 2837 | /// Saturating multiplication |
| ... | @@ -2965,7 +2872,7 @@ fn sectHeaderTo32(shdr: elf.Elf64_Shdr) elf.Elf32_Shdr { | ... | @@ -2965,7 +2872,7 @@ fn sectHeaderTo32(shdr: elf.Elf64_Shdr) elf.Elf32_Shdr { |
| 2965 | }; | 2872 | }; |
| 2966 | } | 2873 | } |
| 2967 | | 2874 | |
| 2968 | fn determineMode(options: Options) fs.File.Mode { | 2875 | pub fn determineMode(options: Options) fs.File.Mode { |
| 2969 | // On common systems with a 0o022 umask, 0o777 will still result in a file created | 2876 | // On common systems with a 0o022 umask, 0o777 will still result in a file created |
| 2970 | // with 0o755 permissions, but it works appropriately if the system is configured | 2877 | // with 0o755 permissions, but it works appropriately if the system is configured |
| 2971 | // more leniently. As another data point, C's fopen seems to open files with the | 2878 | // more leniently. As another data point, C's fopen seems to open files with the |