| ... | ... | @@ -11,7 +11,7 @@ const linux_x64 = std.zig.CrossTarget{ |
| 11 | 11 | .os_tag = .linux, |
| 12 | 12 | }; |
| 13 | 13 | |
| 14 | | const macosx_x64 = std.zig.CrossTarget{ |
| 14 | const macos_x64 = std.zig.CrossTarget{ |
| 15 | 15 | .cpu_arch = .x86_64, |
| 16 | 16 | .os_tag = .macos, |
| 17 | 17 | }; |
| ... | ... | @@ -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 | 150 | case.addError("", &[_][]const u8{"error: no entry point found"}); |
| 151 | 151 | |
| 152 | 152 | // Incorrect return type |
| ... | ... | @@ -157,97 +157,75 @@ pub fn addCases(ctx: *TestContext) !void { |
| 157 | 157 | |
| 158 | 158 | // Regular old hello world |
| 159 | 159 | case.addCompareOutput( |
| 160 | \\extern "c" fn write(usize, usize, usize) usize; |
| 161 | \\extern "c" fn exit(usize) noreturn; |
| 162 | \\ |
| 160 | 163 | \\export fn _start() noreturn { |
| 161 | 164 | \\ print(); |
| 162 | 165 | \\ |
| 163 | | \\ exit(); |
| 166 | \\ exit(0); |
| 164 | 167 | \\} |
| 165 | 168 | \\ |
| 166 | 169 | \\fn print() void { |
| 167 | | \\ asm volatile ("syscall" |
| 168 | | \\ : |
| 169 | | \\ : [number] "{rax}" (0x2000004), |
| 170 | | \\ [arg1] "{rdi}" (1), |
| 171 | | \\ [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")), |
| 172 | | \\ [arg3] "{rdx}" (14) |
| 173 | | \\ : "memory" |
| 174 | | \\ ); |
| 175 | | \\ return; |
| 170 | \\ const msg = @ptrToInt("Hello, World!\n"); |
| 171 | \\ const len = 14; |
| 172 | \\ const nwritten = write(1, msg, len); |
| 173 | \\ assert(nwritten == len); |
| 176 | 174 | \\} |
| 177 | 175 | \\ |
| 178 | | \\fn exit() noreturn { |
| 179 | | \\ asm volatile ("syscall" |
| 180 | | \\ : |
| 181 | | \\ : [number] "{rax}" (0x2000001), |
| 182 | | \\ [arg1] "{rdi}" (0) |
| 183 | | \\ : "memory" |
| 184 | | \\ ); |
| 185 | | \\ unreachable; |
| 176 | \\fn assert(ok: bool) void { |
| 177 | \\ if (!ok) unreachable; // assertion failure |
| 186 | 178 | \\} |
| 187 | 179 | , |
| 188 | 180 | "Hello, World!\n", |
| 189 | 181 | ); |
| 182 | |
| 190 | 183 | // Now change the message only |
| 191 | 184 | case.addCompareOutput( |
| 185 | \\extern "c" fn write(usize, usize, usize) usize; |
| 186 | \\extern "c" fn exit(usize) noreturn; |
| 187 | \\ |
| 192 | 188 | \\export fn _start() noreturn { |
| 193 | 189 | \\ print(); |
| 194 | 190 | \\ |
| 195 | | \\ exit(); |
| 191 | \\ exit(0); |
| 196 | 192 | \\} |
| 197 | 193 | \\ |
| 198 | 194 | \\fn print() void { |
| 199 | | \\ asm volatile ("syscall" |
| 200 | | \\ : |
| 201 | | \\ : [number] "{rax}" (0x2000004), |
| 202 | | \\ [arg1] "{rdi}" (1), |
| 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; |
| 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"); |
| 196 | \\ const len = 104; |
| 197 | \\ const nwritten = write(1, msg, len); |
| 198 | \\ assert(nwritten == len); |
| 208 | 199 | \\} |
| 209 | 200 | \\ |
| 210 | | \\fn exit() noreturn { |
| 211 | | \\ asm volatile ("syscall" |
| 212 | | \\ : |
| 213 | | \\ : [number] "{rax}" (0x2000001), |
| 214 | | \\ [arg1] "{rdi}" (0) |
| 215 | | \\ : "memory" |
| 216 | | \\ ); |
| 217 | | \\ unreachable; |
| 201 | \\fn assert(ok: bool) void { |
| 202 | \\ if (!ok) unreachable; // assertion failure |
| 218 | 203 | \\} |
| 219 | 204 | , |
| 220 | 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 | 208 | // Now we print it twice. |
| 223 | 209 | case.addCompareOutput( |
| 210 | \\extern "c" fn write(usize, usize, usize) usize; |
| 211 | \\extern "c" fn exit(usize) noreturn; |
| 212 | \\ |
| 224 | 213 | \\export fn _start() noreturn { |
| 225 | 214 | \\ print(); |
| 226 | 215 | \\ print(); |
| 227 | 216 | \\ |
| 228 | | \\ exit(); |
| 217 | \\ exit(0); |
| 229 | 218 | \\} |
| 230 | 219 | \\ |
| 231 | 220 | \\fn print() void { |
| 232 | | \\ asm volatile ("syscall" |
| 233 | | \\ : |
| 234 | | \\ : [number] "{rax}" (0x2000004), |
| 235 | | \\ [arg1] "{rdi}" (1), |
| 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; |
| 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"); |
| 222 | \\ const len = 104; |
| 223 | \\ const nwritten = write(1, msg, len); |
| 224 | \\ assert(nwritten == len); |
| 241 | 225 | \\} |
| 242 | 226 | \\ |
| 243 | | \\fn exit() noreturn { |
| 244 | | \\ asm volatile ("syscall" |
| 245 | | \\ : |
| 246 | | \\ : [number] "{rax}" (0x2000001), |
| 247 | | \\ [arg1] "{rdi}" (0) |
| 248 | | \\ : "memory" |
| 249 | | \\ ); |
| 250 | | \\ unreachable; |
| 227 | \\fn assert(ok: bool) void { |
| 228 | \\ if (!ok) unreachable; // assertion failure |
| 251 | 229 | \\} |
| 252 | 230 | , |
| 253 | 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 | 1508 | } |
| 1531 | 1509 | |
| 1532 | 1510 | { |
| 1533 | | var case = ctx.exe("hello world linked to libc", macosx_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); |
| 1511 | var case = ctx.exe("only libc exit", macos_x64); |
| 1552 | 1512 | |
| 1553 | 1513 | // This test case covers an infrequent scenarion where the string table *may* be relocated |
| 1554 | 1514 | // into the position preceeding the symbol table which results in a dyld error. |