Commit 3b7c9dd6bd

Jakub Konka <kubkon@jakubkonka.com>
2021-04-10 11:00:12
zld: differentiate between static and global in stabs
1 parent 717d382
Changed files (2)
src
src/link/MachO/Object.zig
@@ -399,8 +399,13 @@ pub fn parseDebugInfo(self: *Object) !void {
             }
         } else null;
 
-        // TODO How do we work out static, global, local?
-        const tag: Stab.Tag = if (size == null) .global else .function;
+        const tag: Stab.Tag = tag: {
+            if (size != null) break :tag .function;
+            switch (sym.tag) {
+                .weak, .strong => break :tag .global,
+                else => break :tag .static,
+            }
+        };
         try self.stabs.append(self.allocator, .{
             .tag = tag,
             .size = size,
src/link/MachO/Zld.zig
@@ -2519,7 +2519,16 @@ fn writeDebugInfo(self: *Zld) !void {
                         .n_value = stab.size.?,
                     });
                 },
-                else => {
+                .global => {
+                    try stabs.append(.{
+                        .n_strx = sym.inner.n_strx,
+                        .n_type = macho.N_GSYM,
+                        .n_sect = 0,
+                        .n_desc = 0,
+                        .n_value = 0,
+                    });
+                },
+                .static => {
                     try stabs.append(.{
                         .n_strx = sym.inner.n_strx,
                         .n_type = macho.N_STSYM,