aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2021-05-14 11:46:50 +0200
committerJakub Konka <kubkon@jakubkonka.com>2021-05-14 13:08:56 +0200
commit00ebbe6df2249ba8201c0e5472d95022bf73e782 (patch)
tree8a71469cc3f1e2ec94360a9317ebcce576924c9a /src/link/MachO.zig
parent8eea5eddf773a8d1f9f883e71d00409e454ee0bd (diff)
downloadzig-00ebbe6df2249ba8201c0e5472d95022bf73e782.tar.gz
zig-00ebbe6df2249ba8201c0e5472d95022bf73e782.zip
macho: require _main as global export in self-hosted
Clean up type and description flags generation for exports in self-hosted MachO backend.
Diffstat (limited to 'src/link/MachO.zig')
-rw-r--r--src/link/MachO.zig33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/link/MachO.zig b/src/link/MachO.zig
index d8518c4894..5a0deb67bc 100644
--- a/src/link/MachO.zig
+++ b/src/link/MachO.zig
@@ -1369,15 +1369,32 @@ pub fn updateDeclExports(
continue;
}
}
- const n_desc = switch (exp.options.linkage) {
- .Internal => macho.REFERENCE_FLAG_PRIVATE_DEFINED,
- .Strong => blk: {
- if (mem.eql(u8, exp.options.name, "_start")) {
+
+ var n_type: u8 = macho.N_SECT | macho.N_EXT;
+ var n_desc: u16 = 0;
+
+ switch (exp.options.linkage) {
+ .Internal => {
+ // Symbol should be hidden, or in MachO lingo, private extern.
+ // We should also mark the symbol as Weak: n_desc == N_WEAK_DEF.
+ // TODO work out when to add N_WEAK_REF.
+ n_type |= macho.N_PEXT;
+ n_desc |= macho.N_WEAK_DEF;
+ },
+ .Strong => {
+ // Check if the export is _main, and note if os.
+ // Otherwise, don't do anything since we already have all the flags
+ // set that we need for global (strong) linkage.
+ // n_type == N_SECT | N_EXT
+ if (mem.eql(u8, exp.options.name, "_main")) {
self.entry_addr = decl_sym.n_value;
}
- break :blk macho.REFERENCE_FLAG_DEFINED;
},
- .Weak => macho.N_WEAK_REF,
+ .Weak => {
+ // Weak linkage is specified as part of n_desc field.
+ // Symbol's n_type is like for a symbol with strong linkage.
+ n_desc |= macho.N_WEAK_DEF;
+ },
.LinkOnce => {
try module.failed_exports.ensureCapacity(module.gpa, module.failed_exports.items().len + 1);
module.failed_exports.putAssumeCapacityNoClobber(
@@ -1386,8 +1403,8 @@ pub fn updateDeclExports(
);
continue;
},
- };
- const n_type = decl_sym.n_type | macho.N_EXT;
+ }
+
if (exp.link.macho.sym_index) |i| {
const sym = &self.globals.items[i];
sym.* = .{