| ... | @@ -11,7 +11,7 @@ const linux_x64 = std.zig.CrossTarget{ | ... | @@ -11,7 +11,7 @@ const linux_x64 = std.zig.CrossTarget{ |
| 11 | .os_tag = .linux, | 11 | .os_tag = .linux, |
| 12 | }; | 12 | }; |
| 13 | | 13 | |
| 14 | const macosx_x64 = std.zig.CrossTarget{ | 14 | const macos_x64 = std.zig.CrossTarget{ |
| 15 | .cpu_arch = .x86_64, | 15 | .cpu_arch = .x86_64, |
| 16 | .os_tag = .macos, | 16 | .os_tag = .macos, |
| 17 | }; | 17 | }; |
| ... | @@ -146,7 +146,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -146,7 +146,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 146 | } | 146 | } |
| 147 | | 147 | |
| 148 | { | 148 | { |
| 149 | var case = ctx.exe("hello world with updates", macosx_x64); | 149 | var case = ctx.exe("hello world with updates", macos_x64); |
| 150 | case.addError("", &[_][]const u8{"error: no entry point found"}); | 150 | case.addError("", &[_][]const u8{"error: no entry point found"}); |
| 151 | | 151 | |
| 152 | // Incorrect return type | 152 | // Incorrect return type |
| ... | @@ -157,97 +157,75 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -157,97 +157,75 @@ pub fn addCases(ctx: *TestContext) !void { |
| 157 | | 157 | |
| 158 | // Regular old hello world | 158 | // Regular old hello world |
| 159 | case.addCompareOutput( | 159 | case.addCompareOutput( |
| | 160 | \\extern "c" fn write(usize, usize, usize) usize; |
| | 161 | \\extern "c" fn exit(usize) noreturn; |
| | 162 | \\ |
| 160 | \\export fn _start() noreturn { | 163 | \\export fn _start() noreturn { |
| 161 | \\ print(); | 164 | \\ print(); |
| 162 | \\ | 165 | \\ |
| 163 | \\ exit(); | 166 | \\ exit(0); |
| 164 | \\} | 167 | \\} |
| 165 | \\ | 168 | \\ |
| 166 | \\fn print() void { | 169 | \\fn print() void { |
| 167 | \\ asm volatile ("syscall" | 170 | \\ const msg = @ptrToInt("Hello, World!\n"); |
| 168 | \\ : | 171 | \\ const len = 14; |
| 169 | \\ : [number] "{rax}" (0x2000004), | 172 | \\ const nwritten = write(1, msg, len); |
| 170 | \\ [arg1] "{rdi}" (1), | 173 | \\ assert(nwritten == len); |
| 171 | \\ [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")), | | |
| 172 | \\ [arg3] "{rdx}" (14) | | |
| 173 | \\ : "memory" | | |
| 174 | \\ ); | | |
| 175 | \\ return; | | |
| 176 | \\} | 174 | \\} |
| 177 | \\ | 175 | \\ |
| 178 | \\fn exit() noreturn { | 176 | \\fn assert(ok: bool) void { |
| 179 | \\ asm volatile ("syscall" | 177 | \\ if (!ok) unreachable; // assertion failure |
| 180 | \\ : | | |
| 181 | \\ : [number] "{rax}" (0x2000001), | | |
| 182 | \\ [arg1] "{rdi}" (0) | | |
| 183 | \\ : "memory" | | |
| 184 | \\ ); | | |
| 185 | \\ unreachable; | | |
| 186 | \\} | 178 | \\} |
| 187 | , | 179 | , |
| 188 | "Hello, World!\n", | 180 | "Hello, World!\n", |
| 189 | ); | 181 | ); |
| | 182 | |
| 190 | // Now change the message only | 183 | // Now change the message only |
| 191 | case.addCompareOutput( | 184 | case.addCompareOutput( |
| | 185 | \\extern "c" fn write(usize, usize, usize) usize; |
| | 186 | \\extern "c" fn exit(usize) noreturn; |
| | 187 | \\ |
| 192 | \\export fn _start() noreturn { | 188 | \\export fn _start() noreturn { |
| 193 | \\ print(); | 189 | \\ print(); |
| 194 | \\ | 190 | \\ |
| 195 | \\ exit(); | 191 | \\ exit(0); |
| 196 | \\} | 192 | \\} |
| 197 | \\ | 193 | \\ |
| 198 | \\fn print() void { | 194 | \\fn print() void { |
| 199 | \\ asm volatile ("syscall" | 195 | \\ const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n"); |
| 200 | \\ : | 196 | \\ const len = 104; |
| 201 | \\ : [number] "{rax}" (0x2000004), | 197 | \\ const nwritten = write(1, msg, len); |
| 202 | \\ [arg1] "{rdi}" (1), | 198 | \\ assert(nwritten == len); |
| 203 | \\ [arg2] "{rsi}" (@ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n")), | | |
| 204 | \\ [arg3] "{rdx}" (104) | | |
| 205 | \\ : "memory" | | |
| 206 | \\ ); | | |
| 207 | \\ return; | | |
| 208 | \\} | 199 | \\} |
| 209 | \\ | 200 | \\ |
| 210 | \\fn exit() noreturn { | 201 | \\fn assert(ok: bool) void { |
| 211 | \\ asm volatile ("syscall" | 202 | \\ if (!ok) unreachable; // assertion failure |
| 212 | \\ : | | |
| 213 | \\ : [number] "{rax}" (0x2000001), | | |
| 214 | \\ [arg1] "{rdi}" (0) | | |
| 215 | \\ : "memory" | | |
| 216 | \\ ); | | |
| 217 | \\ unreachable; | | |
| 218 | \\} | 203 | \\} |
| 219 | , | 204 | , |
| 220 | "What is up? This is a longer message that will force the data to be relocated in virtual address space.\n", | 205 | "What is up? This is a longer message that will force the data to be relocated in virtual address space.\n", |
| 221 | ); | 206 | ); |
| | 207 | |
| 222 | // Now we print it twice. | 208 | // Now we print it twice. |
| 223 | case.addCompareOutput( | 209 | case.addCompareOutput( |
| | 210 | \\extern "c" fn write(usize, usize, usize) usize; |
| | 211 | \\extern "c" fn exit(usize) noreturn; |
| | 212 | \\ |
| 224 | \\export fn _start() noreturn { | 213 | \\export fn _start() noreturn { |
| 225 | \\ print(); | 214 | \\ print(); |
| 226 | \\ print(); | 215 | \\ print(); |
| 227 | \\ | 216 | \\ |
| 228 | \\ exit(); | 217 | \\ exit(0); |
| 229 | \\} | 218 | \\} |
| 230 | \\ | 219 | \\ |
| 231 | \\fn print() void { | 220 | \\fn print() void { |
| 232 | \\ asm volatile ("syscall" | 221 | \\ const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n"); |
| 233 | \\ : | 222 | \\ const len = 104; |
| 234 | \\ : [number] "{rax}" (0x2000004), | 223 | \\ const nwritten = write(1, msg, len); |
| 235 | \\ [arg1] "{rdi}" (1), | 224 | \\ assert(nwritten == len); |
| 236 | \\ [arg2] "{rsi}" (@ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n")), | | |
| 237 | \\ [arg3] "{rdx}" (104) | | |
| 238 | \\ : "memory" | | |
| 239 | \\ ); | | |
| 240 | \\ return; | | |
| 241 | \\} | 225 | \\} |
| 242 | \\ | 226 | \\ |
| 243 | \\fn exit() noreturn { | 227 | \\fn assert(ok: bool) void { |
| 244 | \\ asm volatile ("syscall" | 228 | \\ if (!ok) unreachable; // assertion failure |
| 245 | \\ : | | |
| 246 | \\ : [number] "{rax}" (0x2000001), | | |
| 247 | \\ [arg1] "{rdi}" (0) | | |
| 248 | \\ : "memory" | | |
| 249 | \\ ); | | |
| 250 | \\ unreachable; | | |
| 251 | \\} | 229 | \\} |
| 252 | , | 230 | , |
| 253 | \\What is up? This is a longer message that will force the data to be relocated in virtual address space. | 231 | \\What is up? This is a longer message that will force the data to be relocated in virtual address space. |
| ... | @@ -1530,25 +1508,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1530,25 +1508,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1530 | } | 1508 | } |
| 1531 | | 1509 | |
| 1532 | { | 1510 | { |
| 1533 | var case = ctx.exe("hello world linked to libc", macosx_x64); | 1511 | var case = ctx.exe("only libc exit", macos_x64); |
| 1534 | | | |
| 1535 | // TODO rewrite this test once we handle more int conversions and return args. | | |
| 1536 | case.addCompareOutput( | | |
| 1537 | \\extern "c" fn write(usize, usize, usize) void; | | |
| 1538 | \\extern "c" fn exit(usize) noreturn; | | |
| 1539 | \\ | | |
| 1540 | \\export fn _start() noreturn { | | |
| 1541 | \\ write(1, @ptrToInt("Hello,"), 6); | | |
| 1542 | \\ write(1, @ptrToInt(" World!\n,"), 8); | | |
| 1543 | \\ exit(0); | | |
| 1544 | \\} | | |
| 1545 | , | | |
| 1546 | "Hello, World!\n", | | |
| 1547 | ); | | |
| 1548 | } | | |
| 1549 | | | |
| 1550 | { | | |
| 1551 | var case = ctx.exe("only libc exit", macosx_x64); | | |
| 1552 | | 1512 | |
| 1553 | // This test case covers an infrequent scenarion where the string table *may* be relocated | 1513 | // This test case covers an infrequent scenarion where the string table *may* be relocated |
| 1554 | // into the position preceeding the symbol table which results in a dyld error. | 1514 | // into the position preceeding the symbol table which results in a dyld error. |