| ... | @@ -885,7 +885,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { | ... | @@ -885,7 +885,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { |
| 885 | const sym_name = self.getString(sym.n_strx); | 885 | const sym_name = self.getString(sym.n_strx); |
| 886 | const resolv = self.symbol_resolver.get(sym.n_strx) orelse unreachable; | 886 | const resolv = self.symbol_resolver.get(sym.n_strx) orelse unreachable; |
| 887 | | 887 | |
| 888 | if (symbolIsDiscarded(sym.*)) { | 888 | if (sym.discarded()) { |
| 889 | sym.* = .{ | 889 | sym.* = .{ |
| 890 | .n_strx = 0, | 890 | .n_strx = 0, |
| 891 | .n_type = macho.N_UNDF, | 891 | .n_type = macho.N_UNDF, |
| ... | @@ -2445,21 +2445,21 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void { | ... | @@ -2445,21 +2445,21 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void { |
| 2445 | const sym_id = @intCast(u32, id); | 2445 | const sym_id = @intCast(u32, id); |
| 2446 | const sym_name = object.getString(sym.n_strx); | 2446 | const sym_name = object.getString(sym.n_strx); |
| 2447 | | 2447 | |
| 2448 | if (symbolIsStab(sym)) { | 2448 | if (sym.stab()) { |
| 2449 | log.err("unhandled symbol type: stab", .{}); | 2449 | log.err("unhandled symbol type: stab", .{}); |
| 2450 | log.err(" symbol '{s}'", .{sym_name}); | 2450 | log.err(" symbol '{s}'", .{sym_name}); |
| 2451 | log.err(" first definition in '{s}'", .{object.name}); | 2451 | log.err(" first definition in '{s}'", .{object.name}); |
| 2452 | return error.UnhandledSymbolType; | 2452 | return error.UnhandledSymbolType; |
| 2453 | } | 2453 | } |
| 2454 | | 2454 | |
| 2455 | if (symbolIsIndr(sym)) { | 2455 | if (sym.indr()) { |
| 2456 | log.err("unhandled symbol type: indirect", .{}); | 2456 | log.err("unhandled symbol type: indirect", .{}); |
| 2457 | log.err(" symbol '{s}'", .{sym_name}); | 2457 | log.err(" symbol '{s}'", .{sym_name}); |
| 2458 | log.err(" first definition in '{s}'", .{object.name}); | 2458 | log.err(" first definition in '{s}'", .{object.name}); |
| 2459 | return error.UnhandledSymbolType; | 2459 | return error.UnhandledSymbolType; |
| 2460 | } | 2460 | } |
| 2461 | | 2461 | |
| 2462 | if (symbolIsAbs(sym)) { | 2462 | if (sym.abs()) { |
| 2463 | log.err("unhandled symbol type: absolute", .{}); | 2463 | log.err("unhandled symbol type: absolute", .{}); |
| 2464 | log.err(" symbol '{s}'", .{sym_name}); | 2464 | log.err(" symbol '{s}'", .{sym_name}); |
| 2465 | log.err(" first definition in '{s}'", .{object.name}); | 2465 | log.err(" first definition in '{s}'", .{object.name}); |
| ... | @@ -2467,7 +2467,7 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void { | ... | @@ -2467,7 +2467,7 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void { |
| 2467 | } | 2467 | } |
| 2468 | | 2468 | |
| 2469 | const n_strx = try self.makeString(sym_name); | 2469 | const n_strx = try self.makeString(sym_name); |
| 2470 | if (symbolIsSect(sym)) { | 2470 | if (sym.sect()) { |
| 2471 | // Defined symbol regardless of scope lands in the locals symbol table. | 2471 | // Defined symbol regardless of scope lands in the locals symbol table. |
| 2472 | const local_sym_index = @intCast(u32, self.locals.items.len); | 2472 | const local_sym_index = @intCast(u32, self.locals.items.len); |
| 2473 | try self.locals.append(self.base.allocator, .{ | 2473 | try self.locals.append(self.base.allocator, .{ |
| ... | @@ -2482,7 +2482,7 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void { | ... | @@ -2482,7 +2482,7 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void { |
| 2482 | | 2482 | |
| 2483 | // If the symbol's scope is not local aka translation unit, then we need work out | 2483 | // If the symbol's scope is not local aka translation unit, then we need work out |
| 2484 | // if we should save the symbol as a global, or potentially flag the error. | 2484 | // if we should save the symbol as a global, or potentially flag the error. |
| 2485 | if (!symbolIsExt(sym)) continue; | 2485 | if (!sym.ext()) continue; |
| 2486 | | 2486 | |
| 2487 | const local = self.locals.items[local_sym_index]; | 2487 | const local = self.locals.items[local_sym_index]; |
| 2488 | const resolv = self.symbol_resolver.getPtr(n_strx) orelse { | 2488 | const resolv = self.symbol_resolver.getPtr(n_strx) orelse { |
| ... | @@ -2507,18 +2507,16 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void { | ... | @@ -2507,18 +2507,16 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void { |
| 2507 | .global => { | 2507 | .global => { |
| 2508 | const global = &self.globals.items[resolv.where_index]; | 2508 | const global = &self.globals.items[resolv.where_index]; |
| 2509 | | 2509 | |
| 2510 | if (symbolIsTentative(global.*)) { | 2510 | if (global.tentative()) { |
| 2511 | assert(self.tentatives.swapRemove(resolv.where_index)); | 2511 | assert(self.tentatives.swapRemove(resolv.where_index)); |
| 2512 | } else if (!(symbolIsWeakDef(sym) or symbolIsPext(sym)) and | 2512 | } else if (!(sym.weakDef() or sym.pext()) and !(global.weakDef() or global.pext())) { |
| 2513 | !(symbolIsWeakDef(global.*) or symbolIsPext(global.*))) | | |
| 2514 | { | | |
| 2515 | log.err("symbol '{s}' defined multiple times", .{sym_name}); | 2513 | log.err("symbol '{s}' defined multiple times", .{sym_name}); |
| 2516 | if (resolv.file) |file| { | 2514 | if (resolv.file) |file| { |
| 2517 | log.err(" first definition in '{s}'", .{self.objects.items[file].name}); | 2515 | log.err(" first definition in '{s}'", .{self.objects.items[file].name}); |
| 2518 | } | 2516 | } |
| 2519 | log.err(" next definition in '{s}'", .{object.name}); | 2517 | log.err(" next definition in '{s}'", .{object.name}); |
| 2520 | return error.MultipleSymbolDefinitions; | 2518 | return error.MultipleSymbolDefinitions; |
| 2521 | } else if (symbolIsWeakDef(sym) or symbolIsPext(sym)) continue; // Current symbol is weak, so skip it. | 2519 | } else if (sym.weakDef() or sym.pext()) continue; // Current symbol is weak, so skip it. |
| 2522 | | 2520 | |
| 2523 | // Otherwise, update the resolver and the global symbol. | 2521 | // Otherwise, update the resolver and the global symbol. |
| 2524 | global.n_type = sym.n_type; | 2522 | global.n_type = sym.n_type; |
| ... | @@ -2554,7 +2552,7 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void { | ... | @@ -2554,7 +2552,7 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void { |
| 2554 | .local_sym_index = local_sym_index, | 2552 | .local_sym_index = local_sym_index, |
| 2555 | .file = object_id, | 2553 | .file = object_id, |
| 2556 | }; | 2554 | }; |
| 2557 | } else if (symbolIsTentative(sym)) { | 2555 | } else if (sym.tentative()) { |
| 2558 | // Symbol is a tentative definition. | 2556 | // Symbol is a tentative definition. |
| 2559 | const resolv = self.symbol_resolver.getPtr(n_strx) orelse { | 2557 | const resolv = self.symbol_resolver.getPtr(n_strx) orelse { |
| 2560 | const global_sym_index = @intCast(u32, self.globals.items.len); | 2558 | const global_sym_index = @intCast(u32, self.globals.items.len); |
| ... | @@ -2577,7 +2575,7 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void { | ... | @@ -2577,7 +2575,7 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void { |
| 2577 | switch (resolv.where) { | 2575 | switch (resolv.where) { |
| 2578 | .global => { | 2576 | .global => { |
| 2579 | const global = &self.globals.items[resolv.where_index]; | 2577 | const global = &self.globals.items[resolv.where_index]; |
| 2580 | if (!symbolIsTentative(global.*)) continue; | 2578 | if (!global.tentative()) continue; |
| 2581 | if (global.n_value >= sym.n_value) continue; | 2579 | if (global.n_value >= sym.n_value) continue; |
| 2582 | | 2580 | |
| 2583 | global.n_desc = sym.n_desc; | 2581 | global.n_desc = sym.n_desc; |
| ... | @@ -3575,9 +3573,9 @@ pub fn updateDeclExports( | ... | @@ -3575,9 +3573,9 @@ pub fn updateDeclExports( |
| 3575 | | 3573 | |
| 3576 | const sym = &self.globals.items[resolv.where_index]; | 3574 | const sym = &self.globals.items[resolv.where_index]; |
| 3577 | | 3575 | |
| 3578 | if (symbolIsTentative(sym.*)) { | 3576 | if (sym.tentative()) { |
| 3579 | assert(self.tentatives.swapRemove(resolv.where_index)); | 3577 | assert(self.tentatives.swapRemove(resolv.where_index)); |
| 3580 | } else if (!is_weak and !(symbolIsWeakDef(sym.*) or symbolIsPext(sym.*))) { | 3578 | } else if (!is_weak and !(sym.weakDef() or sym.pext())) { |
| 3581 | _ = try module.failed_exports.put( | 3579 | _ = try module.failed_exports.put( |
| 3582 | module.gpa, | 3580 | module.gpa, |
| 3583 | exp, | 3581 | exp, |
| ... | @@ -5316,58 +5314,9 @@ pub fn getString(self: *MachO, off: u32) []const u8 { | ... | @@ -5316,58 +5314,9 @@ pub fn getString(self: *MachO, off: u32) []const u8 { |
| 5316 | return mem.sliceTo(@ptrCast([*:0]const u8, self.strtab.items.ptr + off), 0); | 5314 | return mem.sliceTo(@ptrCast([*:0]const u8, self.strtab.items.ptr + off), 0); |
| 5317 | } | 5315 | } |
| 5318 | | 5316 | |
| 5319 | pub fn symbolIsStab(sym: macho.nlist_64) bool { | | |
| 5320 | return (macho.N_STAB & sym.n_type) != 0; | | |
| 5321 | } | | |
| 5322 | | | |
| 5323 | pub fn symbolIsPext(sym: macho.nlist_64) bool { | | |
| 5324 | return (macho.N_PEXT & sym.n_type) != 0; | | |
| 5325 | } | | |
| 5326 | | | |
| 5327 | pub fn symbolIsExt(sym: macho.nlist_64) bool { | | |
| 5328 | return (macho.N_EXT & sym.n_type) != 0; | | |
| 5329 | } | | |
| 5330 | | | |
| 5331 | pub fn symbolIsSect(sym: macho.nlist_64) bool { | | |
| 5332 | const type_ = macho.N_TYPE & sym.n_type; | | |
| 5333 | return type_ == macho.N_SECT; | | |
| 5334 | } | | |
| 5335 | | | |
| 5336 | pub fn symbolIsUndf(sym: macho.nlist_64) bool { | | |
| 5337 | const type_ = macho.N_TYPE & sym.n_type; | | |
| 5338 | return type_ == macho.N_UNDF; | | |
| 5339 | } | | |
| 5340 | | | |
| 5341 | pub fn symbolIsIndr(sym: macho.nlist_64) bool { | | |
| 5342 | const type_ = macho.N_TYPE & sym.n_type; | | |
| 5343 | return type_ == macho.N_INDR; | | |
| 5344 | } | | |
| 5345 | | | |
| 5346 | pub fn symbolIsAbs(sym: macho.nlist_64) bool { | | |
| 5347 | const type_ = macho.N_TYPE & sym.n_type; | | |
| 5348 | return type_ == macho.N_ABS; | | |
| 5349 | } | | |
| 5350 | | | |
| 5351 | pub fn symbolIsWeakDef(sym: macho.nlist_64) bool { | | |
| 5352 | return (sym.n_desc & macho.N_WEAK_DEF) != 0; | | |
| 5353 | } | | |
| 5354 | | | |
| 5355 | pub fn symbolIsWeakRef(sym: macho.nlist_64) bool { | | |
| 5356 | return (sym.n_desc & macho.N_WEAK_REF) != 0; | | |
| 5357 | } | | |
| 5358 | | | |
| 5359 | pub fn symbolIsDiscarded(sym: macho.nlist_64) bool { | | |
| 5360 | return (sym.n_desc & macho.N_DESC_DISCARDED) != 0; | | |
| 5361 | } | | |
| 5362 | | | |
| 5363 | pub fn symbolIsTentative(sym: macho.nlist_64) bool { | | |
| 5364 | if (!symbolIsUndf(sym)) return false; | | |
| 5365 | return sym.n_value != 0; | | |
| 5366 | } | | |
| 5367 | | | |
| 5368 | pub fn symbolIsTemp(sym: macho.nlist_64, sym_name: []const u8) bool { | 5317 | pub fn symbolIsTemp(sym: macho.nlist_64, sym_name: []const u8) bool { |
| 5369 | if (!symbolIsSect(sym)) return false; | 5318 | if (!sym.sect()) return false; |
| 5370 | if (symbolIsExt(sym)) return false; | 5319 | if (sym.ext()) return false; |
| 5371 | return mem.startsWith(u8, sym_name, "l") or mem.startsWith(u8, sym_name, "L"); | 5320 | return mem.startsWith(u8, sym_name, "l") or mem.startsWith(u8, sym_name, "L"); |
| 5372 | } | 5321 | } |
| 5373 | | 5322 | |