| ... | @@ -1282,10 +1282,17 @@ pub fn commitDeclState( | ... | @@ -1282,10 +1282,17 @@ pub fn commitDeclState( |
| 1282 | try pwriteDbgLineNops(elf_file.base.file.?, file_pos, 0, &[0]u8{}, src_fn.len); | 1282 | try pwriteDbgLineNops(elf_file.base.file.?, file_pos, 0, &[0]u8{}, src_fn.len); |
| 1283 | }, | 1283 | }, |
| 1284 | .macho => { | 1284 | .macho => { |
| 1285 | const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?; | 1285 | const macho_file = self.bin_file.cast(File.MachO).?; |
| 1286 | const debug_line_sect = d_sym.getSectionPtr(d_sym.debug_line_section_index.?); | 1286 | if (macho_file.base.isRelocatable()) { |
| 1287 | const file_pos = debug_line_sect.offset + src_fn.off; | 1287 | const debug_line_sect = &macho_file.sections.items(.header)[macho_file.debug_line_sect_index.?]; |
| 1288 | try pwriteDbgLineNops(d_sym.file, file_pos, 0, &[0]u8{}, src_fn.len); | 1288 | const file_pos = debug_line_sect.offset + src_fn.off; |
| | 1289 | try pwriteDbgLineNops(macho_file.base.file.?, file_pos, 0, &[0]u8{}, src_fn.len); |
| | 1290 | } else { |
| | 1291 | const d_sym = macho_file.getDebugSymbols().?; |
| | 1292 | const debug_line_sect = d_sym.getSectionPtr(d_sym.debug_line_section_index.?); |
| | 1293 | const file_pos = debug_line_sect.offset + src_fn.off; |
| | 1294 | try pwriteDbgLineNops(d_sym.file, file_pos, 0, &[0]u8{}, src_fn.len); |
| | 1295 | } |
| 1289 | }, | 1296 | }, |
| 1290 | .wasm => { | 1297 | .wasm => { |
| 1291 | const wasm_file = self.bin_file.cast(File.Wasm).?; | 1298 | const wasm_file = self.bin_file.cast(File.Wasm).?; |
| ... | @@ -1352,18 +1359,32 @@ pub fn commitDeclState( | ... | @@ -1352,18 +1359,32 @@ pub fn commitDeclState( |
| 1352 | | 1359 | |
| 1353 | .macho => { | 1360 | .macho => { |
| 1354 | const macho_file = self.bin_file.cast(File.MachO).?; | 1361 | const macho_file = self.bin_file.cast(File.MachO).?; |
| 1355 | const d_sym = macho_file.getDebugSymbols().?; | 1362 | if (macho_file.base.isRelocatable()) { |
| 1356 | const sect_index = d_sym.debug_line_section_index.?; | 1363 | const sect_index = macho_file.debug_line_sect_index.?; |
| 1357 | try d_sym.growSection(sect_index, needed_size, true, macho_file); | 1364 | try macho_file.growSection(sect_index, needed_size); |
| 1358 | const sect = d_sym.getSection(sect_index); | 1365 | const sect = macho_file.sections.items(.header)[sect_index]; |
| 1359 | const file_pos = sect.offset + src_fn.off; | 1366 | const file_pos = sect.offset + src_fn.off; |
| 1360 | try pwriteDbgLineNops( | 1367 | try pwriteDbgLineNops( |
| 1361 | d_sym.file, | 1368 | macho_file.base.file.?, |
| 1362 | file_pos, | 1369 | file_pos, |
| 1363 | prev_padding_size, | 1370 | prev_padding_size, |
| 1364 | dbg_line_buffer.items, | 1371 | dbg_line_buffer.items, |
| 1365 | next_padding_size, | 1372 | next_padding_size, |
| 1366 | ); | 1373 | ); |
| | 1374 | } else { |
| | 1375 | const d_sym = macho_file.getDebugSymbols().?; |
| | 1376 | const sect_index = d_sym.debug_line_section_index.?; |
| | 1377 | try d_sym.growSection(sect_index, needed_size, true, macho_file); |
| | 1378 | const sect = d_sym.getSection(sect_index); |
| | 1379 | const file_pos = sect.offset + src_fn.off; |
| | 1380 | try pwriteDbgLineNops( |
| | 1381 | d_sym.file, |
| | 1382 | file_pos, |
| | 1383 | prev_padding_size, |
| | 1384 | dbg_line_buffer.items, |
| | 1385 | next_padding_size, |
| | 1386 | ); |
| | 1387 | } |
| 1367 | }, | 1388 | }, |
| 1368 | | 1389 | |
| 1369 | .wasm => { | 1390 | .wasm => { |
| ... | @@ -1460,16 +1481,21 @@ pub fn commitDeclState( | ... | @@ -1460,16 +1481,21 @@ pub fn commitDeclState( |
| 1460 | while (decl_state.exprloc_relocs.popOrNull()) |reloc| { | 1481 | while (decl_state.exprloc_relocs.popOrNull()) |reloc| { |
| 1461 | switch (self.bin_file.tag) { | 1482 | switch (self.bin_file.tag) { |
| 1462 | .macho => { | 1483 | .macho => { |
| 1463 | const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?; | 1484 | const macho_file = self.bin_file.cast(File.MachO).?; |
| 1464 | try d_sym.relocs.append(d_sym.allocator, .{ | 1485 | if (macho_file.base.isRelocatable()) { |
| 1465 | .type = switch (reloc.type) { | 1486 | // TODO |
| 1466 | .direct_load => .direct_load, | 1487 | } else { |
| 1467 | .got_load => .got_load, | 1488 | const d_sym = macho_file.getDebugSymbols().?; |
| 1468 | }, | 1489 | try d_sym.relocs.append(d_sym.allocator, .{ |
| 1469 | .target = reloc.target, | 1490 | .type = switch (reloc.type) { |
| 1470 | .offset = reloc.offset + self.getAtom(.di_atom, di_atom_index).off, | 1491 | .direct_load => .direct_load, |
| 1471 | .addend = 0, | 1492 | .got_load => .got_load, |
| 1472 | }); | 1493 | }, |
| | 1494 | .target = reloc.target, |
| | 1495 | .offset = reloc.offset + self.getAtom(.di_atom, di_atom_index).off, |
| | 1496 | .addend = 0, |
| | 1497 | }); |
| | 1498 | } |
| 1473 | }, | 1499 | }, |
| 1474 | .elf => {}, // TODO | 1500 | .elf => {}, // TODO |
| 1475 | else => unreachable, | 1501 | else => unreachable, |
| ... | @@ -1512,10 +1538,17 @@ fn updateDeclDebugInfoAllocation(self: *Dwarf, atom_index: Atom.Index, len: u32) | ... | @@ -1512,10 +1538,17 @@ fn updateDeclDebugInfoAllocation(self: *Dwarf, atom_index: Atom.Index, len: u32) |
| 1512 | try pwriteDbgInfoNops(elf_file.base.file.?, file_pos, 0, &[0]u8{}, atom.len, false); | 1538 | try pwriteDbgInfoNops(elf_file.base.file.?, file_pos, 0, &[0]u8{}, atom.len, false); |
| 1513 | }, | 1539 | }, |
| 1514 | .macho => { | 1540 | .macho => { |
| 1515 | const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?; | 1541 | const macho_file = self.bin_file.cast(File.MachO).?; |
| 1516 | const debug_info_sect = d_sym.getSectionPtr(d_sym.debug_info_section_index.?); | 1542 | if (macho_file.base.isRelocatable()) { |
| 1517 | const file_pos = debug_info_sect.offset + atom.off; | 1543 | const debug_info_sect = macho_file.sections.items(.header)[macho_file.debug_info_sect_index.?]; |
| 1518 | try pwriteDbgInfoNops(d_sym.file, file_pos, 0, &[0]u8{}, atom.len, false); | 1544 | const file_pos = debug_info_sect.offset + atom.off; |
| | 1545 | try pwriteDbgInfoNops(macho_file.base.file.?, file_pos, 0, &[0]u8{}, atom.len, false); |
| | 1546 | } else { |
| | 1547 | const d_sym = macho_file.getDebugSymbols().?; |
| | 1548 | const debug_info_sect = d_sym.getSectionPtr(d_sym.debug_info_section_index.?); |
| | 1549 | const file_pos = debug_info_sect.offset + atom.off; |
| | 1550 | try pwriteDbgInfoNops(d_sym.file, file_pos, 0, &[0]u8{}, atom.len, false); |
| | 1551 | } |
| 1519 | }, | 1552 | }, |
| 1520 | .wasm => { | 1553 | .wasm => { |
| 1521 | const wasm_file = self.bin_file.cast(File.Wasm).?; | 1554 | const wasm_file = self.bin_file.cast(File.Wasm).?; |
| ... | @@ -1599,19 +1632,34 @@ fn writeDeclDebugInfo(self: *Dwarf, atom_index: Atom.Index, dbg_info_buf: []cons | ... | @@ -1599,19 +1632,34 @@ fn writeDeclDebugInfo(self: *Dwarf, atom_index: Atom.Index, dbg_info_buf: []cons |
| 1599 | | 1632 | |
| 1600 | .macho => { | 1633 | .macho => { |
| 1601 | const macho_file = self.bin_file.cast(File.MachO).?; | 1634 | const macho_file = self.bin_file.cast(File.MachO).?; |
| 1602 | const d_sym = macho_file.getDebugSymbols().?; | 1635 | if (macho_file.base.isRelocatable()) { |
| 1603 | const sect_index = d_sym.debug_info_section_index.?; | 1636 | const sect_index = macho_file.debug_info_sect_index.?; |
| 1604 | try d_sym.growSection(sect_index, needed_size, true, macho_file); | 1637 | try macho_file.growSection(sect_index, needed_size); |
| 1605 | const sect = d_sym.getSection(sect_index); | 1638 | const sect = macho_file.sections.items(.header)[sect_index]; |
| 1606 | const file_pos = sect.offset + atom.off; | 1639 | const file_pos = sect.offset + atom.off; |
| 1607 | try pwriteDbgInfoNops( | 1640 | try pwriteDbgInfoNops( |
| 1608 | d_sym.file, | 1641 | macho_file.base.file.?, |
| 1609 | file_pos, | 1642 | file_pos, |
| 1610 | prev_padding_size, | 1643 | prev_padding_size, |
| 1611 | dbg_info_buf, | 1644 | dbg_info_buf, |
| 1612 | next_padding_size, | 1645 | next_padding_size, |
| 1613 | trailing_zero, | 1646 | trailing_zero, |
| 1614 | ); | 1647 | ); |
| | 1648 | } else { |
| | 1649 | const d_sym = macho_file.getDebugSymbols().?; |
| | 1650 | const sect_index = d_sym.debug_info_section_index.?; |
| | 1651 | try d_sym.growSection(sect_index, needed_size, true, macho_file); |
| | 1652 | const sect = d_sym.getSection(sect_index); |
| | 1653 | const file_pos = sect.offset + atom.off; |
| | 1654 | try pwriteDbgInfoNops( |
| | 1655 | d_sym.file, |
| | 1656 | file_pos, |
| | 1657 | prev_padding_size, |
| | 1658 | dbg_info_buf, |
| | 1659 | next_padding_size, |
| | 1660 | trailing_zero, |
| | 1661 | ); |
| | 1662 | } |
| 1615 | }, | 1663 | }, |
| 1616 | | 1664 | |
| 1617 | .wasm => { | 1665 | .wasm => { |
| ... | @@ -1672,10 +1720,17 @@ pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: InternPool.D | ... | @@ -1672,10 +1720,17 @@ pub fn updateDeclLineNumber(self: *Dwarf, mod: *Module, decl_index: InternPool.D |
| 1672 | try elf_file.base.file.?.pwriteAll(&data, file_pos); | 1720 | try elf_file.base.file.?.pwriteAll(&data, file_pos); |
| 1673 | }, | 1721 | }, |
| 1674 | .macho => { | 1722 | .macho => { |
| 1675 | const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?; | 1723 | const macho_file = self.bin_file.cast(File.MachO).?; |
| 1676 | const sect = d_sym.getSection(d_sym.debug_line_section_index.?); | 1724 | if (macho_file.base.isRelocatable()) { |
| 1677 | const file_pos = sect.offset + atom.off + self.getRelocDbgLineOff(); | 1725 | const sect = macho_file.sections.items(.header)[macho_file.debug_line_sect_index.?]; |
| 1678 | try d_sym.file.pwriteAll(&data, file_pos); | 1726 | const file_pos = sect.offset + atom.off + self.getRelocDbgLineOff(); |
| | 1727 | try macho_file.base.file.?.pwriteAll(&data, file_pos); |
| | 1728 | } else { |
| | 1729 | const d_sym = macho_file.getDebugSymbols().?; |
| | 1730 | const sect = d_sym.getSection(d_sym.debug_line_section_index.?); |
| | 1731 | const file_pos = sect.offset + atom.off + self.getRelocDbgLineOff(); |
| | 1732 | try d_sym.file.pwriteAll(&data, file_pos); |
| | 1733 | } |
| 1679 | }, | 1734 | }, |
| 1680 | .wasm => { | 1735 | .wasm => { |
| 1681 | const wasm_file = self.bin_file.cast(File.Wasm).?; | 1736 | const wasm_file = self.bin_file.cast(File.Wasm).?; |
| ... | @@ -1880,12 +1935,20 @@ pub fn writeDbgAbbrev(self: *Dwarf) !void { | ... | @@ -1880,12 +1935,20 @@ pub fn writeDbgAbbrev(self: *Dwarf) !void { |
| 1880 | }, | 1935 | }, |
| 1881 | .macho => { | 1936 | .macho => { |
| 1882 | const macho_file = self.bin_file.cast(File.MachO).?; | 1937 | const macho_file = self.bin_file.cast(File.MachO).?; |
| 1883 | const d_sym = macho_file.getDebugSymbols().?; | 1938 | if (macho_file.base.isRelocatable()) { |
| 1884 | const sect_index = d_sym.debug_abbrev_section_index.?; | 1939 | const sect_index = macho_file.debug_abbrev_sect_index.?; |
| 1885 | try d_sym.growSection(sect_index, needed_size, false, macho_file); | 1940 | try macho_file.growSection(sect_index, needed_size); |
| 1886 | const sect = d_sym.getSection(sect_index); | 1941 | const sect = macho_file.sections.items(.header)[sect_index]; |
| 1887 | const file_pos = sect.offset + abbrev_offset; | 1942 | const file_pos = sect.offset + abbrev_offset; |
| 1888 | try d_sym.file.pwriteAll(&abbrev_buf, file_pos); | 1943 | try macho_file.base.file.?.pwriteAll(&abbrev_buf, file_pos); |
| | 1944 | } else { |
| | 1945 | const d_sym = macho_file.getDebugSymbols().?; |
| | 1946 | const sect_index = d_sym.debug_abbrev_section_index.?; |
| | 1947 | try d_sym.growSection(sect_index, needed_size, false, macho_file); |
| | 1948 | const sect = d_sym.getSection(sect_index); |
| | 1949 | const file_pos = sect.offset + abbrev_offset; |
| | 1950 | try d_sym.file.pwriteAll(&abbrev_buf, file_pos); |
| | 1951 | } |
| 1889 | }, | 1952 | }, |
| 1890 | .wasm => { | 1953 | .wasm => { |
| 1891 | const wasm_file = self.bin_file.cast(File.Wasm).?; | 1954 | const wasm_file = self.bin_file.cast(File.Wasm).?; |
| ... | @@ -1970,10 +2033,17 @@ pub fn writeDbgInfoHeader(self: *Dwarf, zcu: *Module, low_pc: u64, high_pc: u64) | ... | @@ -1970,10 +2033,17 @@ pub fn writeDbgInfoHeader(self: *Dwarf, zcu: *Module, low_pc: u64, high_pc: u64) |
| 1970 | try pwriteDbgInfoNops(elf_file.base.file.?, file_pos, 0, di_buf.items, jmp_amt, false); | 2033 | try pwriteDbgInfoNops(elf_file.base.file.?, file_pos, 0, di_buf.items, jmp_amt, false); |
| 1971 | }, | 2034 | }, |
| 1972 | .macho => { | 2035 | .macho => { |
| 1973 | const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?; | 2036 | const macho_file = self.bin_file.cast(File.MachO).?; |
| 1974 | const debug_info_sect = d_sym.getSection(d_sym.debug_info_section_index.?); | 2037 | if (macho_file.base.isRelocatable()) { |
| 1975 | const file_pos = debug_info_sect.offset; | 2038 | const debug_info_sect = macho_file.sections.items(.header)[macho_file.debug_info_sect_index.?]; |
| 1976 | try pwriteDbgInfoNops(d_sym.file, file_pos, 0, di_buf.items, jmp_amt, false); | 2039 | const file_pos = debug_info_sect.offset; |
| | 2040 | try pwriteDbgInfoNops(macho_file.base.file.?, file_pos, 0, di_buf.items, jmp_amt, false); |
| | 2041 | } else { |
| | 2042 | const d_sym = macho_file.getDebugSymbols().?; |
| | 2043 | const debug_info_sect = d_sym.getSection(d_sym.debug_info_section_index.?); |
| | 2044 | const file_pos = debug_info_sect.offset; |
| | 2045 | try pwriteDbgInfoNops(d_sym.file, file_pos, 0, di_buf.items, jmp_amt, false); |
| | 2046 | } |
| 1977 | }, | 2047 | }, |
| 1978 | .wasm => { | 2048 | .wasm => { |
| 1979 | const wasm_file = self.bin_file.cast(File.Wasm).?; | 2049 | const wasm_file = self.bin_file.cast(File.Wasm).?; |
| ... | @@ -2296,12 +2366,20 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void { | ... | @@ -2296,12 +2366,20 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void { |
| 2296 | }, | 2366 | }, |
| 2297 | .macho => { | 2367 | .macho => { |
| 2298 | const macho_file = self.bin_file.cast(File.MachO).?; | 2368 | const macho_file = self.bin_file.cast(File.MachO).?; |
| 2299 | const d_sym = macho_file.getDebugSymbols().?; | 2369 | if (macho_file.base.isRelocatable()) { |
| 2300 | const sect_index = d_sym.debug_aranges_section_index.?; | 2370 | const sect_index = macho_file.debug_aranges_sect_index.?; |
| 2301 | try d_sym.growSection(sect_index, needed_size, false, macho_file); | 2371 | try macho_file.growSection(sect_index, needed_size); |
| 2302 | const sect = d_sym.getSection(sect_index); | 2372 | const sect = macho_file.sections.items(.header)[sect_index]; |
| 2303 | const file_pos = sect.offset; | 2373 | const file_pos = sect.offset; |
| 2304 | try d_sym.file.pwriteAll(di_buf.items, file_pos); | 2374 | try macho_file.base.file.?.pwriteAll(di_buf.items, file_pos); |
| | 2375 | } else { |
| | 2376 | const d_sym = macho_file.getDebugSymbols().?; |
| | 2377 | const sect_index = d_sym.debug_aranges_section_index.?; |
| | 2378 | try d_sym.growSection(sect_index, needed_size, false, macho_file); |
| | 2379 | const sect = d_sym.getSection(sect_index); |
| | 2380 | const file_pos = sect.offset; |
| | 2381 | try d_sym.file.pwriteAll(di_buf.items, file_pos); |
| | 2382 | } |
| 2305 | }, | 2383 | }, |
| 2306 | .wasm => { | 2384 | .wasm => { |
| 2307 | const wasm_file = self.bin_file.cast(File.Wasm).?; | 2385 | const wasm_file = self.bin_file.cast(File.Wasm).?; |
| ... | @@ -2437,16 +2515,28 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void { | ... | @@ -2437,16 +2515,28 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void { |
| 2437 | }, | 2515 | }, |
| 2438 | .macho => { | 2516 | .macho => { |
| 2439 | const macho_file = self.bin_file.cast(File.MachO).?; | 2517 | const macho_file = self.bin_file.cast(File.MachO).?; |
| 2440 | const d_sym = macho_file.getDebugSymbols().?; | 2518 | if (macho_file.base.isRelocatable()) { |
| 2441 | const sect_index = d_sym.debug_line_section_index.?; | 2519 | const sect_index = macho_file.debug_line_sect_index.?; |
| 2442 | const needed_size: u32 = @intCast(d_sym.getSection(sect_index).size + delta); | 2520 | const needed_size: u32 = @intCast(macho_file.sections.items(.header)[sect_index].size + delta); |
| 2443 | try d_sym.growSection(sect_index, needed_size, true, macho_file); | 2521 | try macho_file.growSection(sect_index, needed_size); |
| 2444 | const file_pos = d_sym.getSection(sect_index).offset + first_fn.off; | 2522 | const file_pos = macho_file.sections.items(.header)[sect_index].offset + first_fn.off; |
| 2445 | | 2523 | |
| 2446 | const amt = try d_sym.file.preadAll(buffer, file_pos); | 2524 | const amt = try macho_file.base.file.?.preadAll(buffer, file_pos); |
| 2447 | if (amt != buffer.len) return error.InputOutput; | 2525 | if (amt != buffer.len) return error.InputOutput; |
| | 2526 | |
| | 2527 | try macho_file.base.file.?.pwriteAll(buffer, file_pos + delta); |
| | 2528 | } else { |
| | 2529 | const d_sym = macho_file.getDebugSymbols().?; |
| | 2530 | const sect_index = d_sym.debug_line_section_index.?; |
| | 2531 | const needed_size: u32 = @intCast(d_sym.getSection(sect_index).size + delta); |
| | 2532 | try d_sym.growSection(sect_index, needed_size, true, macho_file); |
| | 2533 | const file_pos = d_sym.getSection(sect_index).offset + first_fn.off; |
| | 2534 | |
| | 2535 | const amt = try d_sym.file.preadAll(buffer, file_pos); |
| | 2536 | if (amt != buffer.len) return error.InputOutput; |
| 2448 | | 2537 | |
| 2449 | try d_sym.file.pwriteAll(buffer, file_pos + delta); | 2538 | try d_sym.file.pwriteAll(buffer, file_pos + delta); |
| | 2539 | } |
| 2450 | }, | 2540 | }, |
| 2451 | .wasm => { | 2541 | .wasm => { |
| 2452 | const wasm_file = self.bin_file.cast(File.Wasm).?; | 2542 | const wasm_file = self.bin_file.cast(File.Wasm).?; |
| ... | @@ -2492,10 +2582,17 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void { | ... | @@ -2492,10 +2582,17 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void { |
| 2492 | try pwriteDbgLineNops(elf_file.base.file.?, file_pos, 0, di_buf.items, jmp_amt); | 2582 | try pwriteDbgLineNops(elf_file.base.file.?, file_pos, 0, di_buf.items, jmp_amt); |
| 2493 | }, | 2583 | }, |
| 2494 | .macho => { | 2584 | .macho => { |
| 2495 | const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?; | 2585 | const macho_file = self.bin_file.cast(File.MachO).?; |
| 2496 | const debug_line_sect = d_sym.getSection(d_sym.debug_line_section_index.?); | 2586 | if (macho_file.base.isRelocatable()) { |
| 2497 | const file_pos = debug_line_sect.offset; | 2587 | const debug_line_sect = macho_file.sections.items(.header)[macho_file.debug_line_sect_index.?]; |
| 2498 | try pwriteDbgLineNops(d_sym.file, file_pos, 0, di_buf.items, jmp_amt); | 2588 | const file_pos = debug_line_sect.offset; |
| | 2589 | try pwriteDbgLineNops(macho_file.base.file.?, file_pos, 0, di_buf.items, jmp_amt); |
| | 2590 | } else { |
| | 2591 | const d_sym = macho_file.getDebugSymbols().?; |
| | 2592 | const debug_line_sect = d_sym.getSection(d_sym.debug_line_section_index.?); |
| | 2593 | const file_pos = debug_line_sect.offset; |
| | 2594 | try pwriteDbgLineNops(d_sym.file, file_pos, 0, di_buf.items, jmp_amt); |
| | 2595 | } |
| 2499 | }, | 2596 | }, |
| 2500 | .wasm => { | 2597 | .wasm => { |
| 2501 | const wasm_file = self.bin_file.cast(File.Wasm).?; | 2598 | const wasm_file = self.bin_file.cast(File.Wasm).?; |
| ... | @@ -2613,9 +2710,15 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void { | ... | @@ -2613,9 +2710,15 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void { |
| 2613 | break :pos debug_info_sect.sh_offset; | 2710 | break :pos debug_info_sect.sh_offset; |
| 2614 | }, | 2711 | }, |
| 2615 | .macho => pos: { | 2712 | .macho => pos: { |
| 2616 | const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?; | 2713 | const macho_file = self.bin_file.cast(File.MachO).?; |
| 2617 | const debug_info_sect = d_sym.getSectionPtr(d_sym.debug_info_section_index.?); | 2714 | if (macho_file.base.isRelocatable()) { |
| 2618 | break :pos debug_info_sect.offset; | 2715 | const debug_info_sect = &macho_file.sections.items(.header)[macho_file.debug_info_sect_index.?]; |
| | 2716 | break :pos debug_info_sect.offset; |
| | 2717 | } else { |
| | 2718 | const d_sym = macho_file.getDebugSymbols().?; |
| | 2719 | const debug_info_sect = d_sym.getSectionPtr(d_sym.debug_info_section_index.?); |
| | 2720 | break :pos debug_info_sect.offset; |
| | 2721 | } |
| 2619 | }, | 2722 | }, |
| 2620 | // for wasm, the offset is always 0 as we write to memory first | 2723 | // for wasm, the offset is always 0 as we write to memory first |
| 2621 | .wasm => 0, | 2724 | .wasm => 0, |
| ... | @@ -2633,8 +2736,13 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void { | ... | @@ -2633,8 +2736,13 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void { |
| 2633 | try elf_file.base.file.?.pwriteAll(&buf, file_pos + atom.off + reloc.offset); | 2736 | try elf_file.base.file.?.pwriteAll(&buf, file_pos + atom.off + reloc.offset); |
| 2634 | }, | 2737 | }, |
| 2635 | .macho => { | 2738 | .macho => { |
| 2636 | const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?; | 2739 | const macho_file = self.bin_file.cast(File.MachO).?; |
| 2637 | try d_sym.file.pwriteAll(&buf, file_pos + atom.off + reloc.offset); | 2740 | if (macho_file.base.isRelocatable()) { |
| | 2741 | try macho_file.base.file.?.pwriteAll(&buf, file_pos + atom.off + reloc.offset); |
| | 2742 | } else { |
| | 2743 | const d_sym = macho_file.getDebugSymbols().?; |
| | 2744 | try d_sym.file.pwriteAll(&buf, file_pos + atom.off + reloc.offset); |
| | 2745 | } |
| 2638 | }, | 2746 | }, |
| 2639 | .wasm => { | 2747 | .wasm => { |
| 2640 | const wasm_file = self.bin_file.cast(File.Wasm).?; | 2748 | const wasm_file = self.bin_file.cast(File.Wasm).?; |
| ... | @@ -2659,8 +2767,12 @@ fn addDIFile(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclIndex) !u28 | ... | @@ -2659,8 +2767,12 @@ fn addDIFile(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclIndex) !u28 |
| 2659 | }, | 2767 | }, |
| 2660 | .macho => { | 2768 | .macho => { |
| 2661 | const macho_file = self.bin_file.cast(File.MachO).?; | 2769 | const macho_file = self.bin_file.cast(File.MachO).?; |
| 2662 | const d_sym = macho_file.getDebugSymbols().?; | 2770 | if (macho_file.base.isRelocatable()) { |
| 2663 | d_sym.markDirty(d_sym.debug_line_section_index.?, macho_file); | 2771 | macho_file.markDirty(macho_file.debug_line_sect_index.?); |
| | 2772 | } else { |
| | 2773 | const d_sym = macho_file.getDebugSymbols().?; |
| | 2774 | d_sym.markDirty(d_sym.debug_line_section_index.?, macho_file); |
| | 2775 | } |
| 2664 | }, | 2776 | }, |
| 2665 | .wasm => {}, | 2777 | .wasm => {}, |
| 2666 | else => unreachable, | 2778 | else => unreachable, |