authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-21 12:45:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-21 12:45:32-07:00
log36295d712fbd561c3de9b3eb46e776d63e646e9a
tree9fadd735b548a1d2d2282e9abe0a30b57e21e728
parent26984852bdfdbe3564b19f3ff7b3ecfd606c9902

remove 'pe' object format

Portable Executable is an executable format, not an object format. Everywhere in the entire zig codebase, we treated coff and pe as if they were the same. Remove confusion by not including pe in the std.Target.ObjectFormat enum.

6 files changed, 14 insertions(+), 24 deletions(-)

lib/std/target.zig-1
...@@ -550,7 +550,6 @@ pub const Target = struct {...@@ -550,7 +550,6 @@ pub const Target = struct {
550550
551 pub const ObjectFormat = enum {551 pub const ObjectFormat = enum {
552 coff,552 coff,
553 pe,
554 elf,553 elf,
555 macho,554 macho,
556 wasm,555 wasm,
lib/std/zig.zig+1-1
...@@ -109,7 +109,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro...@@ -109,7 +109,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
109 const root_name = options.root_name;109 const root_name = options.root_name;
110 const target = options.target;110 const target = options.target;
111 switch (options.object_format orelse target.getObjectFormat()) {111 switch (options.object_format orelse target.getObjectFormat()) {
112 .coff, .pe => switch (options.output_mode) {112 .coff => switch (options.output_mode) {
113 .Exe => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.exeFileExt() }),113 .Exe => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.exeFileExt() }),
114 .Lib => {114 .Lib => {
115 const suffix = switch (options.link_mode orelse .Static) {115 const suffix = switch (options.link_mode orelse .Static) {
src/Compilation.zig+1-1
...@@ -3023,7 +3023,7 @@ pub fn addCCArgs(...@@ -3023,7 +3023,7 @@ pub fn addCCArgs(
3023 if (!comp.bin_file.options.strip) {3023 if (!comp.bin_file.options.strip) {
3024 try argv.append("-g");3024 try argv.append("-g");
3025 switch (comp.bin_file.options.object_format) {3025 switch (comp.bin_file.options.object_format) {
3026 .coff, .pe => try argv.append("-gcodeview"),3026 .coff => try argv.append("-gcodeview"),
3027 else => {},3027 else => {},
3028 }3028 }
3029 }3029 }
src/link.zig+3-3
...@@ -191,7 +191,7 @@ pub const File = struct {...@@ -191,7 +191,7 @@ pub const File = struct {
191 const use_stage1 = build_options.is_stage1 and options.use_stage1;191 const use_stage1 = build_options.is_stage1 and options.use_stage1;
192 if (use_stage1 or options.emit == null) {192 if (use_stage1 or options.emit == null) {
193 return switch (options.object_format) {193 return switch (options.object_format) {
194 .coff, .pe => &(try Coff.createEmpty(allocator, options)).base,194 .coff => &(try Coff.createEmpty(allocator, options)).base,
195 .elf => &(try Elf.createEmpty(allocator, options)).base,195 .elf => &(try Elf.createEmpty(allocator, options)).base,
196 .macho => &(try MachO.createEmpty(allocator, options)).base,196 .macho => &(try MachO.createEmpty(allocator, options)).base,
197 .wasm => &(try Wasm.createEmpty(allocator, options)).base,197 .wasm => &(try Wasm.createEmpty(allocator, options)).base,
...@@ -208,7 +208,7 @@ pub const File = struct {...@@ -208,7 +208,7 @@ pub const File = struct {
208 if (options.module == null) {208 if (options.module == null) {
209 // No point in opening a file, we would not write anything to it. Initialize with empty.209 // No point in opening a file, we would not write anything to it. Initialize with empty.
210 return switch (options.object_format) {210 return switch (options.object_format) {
211 .coff, .pe => &(try Coff.createEmpty(allocator, options)).base,211 .coff => &(try Coff.createEmpty(allocator, options)).base,
212 .elf => &(try Elf.createEmpty(allocator, options)).base,212 .elf => &(try Elf.createEmpty(allocator, options)).base,
213 .macho => &(try MachO.createEmpty(allocator, options)).base,213 .macho => &(try MachO.createEmpty(allocator, options)).base,
214 .plan9 => &(try Plan9.createEmpty(allocator, options)).base,214 .plan9 => &(try Plan9.createEmpty(allocator, options)).base,
...@@ -225,7 +225,7 @@ pub const File = struct {...@@ -225,7 +225,7 @@ pub const File = struct {
225 errdefer if (use_lld) allocator.free(sub_path);225 errdefer if (use_lld) allocator.free(sub_path);
226226
227 const file: *File = switch (options.object_format) {227 const file: *File = switch (options.object_format) {
228 .coff, .pe => &(try Coff.openPath(allocator, sub_path, options)).base,228 .coff => &(try Coff.openPath(allocator, sub_path, options)).base,
229 .elf => &(try Elf.openPath(allocator, sub_path, options)).base,229 .elf => &(try Elf.openPath(allocator, sub_path, options)).base,
230 .macho => &(try MachO.openPath(allocator, sub_path, options)).base,230 .macho => &(try MachO.openPath(allocator, sub_path, options)).base,
231 .plan9 => &(try Plan9.openPath(allocator, sub_path, options)).base,231 .plan9 => &(try Plan9.openPath(allocator, sub_path, options)).base,
src/link/Coff.zig+2-5
...@@ -657,10 +657,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {...@@ -657,10 +657,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {
657}657}
658658
659pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {659pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
660 if (build_options.skip_non_native and660 if (build_options.skip_non_native and builtin.object_format != .coff) {
661 builtin.object_format != .coff and
662 builtin.object_format != .pe)
663 {
664 @panic("Attempted to compile for object format that was disabled by build configuration");661 @panic("Attempted to compile for object format that was disabled by build configuration");
665 }662 }
666 if (build_options.have_llvm) {663 if (build_options.have_llvm) {
...@@ -697,7 +694,7 @@ pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, live...@@ -697,7 +694,7 @@ pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, live
697}694}
698695
699pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void {696pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void {
700 if (build_options.skip_non_native and builtin.object_format != .coff and builtin.object_format != .pe) {697 if (build_options.skip_non_native and builtin.object_format != .coff) {
701 @panic("Attempted to compile for object format that was disabled by build configuration");698 @panic("Attempted to compile for object format that was disabled by build configuration");
702 }699 }
703 if (build_options.have_llvm) {700 if (build_options.have_llvm) {
src/main.zig+7-13
...@@ -287,9 +287,9 @@ const usage_build_generic =...@@ -287,9 +287,9 @@ const usage_build_generic =
287 \\ .s Target-specific assembly source code287 \\ .s Target-specific assembly source code
288 \\ .S Assembly with C preprocessor (requires LLVM extensions)288 \\ .S Assembly with C preprocessor (requires LLVM extensions)
289 \\ .c C source code (requires LLVM extensions)289 \\ .c C source code (requires LLVM extensions)
290 \\ .cpp C++ source code (requires LLVM extensions)290 \\ .cxx .cc .C .cpp C++ source code (requires LLVM extensions)
291 \\ Other C++ extensions: .C .cc .cxx
292 \\ .m Objective-C source code (requires LLVM extensions)291 \\ .m Objective-C source code (requires LLVM extensions)
292 \\ .bc LLVM IR Module (requires LLVM extensions)
293 \\293 \\
294 \\General Options:294 \\General Options:
295 \\ -h, --help Print this help and exit295 \\ -h, --help Print this help and exit
...@@ -361,13 +361,12 @@ const usage_build_generic =...@@ -361,13 +361,12 @@ const usage_build_generic =
361 \\ elf Executable and Linking Format361 \\ elf Executable and Linking Format
362 \\ c Compile to C source code362 \\ c Compile to C source code
363 \\ wasm WebAssembly363 \\ wasm WebAssembly
364 \\ pe Portable Executable (Windows)
365 \\ coff Common Object File Format (Windows)364 \\ coff Common Object File Format (Windows)
366 \\ macho macOS relocatables365 \\ macho macOS relocatables
367 \\ spirv Standard, Portable Intermediate Representation V (SPIR-V)366 \\ spirv Standard, Portable Intermediate Representation V (SPIR-V)
368 \\ plan9 Plan 9 from Bell Labs object format367 \\ plan9 Plan 9 from Bell Labs object format
369 \\ hex (planned) Intel IHEX368 \\ hex (planned feature) Intel IHEX
370 \\ raw (planned) Dump machine code directly369 \\ raw (planned feature) Dump machine code directly
371 \\ -dirafter [dir] Add directory to AFTER include search path370 \\ -dirafter [dir] Add directory to AFTER include search path
372 \\ -isystem [dir] Add directory to SYSTEM include search path371 \\ -isystem [dir] Add directory to SYSTEM include search path
373 \\ -I[dir] Add directory to include search path372 \\ -I[dir] Add directory to include search path
...@@ -1708,8 +1707,6 @@ fn buildOutputType(...@@ -1708,8 +1707,6 @@ fn buildOutputType(
1708 break :blk .c;1707 break :blk .c;
1709 } else if (mem.eql(u8, ofmt, "coff")) {1708 } else if (mem.eql(u8, ofmt, "coff")) {
1710 break :blk .coff;1709 break :blk .coff;
1711 } else if (mem.eql(u8, ofmt, "pe")) {
1712 break :blk .pe;
1713 } else if (mem.eql(u8, ofmt, "macho")) {1710 } else if (mem.eql(u8, ofmt, "macho")) {
1714 break :blk .macho;1711 break :blk .macho;
1715 } else if (mem.eql(u8, ofmt, "wasm")) {1712 } else if (mem.eql(u8, ofmt, "wasm")) {
...@@ -1753,7 +1750,7 @@ fn buildOutputType(...@@ -1753,7 +1750,7 @@ fn buildOutputType(
1753 };1750 };
17541751
1755 const a_out_basename = switch (object_format) {1752 const a_out_basename = switch (object_format) {
1756 .pe, .coff => "a.exe",1753 .coff => "a.exe",
1757 else => "a.out",1754 else => "a.out",
1758 };1755 };
17591756
...@@ -2396,11 +2393,8 @@ fn updateModule(gpa: *Allocator, comp: *Compilation, hook: AfterUpdateHook) !voi...@@ -2396,11 +2393,8 @@ fn updateModule(gpa: *Allocator, comp: *Compilation, hook: AfterUpdateHook) !voi
23962393
2397 // If a .pdb file is part of the expected output, we must also copy2394 // If a .pdb file is part of the expected output, we must also copy
2398 // it into place here.2395 // it into place here.
2399 const coff_or_pe = switch (comp.bin_file.options.object_format) {2396 const is_coff = comp.bin_file.options.object_format == .coff;
2400 .coff, .pe => true,2397 const have_pdb = is_coff and !comp.bin_file.options.strip;
2401 else => false,
2402 };
2403 const have_pdb = coff_or_pe and !comp.bin_file.options.strip;
2404 if (have_pdb) {2398 if (have_pdb) {
2405 // Replace `.out` or `.exe` with `.pdb` on both the source and destination2399 // Replace `.out` or `.exe` with `.pdb` on both the source and destination
2406 const src_bin_ext = fs.path.extension(bin_sub_path);2400 const src_bin_ext = fs.path.extension(bin_sub_path);