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 {
550550
551551 pub const ObjectFormat = enum {
552552 coff,
553 pe,
554553 elf,
555554 macho,
556555 wasm,
lib/std/zig.zig+1-1
......@@ -109,7 +109,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
109109 const root_name = options.root_name;
110110 const target = options.target;
111111 switch (options.object_format orelse target.getObjectFormat()) {
112 .coff, .pe => switch (options.output_mode) {
112 .coff => switch (options.output_mode) {
113113 .Exe => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.exeFileExt() }),
114114 .Lib => {
115115 const suffix = switch (options.link_mode orelse .Static) {
src/Compilation.zig+1-1
......@@ -3023,7 +3023,7 @@ pub fn addCCArgs(
30233023 if (!comp.bin_file.options.strip) {
30243024 try argv.append("-g");
30253025 switch (comp.bin_file.options.object_format) {
3026 .coff, .pe => try argv.append("-gcodeview"),
3026 .coff => try argv.append("-gcodeview"),
30273027 else => {},
30283028 }
30293029 }
src/link.zig+3-3
......@@ -191,7 +191,7 @@ pub const File = struct {
191191 const use_stage1 = build_options.is_stage1 and options.use_stage1;
192192 if (use_stage1 or options.emit == null) {
193193 return switch (options.object_format) {
194 .coff, .pe => &(try Coff.createEmpty(allocator, options)).base,
194 .coff => &(try Coff.createEmpty(allocator, options)).base,
195195 .elf => &(try Elf.createEmpty(allocator, options)).base,
196196 .macho => &(try MachO.createEmpty(allocator, options)).base,
197197 .wasm => &(try Wasm.createEmpty(allocator, options)).base,
......@@ -208,7 +208,7 @@ pub const File = struct {
208208 if (options.module == null) {
209209 // No point in opening a file, we would not write anything to it. Initialize with empty.
210210 return switch (options.object_format) {
211 .coff, .pe => &(try Coff.createEmpty(allocator, options)).base,
211 .coff => &(try Coff.createEmpty(allocator, options)).base,
212212 .elf => &(try Elf.createEmpty(allocator, options)).base,
213213 .macho => &(try MachO.createEmpty(allocator, options)).base,
214214 .plan9 => &(try Plan9.createEmpty(allocator, options)).base,
......@@ -225,7 +225,7 @@ pub const File = struct {
225225 errdefer if (use_lld) allocator.free(sub_path);
226226
227227 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,
229229 .elf => &(try Elf.openPath(allocator, sub_path, options)).base,
230230 .macho => &(try MachO.openPath(allocator, sub_path, options)).base,
231231 .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 {
657657}
658658
659659pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
660 if (build_options.skip_non_native and
661 builtin.object_format != .coff and
662 builtin.object_format != .pe)
663 {
660 if (build_options.skip_non_native and builtin.object_format != .coff) {
664661 @panic("Attempted to compile for object format that was disabled by build configuration");
665662 }
666663 if (build_options.have_llvm) {
......@@ -697,7 +694,7 @@ pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, live
697694}
698695
699696pub 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) {
701698 @panic("Attempted to compile for object format that was disabled by build configuration");
702699 }
703700 if (build_options.have_llvm) {
src/main.zig+7-13
......@@ -287,9 +287,9 @@ const usage_build_generic =
287287 \\ .s Target-specific assembly source code
288288 \\ .S Assembly with C preprocessor (requires LLVM extensions)
289289 \\ .c C source code (requires LLVM extensions)
290 \\ .cpp C++ source code (requires LLVM extensions)
291 \\ Other C++ extensions: .C .cc .cxx
290 \\ .cxx .cc .C .cpp C++ source code (requires LLVM extensions)
292291 \\ .m Objective-C source code (requires LLVM extensions)
292 \\ .bc LLVM IR Module (requires LLVM extensions)
293293 \\
294294 \\General Options:
295295 \\ -h, --help Print this help and exit
......@@ -361,13 +361,12 @@ const usage_build_generic =
361361 \\ elf Executable and Linking Format
362362 \\ c Compile to C source code
363363 \\ wasm WebAssembly
364 \\ pe Portable Executable (Windows)
365364 \\ coff Common Object File Format (Windows)
366365 \\ macho macOS relocatables
367366 \\ spirv Standard, Portable Intermediate Representation V (SPIR-V)
368367 \\ plan9 Plan 9 from Bell Labs object format
369 \\ hex (planned) Intel IHEX
370 \\ raw (planned) Dump machine code directly
368 \\ hex (planned feature) Intel IHEX
369 \\ raw (planned feature) Dump machine code directly
371370 \\ -dirafter [dir] Add directory to AFTER include search path
372371 \\ -isystem [dir] Add directory to SYSTEM include search path
373372 \\ -I[dir] Add directory to include search path
......@@ -1708,8 +1707,6 @@ fn buildOutputType(
17081707 break :blk .c;
17091708 } else if (mem.eql(u8, ofmt, "coff")) {
17101709 break :blk .coff;
1711 } else if (mem.eql(u8, ofmt, "pe")) {
1712 break :blk .pe;
17131710 } else if (mem.eql(u8, ofmt, "macho")) {
17141711 break :blk .macho;
17151712 } else if (mem.eql(u8, ofmt, "wasm")) {
......@@ -1753,7 +1750,7 @@ fn buildOutputType(
17531750 };
17541751
17551752 const a_out_basename = switch (object_format) {
1756 .pe, .coff => "a.exe",
1753 .coff => "a.exe",
17571754 else => "a.out",
17581755 };
17591756
......@@ -2396,11 +2393,8 @@ fn updateModule(gpa: *Allocator, comp: *Compilation, hook: AfterUpdateHook) !voi
23962393
23972394 // If a .pdb file is part of the expected output, we must also copy
23982395 // it into place here.
2399 const coff_or_pe = switch (comp.bin_file.options.object_format) {
2400 .coff, .pe => true,
2401 else => false,
2402 };
2403 const have_pdb = coff_or_pe and !comp.bin_file.options.strip;
2396 const is_coff = comp.bin_file.options.object_format == .coff;
2397 const have_pdb = is_coff and !comp.bin_file.options.strip;
24042398 if (have_pdb) {
24052399 // Replace `.out` or `.exe` with `.pdb` on both the source and destination
24062400 const src_bin_ext = fs.path.extension(bin_sub_path);