| ... | @@ -72,7 +72,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr | ... | @@ -72,7 +72,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 72 | switch (crt_file) { | 72 | switch (crt_file) { |
| 73 | .crt1_reactor_o => { | 73 | .crt1_reactor_o => { |
| 74 | var args = std.ArrayList([]const u8).init(arena); | 74 | var args = std.ArrayList([]const u8).init(arena); |
| 75 | try addCCArgs(comp, arena, &args, false); | 75 | try addCCArgs(comp, arena, &args, .{}); |
| 76 | try addLibcBottomHalfIncludes(comp, arena, &args); | 76 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 77 | return comp.build_crt_file("crt1-reactor", .Obj, .@"wasi crt1-reactor.o", prog_node, &.{ | 77 | return comp.build_crt_file("crt1-reactor", .Obj, .@"wasi crt1-reactor.o", prog_node, &.{ |
| 78 | .{ | 78 | .{ |
| ... | @@ -85,7 +85,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr | ... | @@ -85,7 +85,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 85 | }, | 85 | }, |
| 86 | .crt1_command_o => { | 86 | .crt1_command_o => { |
| 87 | var args = std.ArrayList([]const u8).init(arena); | 87 | var args = std.ArrayList([]const u8).init(arena); |
| 88 | try addCCArgs(comp, arena, &args, false); | 88 | try addCCArgs(comp, arena, &args, .{}); |
| 89 | try addLibcBottomHalfIncludes(comp, arena, &args); | 89 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 90 | return comp.build_crt_file("crt1-command", .Obj, .@"wasi crt1-command.o", prog_node, &.{ | 90 | return comp.build_crt_file("crt1-command", .Obj, .@"wasi crt1-command.o", prog_node, &.{ |
| 91 | .{ | 91 | .{ |
| ... | @@ -102,7 +102,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr | ... | @@ -102,7 +102,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 102 | { | 102 | { |
| 103 | // Compile emmalloc. | 103 | // Compile emmalloc. |
| 104 | var args = std.ArrayList([]const u8).init(arena); | 104 | var args = std.ArrayList([]const u8).init(arena); |
| 105 | try addCCArgs(comp, arena, &args, true); | 105 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true, .no_strict_aliasing = true }); |
| 106 | for (emmalloc_src_files) |file_path| { | 106 | for (emmalloc_src_files) |file_path| { |
| 107 | try libc_sources.append(.{ | 107 | try libc_sources.append(.{ |
| 108 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 108 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| ... | @@ -116,7 +116,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr | ... | @@ -116,7 +116,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 116 | { | 116 | { |
| 117 | // Compile libc-bottom-half. | 117 | // Compile libc-bottom-half. |
| 118 | var args = std.ArrayList([]const u8).init(arena); | 118 | var args = std.ArrayList([]const u8).init(arena); |
| 119 | try addCCArgs(comp, arena, &args, true); | 119 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| 120 | try addLibcBottomHalfIncludes(comp, arena, &args); | 120 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 121 | | 121 | |
| 122 | for (libc_bottom_half_src_files) |file_path| { | 122 | for (libc_bottom_half_src_files) |file_path| { |
| ... | @@ -132,7 +132,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr | ... | @@ -132,7 +132,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 132 | { | 132 | { |
| 133 | // Compile libc-top-half. | 133 | // Compile libc-top-half. |
| 134 | var args = std.ArrayList([]const u8).init(arena); | 134 | var args = std.ArrayList([]const u8).init(arena); |
| 135 | try addCCArgs(comp, arena, &args, true); | 135 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| 136 | try addLibcTopHalfIncludes(comp, arena, &args); | 136 | try addLibcTopHalfIncludes(comp, arena, &args); |
| 137 | | 137 | |
| 138 | for (libc_top_half_src_files) |file_path| { | 138 | for (libc_top_half_src_files) |file_path| { |
| ... | @@ -149,7 +149,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr | ... | @@ -149,7 +149,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 149 | }, | 149 | }, |
| 150 | .libwasi_emulated_process_clocks_a => { | 150 | .libwasi_emulated_process_clocks_a => { |
| 151 | var args = std.ArrayList([]const u8).init(arena); | 151 | var args = std.ArrayList([]const u8).init(arena); |
| 152 | try addCCArgs(comp, arena, &args, true); | 152 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| 153 | try addLibcBottomHalfIncludes(comp, arena, &args); | 153 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 154 | | 154 | |
| 155 | var emu_clocks_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | 155 | var emu_clocks_sources = std.ArrayList(Compilation.CSourceFile).init(arena); |
| ... | @@ -165,7 +165,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr | ... | @@ -165,7 +165,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 165 | }, | 165 | }, |
| 166 | .libwasi_emulated_getpid_a => { | 166 | .libwasi_emulated_getpid_a => { |
| 167 | var args = std.ArrayList([]const u8).init(arena); | 167 | var args = std.ArrayList([]const u8).init(arena); |
| 168 | try addCCArgs(comp, arena, &args, true); | 168 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| 169 | try addLibcBottomHalfIncludes(comp, arena, &args); | 169 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 170 | | 170 | |
| 171 | var emu_getpid_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | 171 | var emu_getpid_sources = std.ArrayList(Compilation.CSourceFile).init(arena); |
| ... | @@ -181,7 +181,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr | ... | @@ -181,7 +181,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 181 | }, | 181 | }, |
| 182 | .libwasi_emulated_mman_a => { | 182 | .libwasi_emulated_mman_a => { |
| 183 | var args = std.ArrayList([]const u8).init(arena); | 183 | var args = std.ArrayList([]const u8).init(arena); |
| 184 | try addCCArgs(comp, arena, &args, true); | 184 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| 185 | try addLibcBottomHalfIncludes(comp, arena, &args); | 185 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 186 | | 186 | |
| 187 | var emu_mman_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | 187 | var emu_mman_sources = std.ArrayList(Compilation.CSourceFile).init(arena); |
| ... | @@ -200,7 +200,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr | ... | @@ -200,7 +200,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 200 | | 200 | |
| 201 | { | 201 | { |
| 202 | var args = std.ArrayList([]const u8).init(arena); | 202 | var args = std.ArrayList([]const u8).init(arena); |
| 203 | try addCCArgs(comp, arena, &args, true); | 203 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| 204 | | 204 | |
| 205 | for (emulated_signal_bottom_half_src_files) |file_path| { | 205 | for (emulated_signal_bottom_half_src_files) |file_path| { |
| 206 | try emu_signal_sources.append(.{ | 206 | try emu_signal_sources.append(.{ |
| ... | @@ -214,7 +214,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr | ... | @@ -214,7 +214,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 214 | | 214 | |
| 215 | { | 215 | { |
| 216 | var args = std.ArrayList([]const u8).init(arena); | 216 | var args = std.ArrayList([]const u8).init(arena); |
| 217 | try addCCArgs(comp, arena, &args, true); | 217 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| 218 | try addLibcTopHalfIncludes(comp, arena, &args); | 218 | try addLibcTopHalfIncludes(comp, arena, &args); |
| 219 | try args.append("-D_WASI_EMULATED_SIGNAL"); | 219 | try args.append("-D_WASI_EMULATED_SIGNAL"); |
| 220 | | 220 | |
| ... | @@ -249,17 +249,22 @@ fn sanitize(arena: Allocator, file_path: []const u8) ![]const u8 { | ... | @@ -249,17 +249,22 @@ fn sanitize(arena: Allocator, file_path: []const u8) ![]const u8 { |
| 249 | return out_path; | 249 | return out_path; |
| 250 | } | 250 | } |
| 251 | | 251 | |
| | 252 | const CCOptions = struct { |
| | 253 | want_O3: bool = false, |
| | 254 | no_strict_aliasing: bool = false, |
| | 255 | }; |
| | 256 | |
| 252 | fn addCCArgs( | 257 | fn addCCArgs( |
| 253 | comp: *Compilation, | 258 | comp: *Compilation, |
| 254 | arena: Allocator, | 259 | arena: Allocator, |
| 255 | args: *std.ArrayList([]const u8), | 260 | args: *std.ArrayList([]const u8), |
| 256 | want_O3: bool, | 261 | options: CCOptions, |
| 257 | ) error{OutOfMemory}!void { | 262 | ) error{OutOfMemory}!void { |
| 258 | const target = comp.getTarget(); | 263 | const target = comp.getTarget(); |
| 259 | const arch_name = musl.archNameHeaders(target.cpu.arch); | 264 | const arch_name = musl.archNameHeaders(target.cpu.arch); |
| 260 | const os_name = @tagName(target.os.tag); | 265 | const os_name = @tagName(target.os.tag); |
| 261 | const triple = try std.fmt.allocPrint(arena, "{s}-{s}-musl", .{ arch_name, os_name }); | 266 | const triple = try std.fmt.allocPrint(arena, "{s}-{s}-musl", .{ arch_name, os_name }); |
| 262 | const o_arg = if (want_O3) "-O3" else "-Os"; | 267 | const o_arg = if (options.want_O3) "-O3" else "-Os"; |
| 263 | | 268 | |
| 264 | try args.appendSlice(&[_][]const u8{ | 269 | try args.appendSlice(&[_][]const u8{ |
| 265 | "-std=gnu17", | 270 | "-std=gnu17", |
| ... | @@ -280,6 +285,10 @@ fn addCCArgs( | ... | @@ -280,6 +285,10 @@ fn addCCArgs( |
| 280 | | 285 | |
| 281 | "-DBULK_MEMORY_THRESHOLD=32", | 286 | "-DBULK_MEMORY_THRESHOLD=32", |
| 282 | }); | 287 | }); |
| | 288 | |
| | 289 | if (options.no_strict_aliasing) { |
| | 290 | try args.appendSlice(&[_][]const u8{"-fno-strict-aliasing"}); |
| | 291 | } |
| 283 | } | 292 | } |
| 284 | | 293 | |
| 285 | fn addLibcBottomHalfIncludes( | 294 | fn addLibcBottomHalfIncludes( |