| ... | ... | @@ -72,7 +72,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 72 | 72 | switch (crt_file) { |
| 73 | 73 | .crt1_reactor_o => { |
| 74 | 74 | var args = std.ArrayList([]const u8).init(arena); |
| 75 | | try addCCArgs(comp, arena, &args, false); |
| 75 | try addCCArgs(comp, arena, &args, .{}); |
| 76 | 76 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 77 | 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 | 85 | }, |
| 86 | 86 | .crt1_command_o => { |
| 87 | 87 | var args = std.ArrayList([]const u8).init(arena); |
| 88 | | try addCCArgs(comp, arena, &args, false); |
| 88 | try addCCArgs(comp, arena, &args, .{}); |
| 89 | 89 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 90 | 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 | 102 | { |
| 103 | 103 | // Compile emmalloc. |
| 104 | 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 | 106 | for (emmalloc_src_files) |file_path| { |
| 107 | 107 | try libc_sources.append(.{ |
| 108 | 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 | 116 | { |
| 117 | 117 | // Compile libc-bottom-half. |
| 118 | 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 | 120 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 121 | 121 | |
| 122 | 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 | 132 | { |
| 133 | 133 | // Compile libc-top-half. |
| 134 | 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 | 136 | try addLibcTopHalfIncludes(comp, arena, &args); |
| 137 | 137 | |
| 138 | 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 | 149 | }, |
| 150 | 150 | .libwasi_emulated_process_clocks_a => { |
| 151 | 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 | 153 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 154 | 154 | |
| 155 | 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 | 165 | }, |
| 166 | 166 | .libwasi_emulated_getpid_a => { |
| 167 | 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 | 169 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 170 | 170 | |
| 171 | 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 | 181 | }, |
| 182 | 182 | .libwasi_emulated_mman_a => { |
| 183 | 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 | 185 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 186 | 186 | |
| 187 | 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 | 200 | |
| 201 | 201 | { |
| 202 | 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 | 205 | for (emulated_signal_bottom_half_src_files) |file_path| { |
| 206 | 206 | try emu_signal_sources.append(.{ |
| ... | ... | @@ -214,7 +214,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 214 | 214 | |
| 215 | 215 | { |
| 216 | 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 | 218 | try addLibcTopHalfIncludes(comp, arena, &args); |
| 219 | 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 | 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 | 257 | fn addCCArgs( |
| 253 | 258 | comp: *Compilation, |
| 254 | 259 | arena: Allocator, |
| 255 | 260 | args: *std.ArrayList([]const u8), |
| 256 | | want_O3: bool, |
| 261 | options: CCOptions, |
| 257 | 262 | ) error{OutOfMemory}!void { |
| 258 | 263 | const target = comp.getTarget(); |
| 259 | 264 | const arch_name = musl.archNameHeaders(target.cpu.arch); |
| 260 | 265 | const os_name = @tagName(target.os.tag); |
| 261 | 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 | 269 | try args.appendSlice(&[_][]const u8{ |
| 265 | 270 | "-std=gnu17", |
| ... | ... | @@ -280,6 +285,10 @@ fn addCCArgs( |
| 280 | 285 | |
| 281 | 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 | 294 | fn addLibcBottomHalfIncludes( |